├── .cargo └── config.toml ├── .github └── workflows │ ├── lint.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── img.png ├── kalc.config ├── kalc.vars └── src └── main.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [unstable] 2 | build-std = ["std", "panic_abort"] 3 | build-std-features = ["panic_immediate_abort"] 4 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | lint-linux: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Install dependencies 18 | run: sudo apt-get update && sudo apt-get install -y libwayland-dev libxkbcommon-dev pkg-config libudev-dev libinput-dev libdrm-dev libgbm-dev build-essential 19 | - name: depends 20 | run: | 21 | cd .. 22 | git clone https://github.com/bgkillas/kalc-lib 23 | cd kalc 24 | - name: fmt 25 | run: cargo fmt --check 26 | - name: lint-min 27 | run: cargo clippy --no-default-features --features "rug,fastnum" -- -D clippy::all 28 | - name: lint-all 29 | run: cargo clippy -- -D clippy::all 30 | lint-windows: 31 | runs-on: windows-latest 32 | steps: 33 | - uses: actions/checkout@v4 34 | - name: depends 35 | run: | 36 | cd .. 37 | git clone https://github.com/bgkillas/kalc-lib 38 | cd kalc 39 | - name: Install Rust 40 | uses: actions-rs/toolchain@v1 41 | with: 42 | toolchain: stable 43 | target: x86_64-pc-windows-gnu 44 | profile: minimal 45 | override: true 46 | - name: Install MSYS2 and GMP 47 | uses: msys2/setup-msys2@v2 48 | with: 49 | update: true 50 | install: >- 51 | base-devel 52 | mingw-w64-x86_64-rust 53 | mingw-w64-x86_64-gcc 54 | mingw-w64-x86_64-pkg-config 55 | mingw-w64-x86_64-gmp 56 | mingw-w64-x86_64-mpfr 57 | mingw-w64-x86_64-make 58 | mingw-w64-x86_64-clang 59 | m4 60 | make 61 | python 62 | openssl 63 | git 64 | mingw-w64-x86_64-gn 65 | mingw-w64-x86_64-fontconfig 66 | mingw-w64-x86_64-libpng 67 | mingw-w64-x86_64-freetype 68 | expat 69 | llvm 70 | ninja 71 | msystem: MINGW64 72 | - name: fmt 73 | shell: msys2 {0} 74 | env: 75 | CARGO_HOME: /mingw64/.cargo 76 | RUSTUP_HOME: /mingw64/.rustup 77 | PKG_CONFIG_PATH: /mingw64/lib/pkgconfig 78 | PATH: /mingw64/bin:$PATH 79 | CC: clang 80 | run: | 81 | cargo fmt --check 82 | - name: lint-tiny 83 | shell: msys2 {0} 84 | env: 85 | CARGO_HOME: /mingw64/.cargo 86 | RUSTUP_HOME: /mingw64/.rustup 87 | PKG_CONFIG_PATH: /mingw64/lib/pkgconfig 88 | PATH: /mingw64/bin:$PATH 89 | CC: clang 90 | run: | 91 | cargo clippy --no-default-features --features "rug,fastnum" -- -D clippy::all 92 | - name: lint-full 93 | shell: msys2 {0} 94 | env: 95 | CARGO_HOME: /mingw64/.cargo 96 | RUSTUP_HOME: /mingw64/.rustup 97 | PKG_CONFIG_PATH: /mingw64/lib/pkgconfig 98 | PATH: /mingw64/bin:$PATH 99 | CC: clang 100 | run: | 101 | cargo clippy -- -D clippy::all 102 | lint-macos: 103 | runs-on: macos-latest 104 | steps: 105 | - uses: actions/checkout@v4 106 | - name: depends 107 | run: | 108 | cd .. 109 | git clone https://github.com/bgkillas/kalc-lib 110 | cd kalc 111 | - name: fmt 112 | run: cargo fmt --check 113 | - name: lint-min 114 | run: cargo clippy --no-default-features --features "rug,fastnum" -- -D clippy::all 115 | - name: lint-all 116 | run: cargo clippy -- -D clippy::all -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build-egui-linux: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - name: depends 11 | run: | 12 | cd .. 13 | git clone https://github.com/bgkillas/kalc-lib 14 | cd kalc 15 | - name: Build linux 16 | run: cargo build --release 17 | - uses: actions/upload-artifact@v4 18 | with: 19 | name: kalc-linux 20 | path: target/release/kalc 21 | build-egui-macos: 22 | runs-on: macos-latest 23 | steps: 24 | - uses: actions/checkout@v4 25 | - name: depends 26 | run: | 27 | cd .. 28 | git clone https://github.com/bgkillas/kalc-lib 29 | cd kalc 30 | - name: Build macos 31 | run: cargo build --release 32 | - uses: actions/upload-artifact@v4 33 | with: 34 | name: kalc-macos 35 | path: target/release/kalc 36 | build-egui-macos-x86_64: 37 | runs-on: macos-13 38 | steps: 39 | - uses: actions/checkout@v4 40 | - name: depends 41 | run: | 42 | cd .. 43 | git clone https://github.com/bgkillas/kalc-lib 44 | cd kalc 45 | - name: Build macos 46 | run: cargo build --release 47 | - uses: actions/upload-artifact@v4 48 | with: 49 | name: kalc-macos-x86_64 50 | path: target/release/kalc 51 | build-egui-windows: 52 | runs-on: windows-latest 53 | steps: 54 | - uses: actions/checkout@v4 55 | - name: depends 56 | run: | 57 | cd .. 58 | git clone https://github.com/bgkillas/kalc-lib 59 | cd kalc 60 | - name: Install Rust 61 | uses: actions-rs/toolchain@v1 62 | with: 63 | toolchain: stable 64 | target: x86_64-pc-windows-gnu 65 | profile: minimal 66 | override: true 67 | - name: Install MSYS2 and GMP 68 | uses: msys2/setup-msys2@v2 69 | with: 70 | update: true 71 | install: >- 72 | base-devel 73 | mingw-w64-x86_64-rust 74 | mingw-w64-x86_64-gcc 75 | mingw-w64-x86_64-pkg-config 76 | mingw-w64-x86_64-gmp 77 | mingw-w64-x86_64-mpfr 78 | mingw-w64-x86_64-make 79 | mingw-w64-x86_64-clang 80 | m4 81 | make 82 | python 83 | openssl 84 | git 85 | mingw-w64-x86_64-gn 86 | mingw-w64-x86_64-fontconfig 87 | mingw-w64-x86_64-libpng 88 | mingw-w64-x86_64-freetype 89 | expat 90 | llvm 91 | ninja 92 | msystem: MINGW64 93 | - name: Build windows 94 | shell: msys2 {0} 95 | env: 96 | CARGO_HOME: /mingw64/.cargo 97 | RUSTUP_HOME: /mingw64/.rustup 98 | PKG_CONFIG_PATH: /mingw64/lib/pkgconfig 99 | PATH: /mingw64/bin:$PATH 100 | CC: clang 101 | run: cargo build --release 102 | - uses: actions/upload-artifact@v4 103 | with: 104 | name: kalc.exe 105 | path: target/release/kalc.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .idea/ 3 | bin/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "kalc-lib"] 2 | path = kalc-lib 3 | url = https://github.com/bgkillas/kalc-lib 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "arrayvec" 7 | version = "0.7.6" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" 10 | 11 | [[package]] 12 | name = "autocfg" 13 | version = "1.4.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 16 | 17 | [[package]] 18 | name = "az" 19 | version = "1.2.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" 22 | 23 | [[package]] 24 | name = "bitcode" 25 | version = "0.6.6" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "cf300f4aa6e66f3bdff11f1236a88c622fe47ea814524792240b4d554d9858ee" 28 | dependencies = [ 29 | "arrayvec", 30 | "bitcode_derive", 31 | "bytemuck", 32 | "glam", 33 | "serde", 34 | ] 35 | 36 | [[package]] 37 | name = "bitcode_derive" 38 | version = "0.6.5" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | checksum = "42b6b4cb608b8282dc3b53d0f4c9ab404655d562674c682db7e6c0458cc83c23" 41 | dependencies = [ 42 | "proc-macro2", 43 | "quote", 44 | "syn", 45 | ] 46 | 47 | [[package]] 48 | name = "bitflags" 49 | version = "2.9.1" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" 52 | 53 | [[package]] 54 | name = "bnum" 55 | version = "0.12.1" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "f781dba93de3a5ef6dc5b17c9958b208f6f3f021623b360fb605ea51ce443f10" 58 | dependencies = [ 59 | "serde", 60 | "serde-big-array", 61 | ] 62 | 63 | [[package]] 64 | name = "bytemuck" 65 | version = "1.23.0" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c" 68 | 69 | [[package]] 70 | name = "cfg-if" 71 | version = "1.0.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 74 | 75 | [[package]] 76 | name = "convert_case" 77 | version = "0.7.1" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "bb402b8d4c85569410425650ce3eddc7d698ed96d39a73f941b08fb63082f1e7" 80 | dependencies = [ 81 | "unicode-segmentation", 82 | ] 83 | 84 | [[package]] 85 | name = "crossbeam-deque" 86 | version = "0.8.6" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" 89 | dependencies = [ 90 | "crossbeam-epoch", 91 | "crossbeam-utils", 92 | ] 93 | 94 | [[package]] 95 | name = "crossbeam-epoch" 96 | version = "0.9.18" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" 99 | dependencies = [ 100 | "crossbeam-utils", 101 | ] 102 | 103 | [[package]] 104 | name = "crossbeam-utils" 105 | version = "0.8.21" 106 | source = "registry+https://github.com/rust-lang/crates.io-index" 107 | checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" 108 | 109 | [[package]] 110 | name = "crossterm" 111 | version = "0.29.0" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" 114 | dependencies = [ 115 | "bitflags", 116 | "crossterm_winapi", 117 | "derive_more", 118 | "document-features", 119 | "mio", 120 | "parking_lot", 121 | "rustix", 122 | "signal-hook", 123 | "signal-hook-mio", 124 | "winapi", 125 | ] 126 | 127 | [[package]] 128 | name = "crossterm_winapi" 129 | version = "0.9.1" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" 132 | dependencies = [ 133 | "winapi", 134 | ] 135 | 136 | [[package]] 137 | name = "derive_more" 138 | version = "2.0.1" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | checksum = "093242cf7570c207c83073cf82f79706fe7b8317e98620a47d5be7c3d8497678" 141 | dependencies = [ 142 | "derive_more-impl", 143 | ] 144 | 145 | [[package]] 146 | name = "derive_more-impl" 147 | version = "2.0.1" 148 | source = "registry+https://github.com/rust-lang/crates.io-index" 149 | checksum = "bda628edc44c4bb645fbe0f758797143e4e07926f7ebf4e9bdfbd3d2ce621df3" 150 | dependencies = [ 151 | "convert_case", 152 | "proc-macro2", 153 | "quote", 154 | "syn", 155 | ] 156 | 157 | [[package]] 158 | name = "dirs" 159 | version = "6.0.0" 160 | source = "registry+https://github.com/rust-lang/crates.io-index" 161 | checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" 162 | dependencies = [ 163 | "dirs-sys", 164 | ] 165 | 166 | [[package]] 167 | name = "dirs-sys" 168 | version = "0.5.0" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" 171 | dependencies = [ 172 | "libc", 173 | "option-ext", 174 | "redox_users", 175 | "windows-sys", 176 | ] 177 | 178 | [[package]] 179 | name = "document-features" 180 | version = "0.2.11" 181 | source = "registry+https://github.com/rust-lang/crates.io-index" 182 | checksum = "95249b50c6c185bee49034bcb378a49dc2b5dff0be90ff6616d31d64febab05d" 183 | dependencies = [ 184 | "litrs", 185 | ] 186 | 187 | [[package]] 188 | name = "either" 189 | version = "1.15.0" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 192 | 193 | [[package]] 194 | name = "errno" 195 | version = "0.3.12" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" 198 | dependencies = [ 199 | "libc", 200 | "windows-sys", 201 | ] 202 | 203 | [[package]] 204 | name = "fastnum" 205 | version = "0.2.9" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "b875e26379edd7866a74cec720c6ae7bea3107aaf9fd3b14d7449d87d4c1986b" 208 | dependencies = [ 209 | "autocfg", 210 | "bnum", 211 | "serde", 212 | ] 213 | 214 | [[package]] 215 | name = "fastrand" 216 | version = "2.3.0" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 219 | 220 | [[package]] 221 | name = "getrandom" 222 | version = "0.2.16" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" 225 | dependencies = [ 226 | "cfg-if", 227 | "libc", 228 | "wasi", 229 | ] 230 | 231 | [[package]] 232 | name = "glam" 233 | version = "0.30.3" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | checksum = "6b46b9ca4690308844c644e7c634d68792467260e051c8543e0c7871662b3ba7" 236 | 237 | [[package]] 238 | name = "gmp-mpfr-sys" 239 | version = "1.6.5" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "c66d61197a68f6323b9afa616cf83d55d69191e1bf364d4eb7d35ae18defe776" 242 | dependencies = [ 243 | "libc", 244 | "windows-sys", 245 | ] 246 | 247 | [[package]] 248 | name = "kalc" 249 | version = "1.5.1" 250 | dependencies = [ 251 | "bitcode", 252 | "crossterm", 253 | "dirs", 254 | "kalc-lib", 255 | ] 256 | 257 | [[package]] 258 | name = "kalc-lib" 259 | version = "1.5.1" 260 | source = "registry+https://github.com/rust-lang/crates.io-index" 261 | checksum = "bae7e5f68acc59423c16f89625be149939d2c90bd458a04b1a8740f16200ca76" 262 | dependencies = [ 263 | "crossterm", 264 | "dirs", 265 | "fastnum", 266 | "fastrand", 267 | "gmp-mpfr-sys", 268 | "libc", 269 | "rayon", 270 | "rug", 271 | "serde", 272 | "term_size", 273 | ] 274 | 275 | [[package]] 276 | name = "libc" 277 | version = "0.2.172" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 280 | 281 | [[package]] 282 | name = "libm" 283 | version = "0.2.15" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" 286 | 287 | [[package]] 288 | name = "libredox" 289 | version = "0.1.3" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" 292 | dependencies = [ 293 | "bitflags", 294 | "libc", 295 | ] 296 | 297 | [[package]] 298 | name = "linux-raw-sys" 299 | version = "0.9.4" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" 302 | 303 | [[package]] 304 | name = "litrs" 305 | version = "0.4.1" 306 | source = "registry+https://github.com/rust-lang/crates.io-index" 307 | checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" 308 | 309 | [[package]] 310 | name = "lock_api" 311 | version = "0.4.13" 312 | source = "registry+https://github.com/rust-lang/crates.io-index" 313 | checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" 314 | dependencies = [ 315 | "autocfg", 316 | "scopeguard", 317 | ] 318 | 319 | [[package]] 320 | name = "log" 321 | version = "0.4.27" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 324 | 325 | [[package]] 326 | name = "mio" 327 | version = "1.0.4" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" 330 | dependencies = [ 331 | "libc", 332 | "log", 333 | "wasi", 334 | "windows-sys", 335 | ] 336 | 337 | [[package]] 338 | name = "option-ext" 339 | version = "0.2.0" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" 342 | 343 | [[package]] 344 | name = "parking_lot" 345 | version = "0.12.4" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" 348 | dependencies = [ 349 | "lock_api", 350 | "parking_lot_core", 351 | ] 352 | 353 | [[package]] 354 | name = "parking_lot_core" 355 | version = "0.9.11" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" 358 | dependencies = [ 359 | "cfg-if", 360 | "libc", 361 | "redox_syscall", 362 | "smallvec", 363 | "windows-targets", 364 | ] 365 | 366 | [[package]] 367 | name = "proc-macro2" 368 | version = "1.0.95" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 371 | dependencies = [ 372 | "unicode-ident", 373 | ] 374 | 375 | [[package]] 376 | name = "quote" 377 | version = "1.0.40" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 380 | dependencies = [ 381 | "proc-macro2", 382 | ] 383 | 384 | [[package]] 385 | name = "rayon" 386 | version = "1.10.0" 387 | source = "registry+https://github.com/rust-lang/crates.io-index" 388 | checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" 389 | dependencies = [ 390 | "either", 391 | "rayon-core", 392 | ] 393 | 394 | [[package]] 395 | name = "rayon-core" 396 | version = "1.12.1" 397 | source = "registry+https://github.com/rust-lang/crates.io-index" 398 | checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" 399 | dependencies = [ 400 | "crossbeam-deque", 401 | "crossbeam-utils", 402 | ] 403 | 404 | [[package]] 405 | name = "redox_syscall" 406 | version = "0.5.12" 407 | source = "registry+https://github.com/rust-lang/crates.io-index" 408 | checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" 409 | dependencies = [ 410 | "bitflags", 411 | ] 412 | 413 | [[package]] 414 | name = "redox_users" 415 | version = "0.5.0" 416 | source = "registry+https://github.com/rust-lang/crates.io-index" 417 | checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" 418 | dependencies = [ 419 | "getrandom", 420 | "libredox", 421 | "thiserror", 422 | ] 423 | 424 | [[package]] 425 | name = "rug" 426 | version = "1.27.0" 427 | source = "registry+https://github.com/rust-lang/crates.io-index" 428 | checksum = "4207e8d668e5b8eb574bda8322088ccd0d7782d3d03c7e8d562e82ed82bdcbc3" 429 | dependencies = [ 430 | "az", 431 | "gmp-mpfr-sys", 432 | "libc", 433 | "libm", 434 | "serde", 435 | ] 436 | 437 | [[package]] 438 | name = "rustix" 439 | version = "1.0.7" 440 | source = "registry+https://github.com/rust-lang/crates.io-index" 441 | checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" 442 | dependencies = [ 443 | "bitflags", 444 | "errno", 445 | "libc", 446 | "linux-raw-sys", 447 | "windows-sys", 448 | ] 449 | 450 | [[package]] 451 | name = "scopeguard" 452 | version = "1.2.0" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 455 | 456 | [[package]] 457 | name = "serde" 458 | version = "1.0.219" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" 461 | dependencies = [ 462 | "serde_derive", 463 | ] 464 | 465 | [[package]] 466 | name = "serde-big-array" 467 | version = "0.5.1" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" 470 | dependencies = [ 471 | "serde", 472 | ] 473 | 474 | [[package]] 475 | name = "serde_derive" 476 | version = "1.0.219" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" 479 | dependencies = [ 480 | "proc-macro2", 481 | "quote", 482 | "syn", 483 | ] 484 | 485 | [[package]] 486 | name = "signal-hook" 487 | version = "0.3.18" 488 | source = "registry+https://github.com/rust-lang/crates.io-index" 489 | checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" 490 | dependencies = [ 491 | "libc", 492 | "signal-hook-registry", 493 | ] 494 | 495 | [[package]] 496 | name = "signal-hook-mio" 497 | version = "0.2.4" 498 | source = "registry+https://github.com/rust-lang/crates.io-index" 499 | checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" 500 | dependencies = [ 501 | "libc", 502 | "mio", 503 | "signal-hook", 504 | ] 505 | 506 | [[package]] 507 | name = "signal-hook-registry" 508 | version = "1.4.5" 509 | source = "registry+https://github.com/rust-lang/crates.io-index" 510 | checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" 511 | dependencies = [ 512 | "libc", 513 | ] 514 | 515 | [[package]] 516 | name = "smallvec" 517 | version = "1.15.0" 518 | source = "registry+https://github.com/rust-lang/crates.io-index" 519 | checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" 520 | 521 | [[package]] 522 | name = "syn" 523 | version = "2.0.101" 524 | source = "registry+https://github.com/rust-lang/crates.io-index" 525 | checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" 526 | dependencies = [ 527 | "proc-macro2", 528 | "quote", 529 | "unicode-ident", 530 | ] 531 | 532 | [[package]] 533 | name = "term_size" 534 | version = "0.3.2" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" 537 | dependencies = [ 538 | "libc", 539 | "winapi", 540 | ] 541 | 542 | [[package]] 543 | name = "thiserror" 544 | version = "2.0.12" 545 | source = "registry+https://github.com/rust-lang/crates.io-index" 546 | checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" 547 | dependencies = [ 548 | "thiserror-impl", 549 | ] 550 | 551 | [[package]] 552 | name = "thiserror-impl" 553 | version = "2.0.12" 554 | source = "registry+https://github.com/rust-lang/crates.io-index" 555 | checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" 556 | dependencies = [ 557 | "proc-macro2", 558 | "quote", 559 | "syn", 560 | ] 561 | 562 | [[package]] 563 | name = "unicode-ident" 564 | version = "1.0.18" 565 | source = "registry+https://github.com/rust-lang/crates.io-index" 566 | checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" 567 | 568 | [[package]] 569 | name = "unicode-segmentation" 570 | version = "1.12.0" 571 | source = "registry+https://github.com/rust-lang/crates.io-index" 572 | checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 573 | 574 | [[package]] 575 | name = "wasi" 576 | version = "0.11.0+wasi-snapshot-preview1" 577 | source = "registry+https://github.com/rust-lang/crates.io-index" 578 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 579 | 580 | [[package]] 581 | name = "winapi" 582 | version = "0.3.9" 583 | source = "registry+https://github.com/rust-lang/crates.io-index" 584 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 585 | dependencies = [ 586 | "winapi-i686-pc-windows-gnu", 587 | "winapi-x86_64-pc-windows-gnu", 588 | ] 589 | 590 | [[package]] 591 | name = "winapi-i686-pc-windows-gnu" 592 | version = "0.4.0" 593 | source = "registry+https://github.com/rust-lang/crates.io-index" 594 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 595 | 596 | [[package]] 597 | name = "winapi-x86_64-pc-windows-gnu" 598 | version = "0.4.0" 599 | source = "registry+https://github.com/rust-lang/crates.io-index" 600 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 601 | 602 | [[package]] 603 | name = "windows-sys" 604 | version = "0.59.0" 605 | source = "registry+https://github.com/rust-lang/crates.io-index" 606 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 607 | dependencies = [ 608 | "windows-targets", 609 | ] 610 | 611 | [[package]] 612 | name = "windows-targets" 613 | version = "0.52.6" 614 | source = "registry+https://github.com/rust-lang/crates.io-index" 615 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 616 | dependencies = [ 617 | "windows_aarch64_gnullvm", 618 | "windows_aarch64_msvc", 619 | "windows_i686_gnu", 620 | "windows_i686_gnullvm", 621 | "windows_i686_msvc", 622 | "windows_x86_64_gnu", 623 | "windows_x86_64_gnullvm", 624 | "windows_x86_64_msvc", 625 | ] 626 | 627 | [[package]] 628 | name = "windows_aarch64_gnullvm" 629 | version = "0.52.6" 630 | source = "registry+https://github.com/rust-lang/crates.io-index" 631 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 632 | 633 | [[package]] 634 | name = "windows_aarch64_msvc" 635 | version = "0.52.6" 636 | source = "registry+https://github.com/rust-lang/crates.io-index" 637 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 638 | 639 | [[package]] 640 | name = "windows_i686_gnu" 641 | version = "0.52.6" 642 | source = "registry+https://github.com/rust-lang/crates.io-index" 643 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 644 | 645 | [[package]] 646 | name = "windows_i686_gnullvm" 647 | version = "0.52.6" 648 | source = "registry+https://github.com/rust-lang/crates.io-index" 649 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 650 | 651 | [[package]] 652 | name = "windows_i686_msvc" 653 | version = "0.52.6" 654 | source = "registry+https://github.com/rust-lang/crates.io-index" 655 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 656 | 657 | [[package]] 658 | name = "windows_x86_64_gnu" 659 | version = "0.52.6" 660 | source = "registry+https://github.com/rust-lang/crates.io-index" 661 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 662 | 663 | [[package]] 664 | name = "windows_x86_64_gnullvm" 665 | version = "0.52.6" 666 | source = "registry+https://github.com/rust-lang/crates.io-index" 667 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 668 | 669 | [[package]] 670 | name = "windows_x86_64_msvc" 671 | version = "0.52.6" 672 | source = "registry+https://github.com/rust-lang/crates.io-index" 673 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 674 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "kalc" 3 | description = "a complex numbers, 2d/3d graphing, arbitrary precision, vector/matrix, cli calculator with real-time output and support for units" 4 | license = "GPL-3.0-only" 5 | authors = ["bgkillas "] 6 | keywords = ["cli", "calculator"] 7 | categories = ["command-line-interface", "command-line-utilities", "mathematics"] 8 | repository = "https://github.com/bgkillas/kalc" 9 | rust-version = "1.85.0" 10 | version = "1.5.1" 11 | edition = "2024" 12 | 13 | [features] 14 | default=["serde", "rayon", "rug", "fastnum","gnuplot","kalc-plot"] 15 | force-cross=["kalc-lib/force-cross"] 16 | system-libs=["kalc-lib/system-libs"] 17 | serde=["kalc-lib/serde", "dep:bitcode"] 18 | rayon=["kalc-lib/rayon"] 19 | rug=["kalc-lib/rug"] 20 | fastnum=["kalc-lib/fastnum"] 21 | gnuplot=["kalc-lib/gnuplot"] 22 | kalc-plot=[] 23 | 24 | [profile.release] 25 | lto = true 26 | strip = true 27 | panic = "abort" 28 | split-debuginfo = "packed" 29 | incremental=true 30 | codegen-units=1 31 | 32 | [profile.dev] 33 | opt-level = 1 34 | 35 | [dependencies] 36 | crossterm = "0.29.0" 37 | dirs = "6.0.0" 38 | bitcode = {version="0.6.6", features = ["serde"], optional = true} 39 | #kalc-lib = {version = "1.5.1", path="../kalc-lib", default-features = false, features=["bin-deps","fastrand"]} 40 | kalc-lib = {version = "1.5.1",default-features = false, features=["bin-deps","fastrand"]} 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kalc 2 | 3 | [![crates.io](https://img.shields.io/crates/v/kalc.svg)](https://crates.io/crates/kalc) [![AUR](https://img.shields.io/aur/version/kalc.svg)](https://aur.archlinux.org/packages/kalc/) 4 | 5 | ![img.png](img.png) 6 | 7 | history file is stored in [config_dir](https://docs.rs/dirs/latest/dirs/fn.config_dir.html)/kalc/kalc.history 8 | 9 | config file is stored in [config_dir](https://docs.rs/dirs/latest/dirs/fn.config_dir.html)/kalc/kalc.config example in 10 | repo 11 | 12 | you can set permanent variables and functions in the 13 | file [config_dir](https://docs.rs/dirs/latest/dirs/fn.config_dir.html)/kalc/kalc.vars example in repo, also contains 14 | more advanced example usage 15 | 16 | config defaults listed in kalc.config 17 | 18 | # install instructions 19 | 20 | ## kalc-plot 21 | 22 | [kalc-plot](https://github.com/bgkillas/kalc-plot) is the plotting software i made for this, may want to try this instead of gnuplot, 23 | just must be in the system path and then it will prefer kalc-plot over gnuplot 24 | 25 | ### linux 26 | 27 | use aur or run 28 | ```cargo install kalc``` 29 | 30 | ### windows 31 | 32 | download kalc.exe from https://github.com/bgkillas/kalc/releases/latest 33 | 34 | needs a modern terminal like 'windows terminal' or alacritty, alacritty has better latency seemingly 35 | 36 | for graphing install gnuplot via winget or [sourceforge](https://sourceforge.net/projects/gnuplot/files/gnuplot/) 37 | 38 | ### macos 39 | 40 | install developer tools via ```xcode-select --install``` 41 | 42 | ```cargo install kalc``` 43 | 44 | install gnuplot via ```brew install gnuplot``` 45 | 46 | may need to run kalc from ```kalc 2> /dev/null``` for gnuplot not to output error messages 47 | 48 | # build instructions 49 | 50 | if build fails due to gmp-mpfr-sys try changing the line 51 | `features = ["force-cross"]` 52 | to 53 | `features = ["use-system-libs"]` 54 | at the end of cargo.toml 55 | 56 | ### linux 57 | 58 | dependencys are: rust>=1.79.0, diffutils, gcc, m4, make 59 | 60 | ``` 61 | git clone https://github.com/bgkillas/kalc 62 | cd kalc 63 | cargo build --release 64 | ./target/release/kalc 65 | ``` 66 | 67 | ### windows 68 | 69 | have cargo and the toolchain ```stable-x86_64-pc-windows-gnu``` installed 70 | 71 | as per [gmp-mpfr-sys](https://docs.rs/gmp-mpfr-sys/latest/gmp_mpfr_sys/index.html#building-on-windows) 72 | 73 | install MSYS2 using the [installer](https://www.msys2.org/) 74 | 75 | launch MSYS2 MinGW and run 76 | 77 | ``` 78 | pacman -Syu pacman-mirrors 79 | pacman -S git diffutils m4 make mingw-w64-x86_64-gcc 80 | git clone https://github.com/bgkillas/kalc 81 | cd kalc 82 | mkdir /mnt 83 | mount C: /mnt 84 | ``` 85 | 86 | if cargo is locally installed 87 | 88 | ``` 89 | /mnt/Users/$USER/.cargo/bin/cargo build --release 90 | ./target/release/kalc.exe 91 | ``` 92 | 93 | if cargo is globally installed 94 | 95 | ``` 96 | cargo build --release 97 | ./target/release/kalc.exe 98 | ``` 99 | 100 | then move kalc.exe wherever you want in /mnt (your C drive) 101 | 102 | ### macos 103 | 104 | as per [gmp-mpfr-sys](https://docs.rs/gmp-mpfr-sys/latest/gmp_mpfr_sys/index.html#building-on-macos) 105 | 106 | assure the path upto your build path contains no spaces 107 | 108 | install developer tools via ```xcode-select --install``` 109 | 110 | ``` 111 | git clone https://github.com/bgkillas/kalc 112 | cd kalc 113 | cargo build --release 114 | ./target/release/kalc 115 | ``` 116 | 117 | # usage 118 | 119 | ``` 120 | Usage: kalc [FLAGS] equation_1 equation_2 equation_3... 121 | FLAGS: --help (this message) 122 | --man prints a kalc.1 manpage 123 | --help {thing} to get more detail on a function/option/feature, --help help to list all "things" 124 | --interactive/-i allows interaction after finishing the equations given 125 | --units toggles units 126 | --notation=e/E/s/n defines what kind of notation you should use,(e) 3e2,(E) 3E2,(s) 3*10^2,(n) 300 127 | --graph=normal/domain/domain_alt/depth/flat/none changes how a function is graphed, domain/depth/flat relate to complex graphs 128 | --label=[x],[y],[z] sets the labels for the graphs x/y/z axis 129 | --angle=deg/rad/grad sets your angletype 130 | --2d=[num] number of points to graph in 2D, 2d=-1 for integer placements 131 | --3d=[x],[y] number of points to graph in 3D, 3d=-1 for integer placements 132 | --xr=[min],[max] x range for graphing 133 | --yr=[min],[max] y range for graphing 134 | --zr=[min],[max] z range for graphing 135 | --range=[num] sets all ranges to [-num],[num] 136 | --vxr=[min],[max] x range for graphing, graph view override, useful for parametric 137 | --vyr=[min],[max] y range for graphing, graph view override, useful for parametric 138 | --vzr=[min],[max] z range for graphing, graph view override, useful for parametric 139 | --vrange=[num] sets all ranges to [-num],[num], graph view override, useful for parametric 140 | --point [char] point style for graphing 141 | --base=[input],[output] sets the numbers base from 2 to 36 142 | --ticks=[num](,[num](,[num])) sets amount of ticks, optionally set different x/y/z ticks, -2 will be auto, -1 will be at every whole number, 0 will be none 143 | --onaxis toggles showing the ticks on the x/y/z axis on by default for 2d, off by default for 3d 144 | --prompt toggles the prompt 145 | --gnuplot toggles using gnuplot instead of kalc plot 146 | --color=true/false/auto toggles color output, toggled by default when running from arguments 147 | --comma toggles comma seperation 148 | --graph toggles graphing 149 | --vars disables default variables and kalc.vars 150 | --default sets to default settings and ignores kalc.vars 151 | --line=true/false/auto toggles line graphing 152 | --rt toggles real time printing 153 | --polar toggles displaying polar vectors 154 | --frac toggles fraction display 155 | --prec=[num] sets the output precision(default 512) 156 | --graphprec=[num] sets the graph precision(default 64) 157 | --deci=[num] sets how many decimals to display, -1 for length of terminal, -2 for maximum decimal places, may need to up precision for more decimals 158 | --multi toggles multi line display for matrixes 159 | --tabbed toggles tabbed display for matrixes 160 | --surface displays a colored surface(based on z value) for 3d graphing, only supports 1 graph 161 | --scalegraph scales the y part of a 2d graph to the users screen size, setting --windowsize=x,y makes the ratio more accurate 162 | --saveto=[file] saves the graph as a png to the given file, --windowsize=x,y for resolution 163 | --siunits toggles keeping stuff in si units, a newton will show as 'm s^-2 kg' instead of 'N' 164 | --keepzeros dont remove trailing zeros 165 | --progress shows progress on graph 166 | --default_units=unit1,unit2... sets the default single dimensional unit 167 | 168 | - flags can be executed in runtime just without the dashes 169 | - '~' will find the var value which makes the left side and right side equal each other, via newtons method starting at 0 170 | - '~~' will find the var value which makes the left side and right side equal each other, via newtons method starting at -2/0/2, another will solve some imaginary values 171 | - '===' given f(x)===b, will compute isolate(x,f(x)-b) 172 | - any function with ' appeneded to the name will be converted like f'(x) goes to slope(t,f(t),x) 173 | - any function with ` appeneded to the name will be converted like f`(x) goes to area(t,f(t),0,x) 174 | - "colors=" to see color settings 175 | - "exit" to exit the program 176 | - "clear" to clear the screen 177 | - "history [arg]" to see the history, arg searches for the arg it if specified 178 | - "vars" to list all variables 179 | - "option/var;function" to set a temporal option/var, example: "a=45;angle=deg;sin(a)" = sqrt(2)/2 180 | - "f(x)=var:function" to set a temporal var when defining function, example: "f(x)=a=2:ax" = f(x)=2x 181 | - "_" or "ans" or "ANS" to use the previous answer 182 | - "a={expr}" to define a variable 183 | - "f(x)=..." to define a function 184 | - "f(x,y,z...)=..." to define a multi variable function 185 | - "...=" display parsed input, show values of stuff like xr/deci/prec etc 186 | - "f...=null" to delete a function or variable 187 | - "{x,y,z...}" to define a cartesian vector 188 | - "[r,θ,φ]" to define a polar vector (same as car{r,θ,φ}) 189 | - "f(x)#g(x)" to graph multiple things 190 | - "{vec}#" to graph a vector 191 | - "{mat}#" to graph a matrix 192 | - "number#" to graph a complex number 193 | - "[f(x),x]" to graph a polar graph of f(x) 194 | - "{x,y}" to graph a parametric equation, example: {cos(x),sin(x)} unit circle, {f(x)cos(x),f(x)sin(x)} for polar graph 195 | - "{x,y,z}" to graph a parametric equation in 3d, example: {cos(x),sin(x),x} helix, {sin(x)cos(y),sin(x)sin(y),cos(x)} sphere 196 | - "{{a,b,c},{d,e,f},{g,h,i}}" to define a 3x3 matrix 197 | - "rnd" to generate a random number 198 | - "epoch" to get time in seconds since unix epoch 199 | - Alt+Enter will not print output while still graphing/defining variables 200 | - "help {thing}" to get more detail on a function/option/feature 201 | - "help help" to list all things to query 202 | 203 | Order of Operations: 204 | - user defined functions 205 | - functions, !x, x!, x!!, |x| 206 | - % (modulus), .. (a..b creates lists of integers from a to b) 207 | - ^/** (exponentiation), // (a//b is a root b), ^^ (tetration), computed from right to left 208 | - × internal multiplication for units and negitive signs 209 | - * (multiplication), / (division) 210 | - + (addition), - (subtraction), +-/± (creates a list of the calculation if plus and the calculation if minus) 211 | - to/-> (unit conversions, ie 2m->yd=2.2, leaves unitless if perfect conversion) 212 | - < (lt), <= (le), > (gt), >= (ge), == (eq), != (!eq), >> (a>>b shifts b bits right), << (a<α, A=>Α, b=>β, B=>Β, c=>ξ, C=>Ξ, d=>Δ, D=>δ, 392 | e=>ε, E=>Ε, f=>φ, F=>Φ, g=>γ, G=>Γ, h=>η, H=>Η, 393 | i=>ι, I=>Ι, k=>κ, Κ=>Κ, l=>λ, L=>Λ, m=>μ, M=>Μ, 394 | n=>ν, Ν=>Ν, o=>ο, O=>Ο, p=>π, P=>Π, q=>θ, Q=>Θ, 395 | r=>ρ, R=>Ρ, s=>σ, S=>Σ, t=>τ, T=>Τ, u=>υ, U=>Υ, 396 | w=>ω, W=>Ω, y=>ψ, Y=>Ψ, x=>χ, X=>Χ, z=>ζ, Z=>Ζ, 397 | +=>±, ==>≈, `=>ⁱ, _=>∞, ;=>° 398 | numbers/minus sign convert to superscript acting as exponents 399 | ``` 400 | 401 | # basic example usage 402 | 403 | ``` 404 | kalc 405 | > 1+1 406 | 2 407 | > f(x)=sin(2x) //define f(x), will display how it was parsed 408 | sin(2*x) 409 | > f(x) // graphs f(x) in 2D 410 | sin(2*x) 411 | > f(pi/2) // evaluates f(x) at x=pi/2, so sin(2pi/2)=sin(pi)=0 412 | 0 413 | > f(x,y)=x^2+y^2 414 | x^2+y^2 415 | > f(1,2) // evaluates f(x,y) at x=1, y=2, so 1^2+2^2=5 416 | 5 417 | > f(x,y) // graphs f(x,y) in 3D 418 | x^2+y^2 419 | > a=3^3 420 | 3^3 421 | > cbrt(a) 422 | 3 423 | > im(exp(xi)) // graphs the imag part of exp(xi) in 2D, so sin(x) 424 | im(exp(x*1i)) 425 | > f(x,y,z,w)=x+y+z+w 426 | x+y+z+w 427 | > f(1,2,3,4) // evaluates f(x,y,z,w) at x=1, y=2, z=3, w=4, so 1+2+3+4=10 428 | 10 429 | > f(x,y,2,5) // graphs f(x,y,2,5) in 3D with z=2 and w=5 so x+y+2+5 430 | x+y+2+5 431 | > f(2,5,x,y) // graphs f(2,5,x,y) in 3D with x=2 and y=5 so 2+5+x+y, to graph x and y have to be the unknown variables 432 | 2+5+x+y 433 | > |z| // graphs |(x+yi)| in 3D 434 | norm((x+y+1i)) 435 | > deg // enables degrees 436 | > pol({5,3,2}+{1,2,3}) // prints {magnitude, θ, φ} of {5,3,2}+{1,2,3} 437 | {9.273618495496,57.373262293469,39.805571092265} 438 | > piecewise({+-sqrt(2^2-x^2),(x<2)&&(x>-2)}) # 3{cos(x),sin(x)} # [5,x] # graph=flat;exp(ix) //graphing circles 4 different ways 439 | piecewise({0±sqrt(2^2-x^2),(x<2)&&(x>-2)}) 440 | 3*{cos(x),sin(x)} 441 | exp(1i*x) 442 | ``` 443 | 444 | ### cli usage 445 | 446 | ``` 447 | echo -ne 'sqrt(pi) \n pi^2'|kalc 448 | 1.7724538509055159 449 | 9.869604401089358 450 | 451 | kalc 'sqrt(pi)' 'pi^2' 452 | 1.7724538509055159 453 | 9.869604401089358 454 | 455 | echo -ne 'sin(x)#cos(x)'|kalc // graphs sin(x) and cos(x) in 2D 456 | kalc 'sin(x)#cos(x)' // graphs sin(x) and cos(x) in 2D 457 | ``` 458 | 459 | ### more advanced usage 460 | 461 | see kalc.vars in repo 462 | 463 | # graphing 464 | 465 | my gnuplot config in ~/.gnuplot 466 | 467 | ``` 468 | set terminal x11 469 | set xyplane 0 470 | ``` 471 | 472 | chars available for point style: 473 | 474 | ``` 475 | . - dot 476 | + - plus 477 | x - cross 478 | * - star 479 | s - empty square 480 | S - filled square 481 | o - empty circle 482 | O - filled circle 483 | t - empty triangle 484 | T - filled triangle 485 | d - empty del (upside down triangle) 486 | D - filled del (upside down triangle) 487 | r - empty rhombus 488 | R - filled rhombus 489 | ``` 490 | -------------------------------------------------------------------------------- /img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bgkillas/kalc/2907667074357d2065212dde2de944842a37ea26/img.png -------------------------------------------------------------------------------- /kalc.config: -------------------------------------------------------------------------------- 1 | #options are deg/rad/grad 2 | angle=rad 3 | #options are n(ormal), s(cientific), e/E, for scientific notation 4 | notation=n 5 | #options are normal, domain, domain_alt, depth, flat, none 6 | graph=normal 7 | #if use gnuplot instead of kalc plot when both exist 8 | gnuplot=false 9 | #option to keep data file in tmp directory after graphing 10 | keep_data_file=false 11 | default_units=null 12 | progress=false 13 | keepzeros=false 14 | base=10,10 15 | polar=false 16 | #fractions for numbers 17 | fractions=true 18 | #fractions for vectors 19 | fractionsv=true 20 | #fractions for matrixes 21 | fractionsm=false 22 | rt=true 23 | deci=12 24 | ticks=16,16,16 25 | #no color if non interactive 26 | color=auto 27 | prompt=true 28 | comma=false 29 | prec=512 30 | graphprec=128 31 | xr=-8,8 32 | yr=-8,8 33 | zr=-8,8 34 | vxr=0,0 35 | vyr=0,0 36 | vzr=0,0 37 | 2d=8192 38 | 3d=256,256 39 | point=. 40 | #no lines unless vectors are being graphed 41 | lines=auto 42 | multi=true 43 | tabbed=false 44 | vars=true 45 | debug=false 46 | surface=false 47 | onaxis=true 48 | scalegraph=false 49 | #wont go into interactive shell after executing args 50 | interactive=false 51 | label=x,y,z 52 | graphcli=false 53 | units=true 54 | siunits=false 55 | windowsize=0,0 56 | saveto=null 57 | #time to process until realtime printing stops in milliseconds 58 | slowcheck=256 59 | #https://en.wikipedia.org/wiki/ANSI_escape_code#Colors 60 | textc=0m 61 | promptc=94m 62 | imagc=93m 63 | scic=92m 64 | unitsc=96m 65 | bracketc=91m,92m,93m,94m,95m,96m 66 | #graph line color 67 | re1col=ff5555,5555ff,ff55ff,55ff55,55ffff,ffff55 68 | im1col=aa0000,0000aa,aa00aa,00aa00,00aaaa,aaaa00 69 | -------------------------------------------------------------------------------- /kalc.vars: -------------------------------------------------------------------------------- 1 | #example functions used later on 2 | f(x)=x^3-x 3 | 4 | #tangent line at point p of function f(x) 5 | t(x,p)=f'(p)(x-p)+f(p) 6 | #so f(x) # t(x,1) # t(x,-2) will show the tangent line of f(x) at 1, which intersects at -2p so -2 7 | 8 | #perpendicular to the tangent at given point p 9 | pt(x,p)=(p-x)/f'(p)+f(p) 10 | 11 | #vertical line from top down reflecting at point p of f(x), to graph original line run y0+p 12 | r(x,p)=fm=f'(p):(x-p)(fm^2-1)/(2fm)+f(p) 13 | #to only show the reflection 14 | #r(x,p)=pw({x(f'(p)^2-1)/(2f'(p))+f(p)-p*(f'(p)^2-1)/(2f'(p)),(sgn(f'(p))==-1&&x>=p)||(sgn(f'(p))==1&&x<=p)}) 15 | 16 | #r(x,p) extended to a line mx+b reflecting off of f(x) at point p 17 | r(x,p,m)=(x-p)tan(2atan(f'(p))-atan(m))+f(p) 18 | #in reference to the vars for the function the original line would be mx+f(p)-m*p 19 | rl(x,p,m)=m(x-p)+f(p) 20 | 21 | #newtons method to find 0, off of f(x) 22 | n(x)=x-f(x)/f'(x) 23 | 24 | #trapazoidal method of approximenting area under the curve as n goes towards infinity 25 | ar(a,b,n)=sum(k,(b-a)/n(f(a+k(b-a)/n)+f(a+(k+1)(b-a)/n))/2,0,n-1) 26 | 27 | #basic method of approximenting arc length as n goes towards infinity 28 | al(a,b,n)=sum(k,sqrt(((b-a)/n)^2+(f(a+(k+1)(b-a)/n)-f(a+k(b-a)/n))^2),0,n-1) 29 | #gl(a,b,n) shows the lines al(a,b,n) uses to calculate the arc length, so vrange=6;f(x);gl(0,2,4) shows 4 lines that approximate the arc length of f(x) from 0 to 2 30 | gl(a,b,n)=mat(k,{a+k(b-a)/n,f(a+k(b-a)/n)},0,n) 31 | 32 | #nth derivitive, precision should be around n*128, so this fails at the 5th derivitive at default precision 33 | #dn(x,n)=sum(k,(-1)^k C(n,k) f(x+(n-k)2^-100),0,n)/2^(-100n) 34 | #dn(x,n)=pw({slope(p,dn(p,n-1),x),n>=1},{f(x),1}) 35 | 36 | #f(x) rotated by θ 37 | fr(x,θ)=φ=atan(x,f(x))+θ:{cos(φ),sin(φ)}sqrt(x^2+f(x)^2) 38 | 39 | #the following is a function to estimate the path of a moving positive charge under the effects of any number of stationary positive or negitive charges, loss of accuracy when close to a stationary charge 40 | #c is the starting {x,y,vx,vy} of the moving charge 41 | #t is the time intervals that will be computed 42 | #a is the cordonates and charge of the stationary charges, organized in a matrix like {{x1,y1,c1},{x2,y2,c2}...{xN,yN,cN}} 43 | #example graph function with the moving charge stationary at the origin with 1/10th second time intervals and a positive chage at {0,1} and negitive charge at {2,0} 44 | #part(iter(g,ef(g,1/10,{{0,1,1},{2,0,-1}}),{0,0,0,0},100,1),-1,0..1))#{{0,1}}#{{2,0}} 45 | ef(c,t,a)=x=part(c,0):y=part(c,1):vx=part(c,2):vy=part(c,3):r=vec(i,(part(a,i,0)-x)^2+(part(a,i,1)-y)^2,0,len(a)-1):θ=mat(i,{part(a,i,0)-x,part(a,i,1)-y}/sqrt(part(r,i)),0,len(a)-1):xp=sum(i,-part(a,i,2)part(θ,i,0)/part(r,i),0,len(a)-1):yp=sum(i,-part(a,i,2)part(θ,i,1)/part(r,i),0,len(a)-1):{x+t*vx+t^2/2*xp,y+t*vy+t^2/2*yp,vx+t*xp,vy+t*yp} 46 | 47 | #refraction of light using snells law, x=1 to x=2 is considered a different medium with a refraction index of 'b', 'm' is starting slope of line, 'a' is refraction index outside of x=1 to x=2 48 | #graphing s(x,2,1.5,1.75) will show a refraction example with an index of refraction of 1.5 going to 1.75 with a initial slope of 2 49 | s(x,m,a,b)=d=(am/sqrt(m^2+1)/b)/(sqrt(1-(am/sqrt(m^2+1)/b)^2)):r=(bd/sqrt(d^2+1)/a)/(sqrt(1-(bd/sqrt(d^2+1)/a)^2)):pw({rx+d-r,x>2},{dx+m-d,2>x>1},mx) 50 | 51 | #turns a complex number into coordinates on a riemann sphere 52 | rs(z)=θ=atan(re(z),im(z)):c=cos(θ):s=sin(θ):n=1-2/(|z|+1):r=sqrt((1-n^2)/(c^2+s^2)):{c r,s r,n} 53 | 54 | #nth deritivive of x^p at x=b, negitive p values corrospond to the anti derititive. cant graph negitive integers p likely do to logarithms from integration, however where logarithms for integration do not apply the whole numbers will work, ie g(-1,-2,3)=-1/3 but g(-2,-2,3) will have a logarithm so it fails 55 | g(n,p,b)=P(p,n) b^(p-n) 56 | #below works for -p values but does not integrate properly for -p values 57 | #g(n,p,b)=lim(a,re(P(p+ai,n)),0) b^(p-n) 58 | #another continuation that can graph negitive p values, however it outputs complex numbers at non whole n values 59 | #g(n,p,b)=(-1)^n b^(p-n) ph(-p,n) 60 | #for p=-1 fixes negitive integer n values 61 | #g(n,p,b)=lim(a,(-1)^(n+a) b^(p-n-a) ph(-p,n+a) + b^(p-n) / (a(p-n)!),0) 62 | 63 | 64 | #functions used for tangent planes 65 | z(x,y)=x^3-x+y^3-y 66 | zx(x,y)=slope(p,z(p,y),x) 67 | zy(x,y)=slope(p,z(x,p),y) 68 | #tangent plane at point px, py 69 | zt(x,y,px,py)=(zx(px,py))*x+(zy(px,py))*y+(z(px,py)-zx(px,py)*px-zy(px,py)*py) 70 | #so z(x,y) # zt(x,y,2,3) will have the tangent plane of z(x,y) at (2,3) 71 | 72 | #z(x,y) rotated by θ and φ 73 | zr(x,y,θ,φ)=α=atan(z(x,y),sqrt(x^2+y^2))+φ:β=atan(x,y)+θ:{sin(α)cos(β),sin(α)sin(β),cos(α)}sqrt(x^2+y^2+z(x,y)^2) 74 | 75 | 76 | #gets how many digits match, ch(22/7,pi)=3 as 3.142.. equals 3.141.. upto the third decimal 77 | ch(a,b)=floor(log(10,max{a,b}))-floor(log(10,|a-b|)) 78 | 79 | 80 | #i,j,k unit vectors if you like those 81 | #i={1,0,0} 82 | #j={0,1,0} 83 | #k={0,0,1} 84 | 85 | #a cube given by 3d points 86 | cube={{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,0},{0,0,1},{0,1,1},{0,1,0},{0,1,1},{1,1,1},{1,1,0},{1,1,1},{1,0,1},{1,0,0},{1,0,1},{0,0,1}} 87 | #the following is graphing this cube and it rotated pi/4 rad in yaw a roll directions 88 | #ticks=3;xr=-1,2;yr=-1,2;zr=1.5;cube#cube*rotate(pi/4,0,pi/4) 89 | 90 | #minimum distance between b^x and log(b,x) over b where b>=root(e,e) 91 | minexp(x)=sqrt(2)log(x,eln(x)) 92 | 93 | 94 | #minimum distance between left and right side of x^-(2n+1) over n(n is natural) 95 | minpow(x)=2sqrt(root(x,2x+2)^2+root(x,2x+2)^(-2*x)) 96 | 97 | 98 | #minimum distance between sec(a*x) and its inverse, asec(x)/a 99 | minsec(x)=sqrt(2)(sec(asin((sqrt(x^2+4)-x)/2))-(asin((sqrt(x^2+4)-x)/2)/x)) 100 | 101 | 102 | #following is minimum distance between the center curve and curve right of tan(a*x) 103 | #distance between (x,tan(ax)) and (pi/a-x,-tan(ax)) 104 | disttan(x,a)=sqrt((2x-pi/a)^2+4tan(ax)^2) 105 | 106 | #derivitive of above set to 0 simplified 107 | mintan(x,a)=x+a*sin(ax)/cos(ax)^3-pi/(2a) 108 | 109 | #derivitive of above to find 0 by newtons method 110 | mintanp(x,a)=a^2((1+2sin(ax)^2)/cos(ax)^4)+1 111 | 112 | #modified newtons method to allow graphing along 'a' 113 | n(x,a)=x-mintan(x,a)/mintanp(x,a) 114 | 115 | #disttan(n(n(n(n(1/x,x),x),x),x),x) for example will graph it fairly nicely, we start with 1/x to scale properly and not get trapped in a asymptote 116 | #the following graphically shows that it finds the minimum for just tan(c*x) by inputing the following into the calculator as the circles only intersect the other curve once with 1 line going between the 2 points of interest and the other should intersect the 2 circles at the same points while being perpendicular to the other line, you may need to increase the amount of 'n' to increase precision 117 | # c=2 ; a=n(n(n(n(n(1/(2c),c),c),c),c),c) ; b=disttan(a,c) ; tan(c*x) # piecewise({+-sqrt(b^2-(x-a)^2)+tan(a*c),x<=(a+b)&&x>=(a-b)}) # piecewise({+-sqrt(b^2-(x-(pi/c-a))^2)-tan(c*a),x<=((pi/c-a)+b)&&x>=((pi/c-a)-b)}) # (-2tan(a*c)/(pi/c-2a))x+tan(a*c)-(-2tan(a*c)/(pi/c-2a))a # x*c*sec(a*c)^2-sec(a*c)^2*pi/2 118 | 119 | 120 | #{year,month,day,hour,min,second} derived from epoch time, with o as hour offset 121 | #date(o)=t=epoch:{1970+floor(t->year),floor((fract(t->year)year->day)/30.4375)+1,floor(fract((fract(t->year)year->day)/30.4375)day30.4375->day),floor(fract(fract(t->year)year->day)day->hour)+o,floor(fract(fract(fract(t->year)year->day)day->hour)hour->min),floor(fract(fract(fract(fract(t->year)year->day)day->hour)hour->min)min->second)} 122 | 123 | 124 | #gets the distribution data for the sum of k amounts of n sided die starting at 0, dice(6,2,2) will give the frequency that 2 6 sided die will give a sum of 4 or (p+k) which is 3 so 3/6^2 will give the chance of rolling a sum of 4 from 2 6 sided die, than you can use 'vec(b,dice(6,2,b),0,(6-1)2)' to get the entire distribution data for 2 6 sided die 125 | #dice(n,k,p)=piecewise({1,p==0},{0,(0>p)||(p>(k(n-1)))},{sum(a,dice(n,k-1,p-a),0,n-1),1}) 126 | 127 | 128 | #hyperoperation function 129 | H(a,n,b)=piecewise({b+1,n==0},{a,n==1&&b==0},{0,n==2&&b==0},{1,n>=3&&b==0},{H(a,n-1,H(a,n,b-1)),1}) 130 | 131 | #some recursive sin function 132 | recsin(x)=iter(a,sin(x/(|x-a|+1)),sin(1),16)/sin(1) 133 | #recsin(x)=iter(a,sin(πx/(2|x-a|+2)),sin(1),16) 134 | #recsin(x)=iter(a,sin(x/(|x-a|+1))/sin(1),sin(1),16) 135 | #recsin(x)=iter(a,sin(x/(|x-a|+1)),sin(1),16) 136 | 137 | #graph of the chance for the sum of 2 die to be less then value of a card picked 138 | # a=dice{6,6} ; b=1..13 ; vec(c,part(a,c)*part(b,c),0,10) # vec(c,part(a,c)*(13-part(b,c)),0,10) 139 | 140 | 141 | #vector input example, m{1,2,3,4}=1^2+2^2+3^2+4^2 142 | m(v)=sum(a,part(v,a)^2,0,len(v)-1) 143 | 144 | 145 | #x^3+px+q=0, depressed cubic :c 146 | dc(p,q)=cbrt(-q/2+sqrt(q^2/4+p^3/27))+cbrt(-q/2-sqrt(q^2/4+p^3/27)) 147 | 148 | 149 | #complex expansion of fibonacci sequence 150 | fibonacci(x)=(φ^x-(-1/φ)^x)/sqrt(5) 151 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use crossterm::{ 2 | cursor::{DisableBlinking, EnableBlinking}, 3 | execute, terminal, 4 | }; 5 | #[cfg(feature = "gnuplot")] 6 | use kalc_lib::graph::graph; 7 | use kalc_lib::misc::get_word_bank; 8 | #[cfg(all(feature = "kalc-plot", feature = "serde"))] 9 | use kalc_lib::units::Data; 10 | use kalc_lib::{ 11 | help::help_for, 12 | load_vars::{add_var, get_cli_vars, get_file_vars, get_vars, set_commands_or_vars}, 13 | math::do_math, 14 | misc::{ 15 | clear, clearln, convert, end_word, get_terminal_dimensions, handle_err, insert_last, 16 | prompt, read_single_char, to_output, write, 17 | }, 18 | options::{arg_opts, commands, equal_to, file_opts, silent_commands}, 19 | parse::input_var, 20 | print::{print_answer, print_concurrent}, 21 | units::{Colors, HowGraphing, Options, Variable}, 22 | }; 23 | #[cfg(any(feature = "kalc-plot", feature = "gnuplot"))] 24 | use std::thread::{self, JoinHandle}; 25 | use std::{ 26 | cmp::{Ordering, min}, 27 | env::args, 28 | fs::{File, OpenOptions}, 29 | io::{BufRead, BufReader, Error, IsTerminal, Stdout, Write, stdin, stdout}, 30 | time::Instant, 31 | }; 32 | #[cfg(feature = "kalc-plot")] 33 | use std::{ 34 | env, 35 | path::{Path, PathBuf}, 36 | process::Stdio, 37 | }; 38 | fn main() -> Result<(), Error> { 39 | let mut colors = Colors::default(); 40 | let mut options = Options::default(); 41 | let mut args = args().collect::>(); 42 | let mut default = false; 43 | let dir = dirs::config_dir().unwrap().to_str().unwrap().to_owned() + "/kalc"; 44 | std::fs::create_dir_all(dir.clone())?; 45 | let mut check = Vec::new(); 46 | { 47 | let file_path = dir.clone() + "/kalc.config"; 48 | if let Ok(s) = file_opts( 49 | &mut options, 50 | &mut colors, 51 | &file_path, 52 | &Vec::new(), 53 | Vec::new(), 54 | true, 55 | ) { 56 | check = s; 57 | } 58 | if let Ok(s) = arg_opts(&mut options, &mut colors, &mut args, &Vec::new(), true) { 59 | default = s; 60 | } 61 | } 62 | if !stdin().is_terminal() { 63 | let lines = stdin() 64 | .lock() 65 | .lines() 66 | .map(Result::unwrap) 67 | .filter(|l| !l.is_empty() && !l.starts_with("#")); 68 | args.splice(0..0, lines); 69 | } 70 | options.interactive = args.is_empty(); 71 | let mut stdout = stdout(); 72 | if options.interactive { 73 | options.color.auto_set(true); 74 | terminal::enable_raw_mode()?; 75 | print!( 76 | "\x1b[G\x1b[K{}{}", 77 | prompt(options, &colors), 78 | if options.color.as_bool() { 79 | "\x1b[0m" 80 | } else { 81 | "" 82 | } 83 | ); 84 | stdout.flush()?; 85 | } 86 | for arg in args.iter_mut() { 87 | let c = arg.as_bytes(); 88 | if c[0] == c[arg.len() - 1] && matches!(c[0], b'\'' | b'"') { 89 | arg.remove(0); 90 | arg.pop(); 91 | } 92 | } 93 | 94 | let file_path = dir.clone() + "/kalc.vars"; 95 | let mut vars: Vec = 96 | if options.allow_vars && (options.interactive || options.stay_interactive) { 97 | get_vars(options) 98 | } else { 99 | Default::default() 100 | }; 101 | let mut err = false; 102 | let base = options.base; 103 | let mut argsj = args.join(" "); 104 | if !check.is_empty() { 105 | argsj += " "; 106 | let file_path = dir.clone() + "/kalc.config"; 107 | argsj += &BufReader::new(File::open(file_path)?) 108 | .lines() 109 | .map(Result::unwrap) 110 | .collect::>() 111 | .join(" "); 112 | } 113 | 114 | if !options.interactive && options.allow_vars && !options.stay_interactive { 115 | get_cli_vars(options, argsj.clone(), &mut vars) 116 | } 117 | 118 | if options.allow_vars && !default { 119 | options.base = (10, 10); 120 | if let Ok(file) = File::open(&file_path) { 121 | let lines = BufReader::new(file) 122 | .lines() 123 | .map(Result::unwrap) 124 | .filter_map(|l| (!l.starts_with('#') && !l.is_empty()).then_some(l)) 125 | .collect::>(); 126 | let mut split; 127 | let mut blacklist = if options.interactive || options.stay_interactive { 128 | Vec::new() 129 | } else { 130 | vars.iter() 131 | .map(|v| v.name.iter().collect::()) 132 | .collect::>() 133 | }; 134 | 'upper: for i in lines.clone() { 135 | split = i.splitn(2, '='); 136 | let l = split.next().unwrap().to_string(); 137 | let left = if l.contains('(') { 138 | l.split('(').next().unwrap().to_owned() 139 | } else { 140 | l.clone() 141 | }; 142 | if options.interactive 143 | || options.stay_interactive 144 | || (!blacklist.contains(&l) && { 145 | let mut b = false; 146 | let mut word = String::new(); 147 | for c in argsj.chars() { 148 | if c.is_alphanumeric() || matches!(c, '\'' | '`' | '_') { 149 | word.push(c) 150 | } else { 151 | if l.contains('(') { 152 | b = word.trim_end_matches('\'').trim_end_matches('`') == left 153 | && matches!(c, '(' | '{' | '[' | '|'); 154 | } else { 155 | b = word == left; 156 | } 157 | if b { 158 | break; 159 | } 160 | word.clear() 161 | } 162 | } 163 | b 164 | }) 165 | { 166 | if let Some(r) = split.next() { 167 | let le = l.chars().collect::>(); 168 | if !options.interactive && !options.stay_interactive { 169 | blacklist.push(l); 170 | get_file_vars(options, &mut vars, lines.clone(), r, &mut blacklist); 171 | } 172 | for (i, v) in vars.iter().enumerate() { 173 | if v.name.split(|c| c == &'(').next() == le.split(|c| c == &'(').next() 174 | && v.name.contains(&'(') == le.contains(&'(') 175 | && v.name.iter().filter(|&&c| c == ',').count() 176 | == le.iter().filter(|&&c| c == ',').count() 177 | { 178 | if r == "null" { 179 | if let Err(s) = 180 | add_var(le, r, i, &mut vars, options, true, true, true) 181 | { 182 | err = true; 183 | println!("\x1b[G\x1b[K{s}") 184 | } 185 | } else if let Err(s) = 186 | add_var(le, r, i, &mut vars, options, true, true, false) 187 | { 188 | err = true; 189 | println!("\x1b[G\x1b[K{s}") 190 | } 191 | continue 'upper; 192 | } 193 | } 194 | for (i, j) in vars.iter().enumerate() { 195 | if j.name.len() <= le.len() { 196 | if let Err(s) = 197 | add_var(le, r, i, &mut vars, options, false, false, false) 198 | { 199 | err = true; 200 | println!("\x1b[G\x1b[K{s}") 201 | } 202 | continue 'upper; 203 | } 204 | } 205 | if let Err(s) = add_var(le, r, 0, &mut vars, options, false, false, false) { 206 | err = true; 207 | println!("\x1b[G\x1b[K{s}") 208 | } 209 | } 210 | } 211 | } 212 | } 213 | } 214 | let file_path = dir.clone() + "/kalc.config"; 215 | 216 | if !check.is_empty() { 217 | if let Err(s) = file_opts(&mut options, &mut colors, &file_path, &vars, check, false) { 218 | println!("{s}"); 219 | std::process::exit(1); 220 | } 221 | } 222 | 223 | if let Err(s) = arg_opts(&mut options, &mut colors, &mut args, &vars, false) { 224 | println!("{s}"); 225 | std::process::exit(1); 226 | } 227 | 228 | if options.interactive && err { 229 | print!( 230 | "\x1b[G\x1b[K{}{}", 231 | prompt(options, &colors), 232 | if options.color.as_bool() { 233 | "\x1b[0m" 234 | } else { 235 | "" 236 | } 237 | ); 238 | stdout.flush()?; 239 | } 240 | options.base = base; 241 | let (mut file, mut unmod_lines) = if options.interactive || options.stay_interactive { 242 | options.color.auto_set(true); 243 | let file_path = &(dir.clone() + "/kalc.history"); 244 | File::open(file_path).unwrap_or_else(|_| File::create(file_path).unwrap()); 245 | 246 | ( 247 | Some(OpenOptions::new().append(true).open(file_path)?), 248 | Some( 249 | BufReader::new(File::open(file_path)?) 250 | .lines() 251 | .map(Result::unwrap) 252 | .collect::>(), 253 | ), 254 | ) 255 | } else { 256 | options.color.auto_set(false); 257 | (None, None) 258 | }; 259 | #[cfg(any(feature = "gnuplot", feature = "kalc-plot"))] 260 | let mut handles: Vec> = Vec::new(); 261 | let mut cut: Vec = Vec::new(); 262 | 263 | 'main: loop { 264 | let mut input = Vec::new(); 265 | let mut graphable = HowGraphing::default(); 266 | let mut varcheck = false; 267 | #[cfg(feature = "gnuplot")] 268 | let mut last = Vec::new(); 269 | #[cfg(not(feature = "gnuplot"))] 270 | let last: Vec; 271 | if !args.is_empty() { 272 | let watch = options.debug.then(Instant::now); 273 | input = args.remove(0).chars().collect(); 274 | let output; 275 | let funcvar; 276 | { 277 | let mut options = options; 278 | let mut unparsed = input.clone(); 279 | { 280 | let split = input.split(|c| c == &';'); 281 | let count = split.clone().count(); 282 | if count != 1 { 283 | unparsed = split.clone().next_back().unwrap().to_vec(); 284 | for (i, s) in split.enumerate() { 285 | if i == count - 1 { 286 | break; 287 | } 288 | silent_commands( 289 | &mut options, 290 | &s.iter() 291 | .copied() 292 | .filter(|&c| !c.is_whitespace()) 293 | .collect::>(), 294 | ); 295 | if s.contains(&'=') { 296 | if let Err(s) = 297 | set_commands_or_vars(&mut colors, &mut options, &mut vars, s) 298 | { 299 | eprintln!("{s}"); 300 | continue 'main; 301 | } 302 | } 303 | } 304 | } 305 | let tempinput = unparsed.iter().collect::(); 306 | if tempinput.starts_with("help ") { 307 | println!("{}", help_for(tempinput.splitn(2, ' ').last().unwrap())); 308 | continue; 309 | } else if tempinput.ends_with('=') { 310 | println!( 311 | "{}", 312 | equal_to( 313 | options, 314 | &colors, 315 | &vars, 316 | &tempinput[..tempinput.len().saturating_sub(1)], 317 | "", 318 | ) 319 | ); 320 | continue; 321 | } 322 | } 323 | (output, funcvar, graphable, varcheck, _) = match input_var( 324 | &unparsed.iter().map(convert).collect::(), 325 | &vars, 326 | &mut Vec::new(), 327 | &mut 0, 328 | options, 329 | false, 330 | 0, 331 | Vec::new(), 332 | false, 333 | &mut Vec::new(), 334 | None, 335 | None, 336 | ) { 337 | Ok(f) => f, 338 | Err(s) => { 339 | eprintln!("{}: {s}", input.iter().collect::()); 340 | continue; 341 | } 342 | }; 343 | if !graphable.graph && !varcheck { 344 | match do_math(output, options, funcvar) { 345 | Ok(n) => print_answer(n, options, &colors), 346 | Err(s) => { 347 | eprintln!("{}: {s}", input.iter().collect::()); 348 | continue; 349 | } 350 | } 351 | 352 | println!( 353 | "{}", 354 | watch 355 | .map(|t| " ".to_owned() + &t.elapsed().as_nanos().to_string()) 356 | .unwrap_or_default() 357 | ); 358 | } 359 | } 360 | } else { 361 | if !options.interactive { 362 | if options.stay_interactive { 363 | setup_for_interactive(&colors, &mut options, &mut stdout)? 364 | } else { 365 | #[cfg(any(feature = "gnuplot", feature = "kalc-plot"))] 366 | for handle in handles { 367 | handle.join().unwrap(); 368 | } 369 | break; 370 | } 371 | } 372 | let mut long = false; 373 | let mut frac = 0; 374 | let mut placement = 0; 375 | let mut current = Vec::new(); 376 | let mut lines = unmod_lines.clone().unwrap(); 377 | let mut i = lines.len(); 378 | last = if i == 0 { 379 | "".chars() 380 | } else if lines[i - 1].ends_with('\t') { 381 | lines[i - 1][..lines[i - 1].len() - 1].chars() 382 | } else { 383 | lines[i - 1].chars() 384 | } 385 | .collect(); 386 | 387 | let [mut start, mut end, mut xxpos] = [0; 3]; 388 | let [mut slow, mut firstslow, mut xxbool, mut xxstart] = [false; 4]; 389 | let mut lastd = get_terminal_dimensions(); 390 | loop { 391 | let c = read_single_char(); 392 | let watch = Instant::now(); 393 | { 394 | let d = get_terminal_dimensions(); 395 | if lastd != d { 396 | lastd = d; 397 | end = start + get_terminal_dimensions().0 398 | - if options.prompt { 3 } else { 1 }; 399 | end = min(end, input.len()); 400 | placement = min(placement, end); 401 | if options.real_time_output && !slow { 402 | execute!(stdout, DisableBlinking)?; 403 | (frac, graphable, long, varcheck) = print_concurrent( 404 | &input, 405 | &last, 406 | &vars, 407 | options, 408 | colors.clone(), 409 | start, 410 | end, 411 | false, 412 | ); 413 | if watch.elapsed().as_millis() > options.slowcheck { 414 | firstslow = true; 415 | slow = true; 416 | } 417 | } else if options.real_time_output && firstslow { 418 | firstslow = false; 419 | handle_err( 420 | "too slow, will print on enter", 421 | &vars, 422 | &input, 423 | options, 424 | &colors, 425 | start, 426 | end, 427 | ) 428 | } else { 429 | clearln(&input, &vars, start, end, options, &colors); 430 | } 431 | if options.debug { 432 | let time = watch.elapsed().as_nanos(); 433 | print!( 434 | " {}\x1b[{}D", 435 | time, 436 | time.to_string().len() + 1 + end - placement 437 | ); 438 | } else if end - placement != 0 { 439 | print!("\x1b[{}D", end - placement) 440 | } 441 | } 442 | } 443 | match c { 444 | '\n' | '\x14' | '\x09' | '\x06' => { 445 | if c != '\x14' && c != '\x06' { 446 | execute!(stdout, DisableBlinking)?; 447 | } 448 | end = start + get_terminal_dimensions().0 449 | - if options.prompt { 3 } else { 1 }; 450 | end = min(end, input.len()); 451 | if (!options.real_time_output || long || (slow && !firstslow)) 452 | && (!input.is_empty() && !input.starts_with(&['#'])) 453 | && c != '\x14' 454 | && c != '\x06' 455 | { 456 | (frac, graphable, _, varcheck) = print_concurrent( 457 | &input, 458 | &last, 459 | &vars, 460 | options, 461 | colors.clone(), 462 | start, 463 | end, 464 | c == '\n', 465 | ); 466 | slow = watch.elapsed().as_millis() > options.slowcheck; 467 | } 468 | if c == '\x09' { 469 | clear(&input, &vars, start, end, options, &colors); 470 | } else { 471 | if !input.is_empty() && !input.starts_with(&['#']) && frac != 0 { 472 | print!("\x1b[{frac}B"); 473 | } 474 | if c == '\x14' || c == '\x06' { 475 | print!("\x1b[G{}\x1b[J", if input.is_empty() { "\n" } else { "" }); 476 | terminal::disable_raw_mode()?; 477 | std::process::exit(0); 478 | } 479 | } 480 | print!("\x1b[G\n\x1b[K"); 481 | break; 482 | } 483 | '\x03' => { 484 | //ctrl+backspace 485 | if placement != 0 && end_word(input[placement - 1]) { 486 | placement -= 1; 487 | input.remove(placement); 488 | } else { 489 | for (i, c) in input[..placement].iter().rev().enumerate() { 490 | if c.is_whitespace() || i + 1 == placement { 491 | input.drain(placement - i - 1..placement); 492 | placement -= i + 1; 493 | break; 494 | } 495 | if end_word(*c) { 496 | input.drain(placement - i..placement); 497 | placement -= i; 498 | break; 499 | } 500 | } 501 | } 502 | end = min(end, input.len()); 503 | start = min(start, end); 504 | if i == lines.len() { 505 | current.clone_from(&input); 506 | } else { 507 | lines[i] = input.clone().iter().collect::(); 508 | } 509 | if options.real_time_output && !slow { 510 | execute!(stdout, DisableBlinking)?; 511 | (frac, graphable, long, varcheck) = print_concurrent( 512 | &input, 513 | &last, 514 | &vars, 515 | options, 516 | colors.clone(), 517 | start, 518 | end, 519 | false, 520 | ); 521 | if watch.elapsed().as_millis() > options.slowcheck { 522 | firstslow = true; 523 | slow = true; 524 | } 525 | } else if options.real_time_output && firstslow { 526 | firstslow = false; 527 | handle_err( 528 | "too slow, will print on enter", 529 | &vars, 530 | &input, 531 | options, 532 | &colors, 533 | start, 534 | end, 535 | ) 536 | } else { 537 | clearln(&input, &vars, start, end, options, &colors); 538 | } 539 | if options.debug { 540 | let time = watch.elapsed().as_nanos(); 541 | print!( 542 | " {}\x1b[{}D", 543 | time, 544 | time.to_string().len() + 1 + end - placement 545 | ); 546 | } else if end - placement != 0 { 547 | print!("\x1b[{}D", end - placement) 548 | } 549 | if input.is_empty() { 550 | slow = false; 551 | clear(&input, &vars, start, end, options, &colors); 552 | } 553 | } 554 | '\x08' => { 555 | //backspace 556 | if placement - start == 0 && start != 0 { 557 | start -= 1; 558 | } 559 | if placement != 0 { 560 | placement -= 1; 561 | input.remove(placement); 562 | } 563 | end = start + get_terminal_dimensions().0 564 | - if options.prompt { 3 } else { 1 }; 565 | end = min(end, input.len()); 566 | if i == lines.len() { 567 | current.clone_from(&input); 568 | } else { 569 | lines[i] = input.clone().iter().collect::(); 570 | } 571 | if options.real_time_output && !slow { 572 | execute!(stdout, DisableBlinking)?; 573 | (frac, graphable, long, varcheck) = print_concurrent( 574 | &input, 575 | &last, 576 | &vars, 577 | options, 578 | colors.clone(), 579 | start, 580 | end, 581 | false, 582 | ); 583 | if watch.elapsed().as_millis() > options.slowcheck { 584 | firstslow = true; 585 | slow = true; 586 | } 587 | } else if options.real_time_output && firstslow { 588 | firstslow = false; 589 | handle_err( 590 | "too slow, will print on enter", 591 | &vars, 592 | &input, 593 | options, 594 | &colors, 595 | start, 596 | end, 597 | ) 598 | } else { 599 | clearln(&input, &vars, start, end, options, &colors); 600 | } 601 | if options.debug { 602 | let time = watch.elapsed().as_nanos(); 603 | print!( 604 | " {}\x1b[{}D", 605 | time, 606 | time.to_string().len() + 1 + end - placement 607 | ); 608 | } else if end - placement != 0 { 609 | print!("\x1b[{}D", end - placement) 610 | } 611 | if input.is_empty() { 612 | slow = false; 613 | clear(&input, &vars, start, end, options, &colors); 614 | } 615 | } 616 | '\x7F' => { 617 | //delete 618 | if placement == input.len() { 619 | continue; 620 | } 621 | if placement - start == 0 && start != 0 { 622 | start -= 1; 623 | } 624 | if !input.is_empty() { 625 | input.remove(placement); 626 | } 627 | end = start + get_terminal_dimensions().0 628 | - if options.prompt { 3 } else { 1 }; 629 | end = min(end, input.len()); 630 | start = min(start, end); 631 | if i == lines.len() { 632 | current.clone_from(&input); 633 | } else { 634 | lines[i] = input.clone().iter().collect::(); 635 | } 636 | if options.real_time_output && !slow { 637 | execute!(stdout, DisableBlinking)?; 638 | (frac, graphable, long, varcheck) = print_concurrent( 639 | &input, 640 | &last, 641 | &vars, 642 | options, 643 | colors.clone(), 644 | start, 645 | end, 646 | false, 647 | ); 648 | if watch.elapsed().as_millis() > options.slowcheck { 649 | firstslow = true; 650 | slow = true; 651 | } 652 | } else if options.real_time_output && firstslow { 653 | firstslow = false; 654 | handle_err( 655 | "too slow, will print on enter", 656 | &vars, 657 | &input, 658 | options, 659 | &colors, 660 | start, 661 | end, 662 | ) 663 | } else { 664 | clearln(&input, &vars, start, end, options, &colors); 665 | } 666 | if options.debug { 667 | let time = watch.elapsed().as_nanos(); 668 | print!( 669 | " {}\x1b[{}D", 670 | time, 671 | time.to_string().len() + 1 + end - placement 672 | ); 673 | } else if end - placement != 0 { 674 | print!("\x1b[{}D", end - placement) 675 | } 676 | if input.is_empty() { 677 | slow = false; 678 | clear(&input, &vars, start, end, options, &colors); 679 | } 680 | } 681 | '\x11' => { 682 | //end 683 | placement = input.len(); 684 | end = input.len(); 685 | start = if get_terminal_dimensions().0 - if options.prompt { 3 } else { 1 } 686 | > input.len() 687 | { 688 | 0 689 | } else { 690 | input.len() 691 | - (get_terminal_dimensions().0 - if options.prompt { 3 } else { 1 }) 692 | }; 693 | clearln(&input, &vars, start, end, options, &colors); 694 | } 695 | '\x18' => { 696 | //ctrl+u 697 | cut = input.drain(..placement).collect(); 698 | end -= placement; 699 | placement = 0; 700 | if options.real_time_output && !slow { 701 | execute!(stdout, DisableBlinking)?; 702 | (frac, graphable, long, varcheck) = print_concurrent( 703 | &input, 704 | &last, 705 | &vars, 706 | options, 707 | colors.clone(), 708 | start, 709 | end, 710 | false, 711 | ); 712 | if watch.elapsed().as_millis() > options.slowcheck { 713 | firstslow = true; 714 | slow = true; 715 | } 716 | } else if options.real_time_output && firstslow { 717 | firstslow = false; 718 | handle_err( 719 | "too slow, will print on enter", 720 | &vars, 721 | &input, 722 | options, 723 | &colors, 724 | start, 725 | end, 726 | ) 727 | } else { 728 | clearln(&input, &vars, start, end, options, &colors); 729 | } 730 | if end - placement != 0 { 731 | print!("\x1b[{}D", end - placement) 732 | } 733 | } 734 | '\x19' => { 735 | //ctrl+k 736 | cut = input.drain(placement..).collect(); 737 | end = min(end, input.len()); 738 | if options.real_time_output && !slow { 739 | execute!(stdout, DisableBlinking)?; 740 | (frac, graphable, long, varcheck) = print_concurrent( 741 | &input, 742 | &last, 743 | &vars, 744 | options, 745 | colors.clone(), 746 | start, 747 | end, 748 | false, 749 | ); 750 | if watch.elapsed().as_millis() > options.slowcheck { 751 | firstslow = true; 752 | slow = true; 753 | } 754 | } else if options.real_time_output && firstslow { 755 | firstslow = false; 756 | handle_err( 757 | "too slow, will print on enter", 758 | &vars, 759 | &input, 760 | options, 761 | &colors, 762 | start, 763 | end, 764 | ) 765 | } else { 766 | clearln(&input, &vars, start, end, options, &colors); 767 | } 768 | if end - placement != 0 { 769 | print!("\x1b[{}D", end - placement) 770 | } 771 | } 772 | '\x17' => { 773 | //ctrl+y 774 | let mut cut = cut.clone(); 775 | end += cut.len(); 776 | cut.extend(input.drain(placement..)); 777 | input.extend(cut); 778 | if options.real_time_output && !slow { 779 | execute!(stdout, DisableBlinking)?; 780 | (frac, graphable, long, varcheck) = print_concurrent( 781 | &input, 782 | &last, 783 | &vars, 784 | options, 785 | colors.clone(), 786 | start, 787 | end, 788 | false, 789 | ); 790 | if watch.elapsed().as_millis() > options.slowcheck { 791 | firstslow = true; 792 | slow = true; 793 | } 794 | } else if options.real_time_output && firstslow { 795 | firstslow = false; 796 | handle_err( 797 | "too slow, will print on enter", 798 | &vars, 799 | &input, 800 | options, 801 | &colors, 802 | start, 803 | end, 804 | ) 805 | } else { 806 | clearln(&input, &vars, start, end, options, &colors); 807 | } 808 | if end - placement != 0 { 809 | print!("\x1b[{}D", end - placement) 810 | } 811 | } 812 | '\x16' => { 813 | //ctrl+t 814 | if placement < input.len() && placement != 0 { 815 | input.swap(placement - 1, placement); 816 | if options.real_time_output && !slow { 817 | execute!(stdout, DisableBlinking)?; 818 | (frac, graphable, long, varcheck) = print_concurrent( 819 | &input, 820 | &last, 821 | &vars, 822 | options, 823 | colors.clone(), 824 | start, 825 | end, 826 | false, 827 | ); 828 | if watch.elapsed().as_millis() > options.slowcheck { 829 | firstslow = true; 830 | slow = true; 831 | } 832 | } else if options.real_time_output && firstslow { 833 | firstslow = false; 834 | handle_err( 835 | "too slow, will print on enter", 836 | &vars, 837 | &input, 838 | options, 839 | &colors, 840 | start, 841 | end, 842 | ) 843 | } else { 844 | clearln(&input, &vars, start, end, options, &colors); 845 | } 846 | if end - placement != 0 { 847 | print!("\x1b[{}D", end - placement) 848 | } 849 | } 850 | } 851 | '\x15' => { 852 | //ctrl+l 853 | print!("\x1b[H\x1b[J"); 854 | if options.real_time_output && !slow { 855 | execute!(stdout, DisableBlinking)?; 856 | (frac, graphable, long, varcheck) = print_concurrent( 857 | &input, 858 | &last, 859 | &vars, 860 | options, 861 | colors.clone(), 862 | start, 863 | end, 864 | false, 865 | ); 866 | if watch.elapsed().as_millis() > options.slowcheck { 867 | firstslow = true; 868 | slow = true; 869 | } 870 | } else if options.real_time_output && firstslow { 871 | firstslow = false; 872 | handle_err( 873 | "too slow, will print on enter", 874 | &vars, 875 | &input, 876 | options, 877 | &colors, 878 | start, 879 | end, 880 | ) 881 | } else { 882 | clearln(&input, &vars, start, end, options, &colors); 883 | } 884 | if end - placement != 0 { 885 | print!("\x1b[{}D", end - placement) 886 | } 887 | } 888 | '\x10' => { 889 | //home 890 | placement = 0; 891 | start = 0; 892 | end = if get_terminal_dimensions().0 - if options.prompt { 3 } else { 1 } 893 | > input.len() 894 | { 895 | input.len() 896 | } else { 897 | get_terminal_dimensions().0 - if options.prompt { 3 } else { 1 } 898 | }; 899 | clearln(&input, &vars, start, end, options, &colors); 900 | if end - placement != 0 { 901 | print!("\x1b[{}D", end - placement) 902 | } 903 | } 904 | '\x1D' | '\x05' => { 905 | //up history 906 | i -= if i > 0 { 1 } else { 0 }; 907 | if lines.is_empty() { 908 | continue; 909 | } 910 | input = lines[i].clone().chars().collect::>(); 911 | slow = input.ends_with(&['\t']); 912 | 913 | if slow && options.real_time_output { 914 | input.pop(); 915 | firstslow = false; 916 | placement = input.len(); 917 | end = input.len(); 918 | start = if get_terminal_dimensions().0 919 | - if options.prompt { 3 } else { 1 } 920 | > input.len() 921 | { 922 | 0 923 | } else { 924 | input.len() 925 | - (get_terminal_dimensions().0 926 | - if options.prompt { 3 } else { 1 }) 927 | }; 928 | handle_err( 929 | "too slow, will print on enter", 930 | &vars, 931 | &input, 932 | options, 933 | &colors, 934 | start, 935 | end, 936 | ) 937 | } else { 938 | if slow { 939 | input.pop(); 940 | } 941 | placement = input.len(); 942 | end = input.len(); 943 | start = if get_terminal_dimensions().0 944 | - if options.prompt { 3 } else { 1 } 945 | > input.len() 946 | { 947 | 0 948 | } else { 949 | input.len() 950 | - (get_terminal_dimensions().0 951 | - if options.prompt { 3 } else { 1 }) 952 | }; 953 | } 954 | if options.real_time_output && !slow { 955 | execute!(stdout, DisableBlinking)?; 956 | (frac, graphable, long, varcheck) = print_concurrent( 957 | &input, 958 | &last, 959 | &vars, 960 | options, 961 | colors.clone(), 962 | start, 963 | end, 964 | false, 965 | ); 966 | slow = watch.elapsed().as_millis() > options.slowcheck; 967 | firstslow = slow 968 | } else { 969 | clearln(&input, &vars, start, end, options, &colors); 970 | } 971 | } 972 | '\x1E' | '\x04' => { 973 | //down history 974 | i += 1; 975 | if i >= lines.len() { 976 | i = lines.len(); 977 | input.clone_from(¤t); 978 | } else { 979 | input = lines[i].clone().chars().collect::>(); 980 | } 981 | slow = input.ends_with(&['\t']); 982 | if slow && options.real_time_output { 983 | input.pop(); 984 | firstslow = false; 985 | placement = input.len(); 986 | end = input.len(); 987 | start = if get_terminal_dimensions().0 988 | - if options.prompt { 3 } else { 1 } 989 | > input.len() 990 | { 991 | 0 992 | } else { 993 | input.len() 994 | - (get_terminal_dimensions().0 995 | - if options.prompt { 3 } else { 1 }) 996 | }; 997 | handle_err( 998 | "too slow, will print on enter", 999 | &vars, 1000 | &input, 1001 | options, 1002 | &colors, 1003 | start, 1004 | end, 1005 | ) 1006 | } else { 1007 | if slow { 1008 | input.pop(); 1009 | } 1010 | placement = input.len(); 1011 | end = input.len(); 1012 | start = if get_terminal_dimensions().0 1013 | - if options.prompt { 3 } else { 1 } 1014 | > input.len() 1015 | { 1016 | 0 1017 | } else { 1018 | input.len() 1019 | - (get_terminal_dimensions().0 1020 | - if options.prompt { 3 } else { 1 }) 1021 | }; 1022 | } 1023 | if options.real_time_output && !slow { 1024 | execute!(stdout, DisableBlinking)?; 1025 | (frac, graphable, long, varcheck) = print_concurrent( 1026 | &input, 1027 | &last, 1028 | &vars, 1029 | options, 1030 | colors.clone(), 1031 | start, 1032 | end, 1033 | false, 1034 | ); 1035 | slow = watch.elapsed().as_millis() > options.slowcheck; 1036 | firstslow = slow; 1037 | } else { 1038 | clearln(&input, &vars, start, end, options, &colors); 1039 | } 1040 | } 1041 | '\x1B' => { 1042 | //left 1043 | if placement - start == 0 && placement != 0 && start != 0 { 1044 | start -= 1; 1045 | placement -= 1; 1046 | end = start + get_terminal_dimensions().0 1047 | - if options.prompt { 3 } else { 1 }; 1048 | end = min(end, input.len()); 1049 | clearln(&input, &vars, start, end, options, &colors); 1050 | print!("\x1b[{}D", end - placement) 1051 | } else if placement != 0 { 1052 | placement -= 1; 1053 | print!("\x08"); 1054 | } 1055 | } 1056 | '\x1C' => { 1057 | //right 1058 | end = start + get_terminal_dimensions().0 1059 | - if options.prompt { 3 } else { 1 }; 1060 | end = min(end, input.len()); 1061 | if placement == end && end != input.len() { 1062 | start += 1; 1063 | placement += 1; 1064 | end += 1; 1065 | clearln(&input, &vars, start, end, options, &colors) 1066 | } else if placement != input.len() { 1067 | placement += 1; 1068 | print!("\x1b[C") 1069 | } 1070 | } 1071 | '\x12' => { 1072 | //ctrl+left 1073 | if placement != 0 { 1074 | let s = placement; 1075 | let mut hit = false; 1076 | for (i, j) in input[..s].iter().enumerate().rev() { 1077 | if !j.is_alphanumeric() { 1078 | if hit { 1079 | hit = false; 1080 | placement = i + 1; 1081 | break; 1082 | } 1083 | } else { 1084 | hit = true; 1085 | } 1086 | } 1087 | if hit { 1088 | placement = 0; 1089 | } 1090 | if placement <= start { 1091 | end = placement 1092 | + (get_terminal_dimensions().0 1093 | - if options.prompt { 3 } else { 1 }); 1094 | end = min(end, input.len()); 1095 | start = placement; 1096 | clearln(&input, &vars, start, end, options, &colors); 1097 | if end - placement != 0 { 1098 | print!("\x1b[{}D", end - placement) 1099 | } 1100 | } else if placement == s { 1101 | placement = 0; 1102 | print!("\x1b[{s}D"); 1103 | } else { 1104 | print!("\x1b[{}D", s - placement); 1105 | } 1106 | } 1107 | } 1108 | '\x13' => { 1109 | //ctrl+right 1110 | if placement != input.len() { 1111 | let s = placement; 1112 | let mut hit = false; 1113 | for (i, j) in input[s + 1..].iter().enumerate() { 1114 | if !j.is_alphanumeric() { 1115 | if hit { 1116 | hit = false; 1117 | placement += i + 1; 1118 | break; 1119 | } 1120 | } else { 1121 | hit = true; 1122 | } 1123 | } 1124 | if hit { 1125 | placement = input.len(); 1126 | } 1127 | if placement >= end { 1128 | start = placement.saturating_sub( 1129 | get_terminal_dimensions().0 1130 | - if options.prompt { 3 } else { 1 }, 1131 | ); 1132 | end = placement; 1133 | clearln(&input, &vars, start, end, options, &colors) 1134 | } else if placement == s { 1135 | placement = input.len(); 1136 | print!("\x1b[{}C", input.len() - s); 1137 | } else { 1138 | print!("\x1b[{}C", placement - s); 1139 | } 1140 | } 1141 | } 1142 | '\x1F' => { 1143 | //tab completion 1144 | let mut word = String::new(); 1145 | let mut wait = false; 1146 | let mut count = 0; 1147 | let mut start_pos = placement; 1148 | for (i, c) in input[..placement].iter().rev().enumerate() { 1149 | if !wait { 1150 | if c.is_alphabetic() 1151 | || matches!(*c, '°' | '\'' | '`' | '_' | '∫' | '$' | '¢') 1152 | { 1153 | word.insert(0, *c) 1154 | } else if i == 0 { 1155 | wait = true 1156 | } else { 1157 | break; 1158 | } 1159 | } 1160 | if wait { 1161 | if c == &'(' || c == &'{' { 1162 | count -= 1; 1163 | } else if c == &')' || c == &'}' { 1164 | count += 1; 1165 | } 1166 | if count == -1 { 1167 | wait = false; 1168 | start_pos -= i; 1169 | } 1170 | } 1171 | } 1172 | if !word.is_empty() { 1173 | let bank = get_word_bank(&word, &vars, options); 1174 | let mut var = false; 1175 | if bank.len() == 1 { 1176 | let mut w = bank[0].to_string(); 1177 | if w.contains('(') { 1178 | w = w.split('(').next().unwrap().to_string(); 1179 | if (placement == input.len() || input[placement] != '(') 1180 | && input[placement - 1] != '(' 1181 | && start_pos == placement 1182 | { 1183 | w.push('(') 1184 | } 1185 | } else { 1186 | var = true 1187 | } 1188 | let w = w.chars().collect::>(); 1189 | input.splice( 1190 | placement..placement, 1191 | w[word.chars().count()..].iter().collect::().chars(), 1192 | ); 1193 | placement += w.len() - word.chars().count(); 1194 | end = start + get_terminal_dimensions().0 1195 | - if options.prompt { 3 } else { 1 } 1196 | + 1; 1197 | if end > input.len() { 1198 | end = input.len() 1199 | } else if placement == end { 1200 | start += 1; 1201 | } else { 1202 | end -= 1; 1203 | } 1204 | if i == lines.len() { 1205 | current.clone_from(&input); 1206 | } else { 1207 | lines[i] = input.clone().iter().collect::(); 1208 | } 1209 | if options.real_time_output && !slow && var { 1210 | execute!(stdout, DisableBlinking)?; 1211 | (frac, graphable, long, varcheck) = print_concurrent( 1212 | &input, 1213 | &last, 1214 | &vars, 1215 | options, 1216 | colors.clone(), 1217 | start, 1218 | end, 1219 | false, 1220 | ); 1221 | if watch.elapsed().as_millis() > options.slowcheck { 1222 | firstslow = true; 1223 | slow = true; 1224 | } 1225 | } else if options.real_time_output && firstslow && var { 1226 | firstslow = false; 1227 | handle_err( 1228 | "too slow, will print on enter", 1229 | &vars, 1230 | &input, 1231 | options, 1232 | &colors, 1233 | start, 1234 | end, 1235 | ) 1236 | } else { 1237 | clear(&input, &vars, start, end, options, &colors); 1238 | } 1239 | if end - placement != 0 { 1240 | print!("\x1b[{}D", end - placement) 1241 | } 1242 | } else if !bank.is_empty() { 1243 | let mut k = 0; 1244 | let mut char = '\0'; 1245 | 'upper: for n in 1246 | 0..bank.iter().fold(usize::MAX, |min, str| min.min(str.len())) 1247 | { 1248 | for b in &bank { 1249 | let c = b.chars().nth(n).unwrap(); 1250 | if char == '\0' { 1251 | char = c 1252 | } else if c != char { 1253 | break 'upper; 1254 | } 1255 | } 1256 | k += 1; 1257 | char = '\0' 1258 | } 1259 | input.splice( 1260 | placement..placement, 1261 | bank[0][word.chars().count()..k].chars(), 1262 | ); 1263 | placement += k - word.chars().count(); 1264 | end = start + get_terminal_dimensions().0 1265 | - if options.prompt { 3 } else { 1 } 1266 | + 1; 1267 | if end > input.len() { 1268 | end = input.len() 1269 | } else if placement == end { 1270 | start += 1; 1271 | } else { 1272 | end -= 1; 1273 | } 1274 | if i == lines.len() { 1275 | current.clone_from(&input); 1276 | } else { 1277 | lines[i] = input.clone().iter().collect::(); 1278 | } 1279 | clear(&input, &vars, start, end, options, &colors); 1280 | if end - placement != 0 { 1281 | print!("\x1b[{}D", end - placement) 1282 | } 1283 | } 1284 | if !var && !bank.is_empty() { 1285 | let width = get_terminal_dimensions().0; 1286 | let mut n = 1; 1287 | let tab = bank.iter().fold(0, |max, str| max.max(str.len())) + 3; 1288 | let mut len = 0; 1289 | print!("\x1b[G\n\x1b[K"); 1290 | for b in bank { 1291 | if len + tab > width { 1292 | len = 0; 1293 | n += 1; 1294 | print!("\x1b[G\n\x1b[K") 1295 | } 1296 | len += tab; 1297 | print!( 1298 | "{}{}", 1299 | to_output( 1300 | &b.chars().collect::>(), 1301 | &vars, 1302 | options.color.as_bool(), 1303 | &colors 1304 | ), 1305 | " ".repeat(tab - b.chars().count()) 1306 | ) 1307 | } 1308 | print!( 1309 | "\x1b[G\x1b[{}A\x1b[{}C", 1310 | n, 1311 | placement + if options.prompt { 2 } else { 0 } 1312 | ); 1313 | long = true 1314 | } 1315 | } 1316 | } 1317 | '\x0E' => { 1318 | //ctrl+xx 1319 | if xxbool { 1320 | (placement, xxpos) = (xxpos, placement); 1321 | match placement.cmp(&xxpos) { 1322 | Ordering::Greater => { 1323 | placement = min(placement, input.len()); 1324 | if placement >= end { 1325 | start = placement.saturating_sub( 1326 | get_terminal_dimensions().0 1327 | - if options.prompt { 3 } else { 1 }, 1328 | ); 1329 | end = placement; 1330 | clearln(&input, &vars, start, end, options, &colors) 1331 | } else if placement == xxpos { 1332 | placement = input.len(); 1333 | print!("\x1b[{}C", input.len() - xxpos); 1334 | } else { 1335 | print!("\x1b[{}C", placement - xxpos); 1336 | } 1337 | } 1338 | Ordering::Less => { 1339 | if placement <= start { 1340 | end = placement 1341 | + (get_terminal_dimensions().0 1342 | - if options.prompt { 3 } else { 1 }); 1343 | end = min(end, input.len()); 1344 | start = placement; 1345 | clearln(&input, &vars, start, end, options, &colors); 1346 | if end - placement != 0 { 1347 | print!("\x1b[{}D", end - placement) 1348 | } 1349 | } else if placement == xxpos { 1350 | placement = 0; 1351 | print!("\x1b[{xxpos}D"); 1352 | } else { 1353 | print!("\x1b[{}D", xxpos - placement); 1354 | } 1355 | } 1356 | _ => (), 1357 | } 1358 | xxbool = false 1359 | } else { 1360 | xxbool = true; 1361 | continue; 1362 | } 1363 | if xxstart { 1364 | xxpos = 0; 1365 | } 1366 | xxstart = !xxstart; 1367 | } 1368 | '\x0D' => { 1369 | //ctrl+w 1370 | if placement != 0 && end_word(input[placement - 1]) { 1371 | placement -= 1; 1372 | cut = vec![input.remove(placement)]; 1373 | } else { 1374 | for (i, c) in input[..placement].iter().rev().enumerate() { 1375 | if c.is_whitespace() || i + 1 == placement { 1376 | cut = input 1377 | .drain(placement - i - 1..placement) 1378 | .collect::>(); 1379 | placement -= i + 1; 1380 | break; 1381 | } 1382 | if end_word(*c) { 1383 | cut = input 1384 | .drain(placement - i..placement) 1385 | .collect::>(); 1386 | placement -= i; 1387 | break; 1388 | } 1389 | } 1390 | } 1391 | end = min(end, input.len()); 1392 | start = min(start, end); 1393 | if i == lines.len() { 1394 | current.clone_from(&input); 1395 | } else { 1396 | lines[i] = input.clone().iter().collect::(); 1397 | } 1398 | if options.real_time_output && !slow { 1399 | execute!(stdout, DisableBlinking)?; 1400 | (frac, graphable, long, varcheck) = print_concurrent( 1401 | &input, 1402 | &last, 1403 | &vars, 1404 | options, 1405 | colors.clone(), 1406 | start, 1407 | end, 1408 | false, 1409 | ); 1410 | if watch.elapsed().as_millis() > options.slowcheck { 1411 | firstslow = true; 1412 | slow = true; 1413 | } 1414 | } else if options.real_time_output && firstslow { 1415 | firstslow = false; 1416 | handle_err( 1417 | "too slow, will print on enter", 1418 | &vars, 1419 | &input, 1420 | options, 1421 | &colors, 1422 | start, 1423 | end, 1424 | ) 1425 | } else { 1426 | clearln(&input, &vars, start, end, options, &colors); 1427 | } 1428 | if options.debug { 1429 | let time = watch.elapsed().as_nanos(); 1430 | print!( 1431 | " {}\x1b[{}D", 1432 | time, 1433 | time.to_string().len() + 1 + end - placement 1434 | ); 1435 | } else if end - placement != 0 { 1436 | print!("\x1b[{}D", end - placement) 1437 | } 1438 | if input.is_empty() { 1439 | slow = false; 1440 | clear(&input, &vars, start, end, options, &colors); 1441 | } 1442 | } 1443 | '\x0C' => { 1444 | //alt+d 1445 | if placement < input.len() && end_word(input[placement]) { 1446 | cut = vec![input.remove(placement)]; 1447 | } else { 1448 | let mut pos = 0; 1449 | for (i, c) in input[placement..].iter().enumerate() { 1450 | if c.is_whitespace() || placement + i + 1 == input.len() { 1451 | pos = i + 1; 1452 | } 1453 | if end_word(*c) { 1454 | pos = i; 1455 | break; 1456 | } 1457 | } 1458 | cut = input.drain(placement..placement + pos).collect(); 1459 | } 1460 | end = min(end, input.len()); 1461 | if options.real_time_output && !slow { 1462 | execute!(stdout, DisableBlinking)?; 1463 | (frac, graphable, long, varcheck) = print_concurrent( 1464 | &input, 1465 | &last, 1466 | &vars, 1467 | options, 1468 | colors.clone(), 1469 | start, 1470 | end, 1471 | false, 1472 | ); 1473 | if watch.elapsed().as_millis() > options.slowcheck { 1474 | firstslow = true; 1475 | slow = true; 1476 | } 1477 | } else if options.real_time_output && firstslow { 1478 | firstslow = false; 1479 | handle_err( 1480 | "too slow, will print on enter", 1481 | &vars, 1482 | &input, 1483 | options, 1484 | &colors, 1485 | start, 1486 | end, 1487 | ) 1488 | } else { 1489 | clearln(&input, &vars, start, end, options, &colors); 1490 | } 1491 | if end - placement != 0 { 1492 | print!("\x1b[{}D", end - placement) 1493 | } 1494 | } 1495 | '\x0F' => { 1496 | //alt+t 1497 | let first; 1498 | if placement < input.len() && end_word(input[placement]) { 1499 | first = vec![input.remove(placement)]; 1500 | } else { 1501 | let mut pos = 0; 1502 | for (i, c) in input[placement..].iter().enumerate() { 1503 | if c.is_whitespace() || placement + i + 1 == input.len() { 1504 | pos = i + 1; 1505 | } 1506 | if end_word(*c) { 1507 | pos = i; 1508 | break; 1509 | } 1510 | } 1511 | first = input.drain(placement..placement + pos).collect(); 1512 | } 1513 | let second; 1514 | if placement != 0 && end_word(input[placement - 1]) { 1515 | second = vec![input.remove(placement)]; 1516 | } else { 1517 | let mut pos = 0; 1518 | for (i, c) in input[..placement].iter().rev().enumerate() { 1519 | if end_word(*c) { 1520 | pos = i; 1521 | break; 1522 | } 1523 | if c.is_whitespace() || i + 1 == placement { 1524 | pos = i + 1; 1525 | break; 1526 | } 1527 | } 1528 | second = input 1529 | .drain(placement - pos..placement) 1530 | .collect::>(); 1531 | } 1532 | placement -= second.len(); 1533 | input.splice(placement..placement, first.clone()); 1534 | placement += first.len(); 1535 | if placement > input.len() { 1536 | placement = input.len() - 1 1537 | } 1538 | input.splice(placement..placement, second.clone()); 1539 | if options.real_time_output && !slow { 1540 | execute!(stdout, DisableBlinking)?; 1541 | (frac, graphable, long, varcheck) = print_concurrent( 1542 | &input, 1543 | &last, 1544 | &vars, 1545 | options, 1546 | colors.clone(), 1547 | start, 1548 | end, 1549 | false, 1550 | ); 1551 | if watch.elapsed().as_millis() > options.slowcheck { 1552 | firstslow = true; 1553 | slow = true; 1554 | } 1555 | } else if options.real_time_output && firstslow { 1556 | firstslow = false; 1557 | handle_err( 1558 | "too slow, will print on enter", 1559 | &vars, 1560 | &input, 1561 | options, 1562 | &colors, 1563 | start, 1564 | end, 1565 | ) 1566 | } else { 1567 | clearln(&input, &vars, start, end, options, &colors); 1568 | } 1569 | if end - placement != 0 { 1570 | print!("\x1b[{}D", end - placement) 1571 | } 1572 | } 1573 | '\0' => (), 1574 | _ => { 1575 | input.insert(placement, c); 1576 | placement += 1; 1577 | end = start + get_terminal_dimensions().0 1578 | - if options.prompt { 3 } else { 1 } 1579 | + 1; 1580 | if end > input.len() { 1581 | end = input.len() 1582 | } else if placement == end { 1583 | start += 1; 1584 | } else { 1585 | end -= 1; 1586 | } 1587 | if i == lines.len() { 1588 | current.clone_from(&input); 1589 | } else { 1590 | lines[i] = input.clone().iter().collect::(); 1591 | } 1592 | if options.real_time_output && !slow { 1593 | execute!(stdout, DisableBlinking)?; 1594 | (frac, graphable, long, varcheck) = print_concurrent( 1595 | &input, 1596 | &last, 1597 | &vars, 1598 | options, 1599 | colors.clone(), 1600 | start, 1601 | end, 1602 | false, 1603 | ); 1604 | if watch.elapsed().as_millis() > options.slowcheck { 1605 | firstslow = true; 1606 | slow = true; 1607 | } 1608 | } else if options.real_time_output && firstslow { 1609 | firstslow = false; 1610 | handle_err( 1611 | "too slow, will print on enter", 1612 | &vars, 1613 | &input, 1614 | options, 1615 | &colors, 1616 | start, 1617 | end, 1618 | ) 1619 | } else { 1620 | clearln(&input, &vars, start, end, options, &colors); 1621 | } 1622 | if options.debug { 1623 | let time = watch.elapsed().as_nanos(); 1624 | print!( 1625 | " {}\x1b[{}D", 1626 | time, 1627 | time.to_string().len() + 1 + end - placement 1628 | ); 1629 | } else if end - placement != 0 { 1630 | print!("\x1b[{}D", end - placement) 1631 | } 1632 | } 1633 | } 1634 | stdout.flush()?; 1635 | } 1636 | commands(&mut options, &lines, &input, &mut stdout); 1637 | if !varcheck { 1638 | print!("{}", prompt(options, &colors)); 1639 | if options.color.as_bool() { 1640 | print!("\x1b[0m"); 1641 | } 1642 | } 1643 | stdout.flush()?; 1644 | execute!(stdout, EnableBlinking)?; 1645 | if input.is_empty() { 1646 | continue; 1647 | } 1648 | write( 1649 | insert_last(&input, last.iter().collect::().as_str()), 1650 | file.as_mut().unwrap(), 1651 | unmod_lines.as_mut().unwrap(), 1652 | slow, 1653 | last.iter().collect::(), 1654 | ); 1655 | } 1656 | if varcheck { 1657 | if let Err(s) = set_commands_or_vars(&mut colors, &mut options, &mut vars, &input) { 1658 | if !s.is_empty() { 1659 | print!( 1660 | "\x1b[G\x1b[A\x1b[K{}\x1b[G\n{}", 1661 | s, 1662 | prompt(options, &colors) 1663 | ); 1664 | } else { 1665 | print!( 1666 | "{}{}", 1667 | prompt(options, &colors), 1668 | if options.color.as_bool() { 1669 | "\x1b[0m" 1670 | } else { 1671 | "" 1672 | } 1673 | ); 1674 | } 1675 | } else { 1676 | print!( 1677 | "{}{}", 1678 | prompt(options, &colors), 1679 | if options.color.as_bool() { 1680 | "\x1b[0m" 1681 | } else { 1682 | "" 1683 | } 1684 | ); 1685 | } 1686 | stdout.flush()? 1687 | } else if graphable.graph { 1688 | #[cfg(feature = "kalc-plot")] 1689 | if !options.gnuplot { 1690 | if let Some(path) = find_it("kalc-plot") { 1691 | #[cfg(feature = "serde")] 1692 | let data = Data { 1693 | vars: vars.clone(), 1694 | options, 1695 | colors: colors.clone(), 1696 | }; 1697 | #[allow(clippy::zombie_processes)] 1698 | #[allow(unused_unsafe)] 1699 | handles.push(thread::spawn(move || unsafe { 1700 | let mut plot = kalc_lib::misc::spawn_cmd(path) 1701 | .arg("-d") 1702 | .arg(input.iter().collect::()) 1703 | .stdin(Stdio::piped()) 1704 | .spawn() 1705 | .unwrap(); 1706 | #[cfg(feature = "serde")] 1707 | { 1708 | let stdin = plot.stdin.as_mut().unwrap(); 1709 | let data = bitcode::serialize(&data).unwrap(); 1710 | stdin.write_all(&data.len().to_be_bytes()).unwrap(); 1711 | stdin.write_all(&data).unwrap(); 1712 | } 1713 | #[cfg(not(unix))] 1714 | plot.wait().unwrap(); 1715 | })); 1716 | continue; 1717 | } 1718 | } 1719 | #[cfg(feature = "gnuplot")] 1720 | { 1721 | let inputs: Vec = insert_last(&input, &last.iter().collect::()) 1722 | .split('#') 1723 | .map(str::to_owned) 1724 | .collect(); 1725 | let watch = options.debug.then_some(Instant::now()); 1726 | if options.graph_cli { 1727 | if options.interactive { 1728 | terminal::disable_raw_mode()?; 1729 | graph(inputs, vars.clone(), options, watch, colors.clone(), true) 1730 | .join() 1731 | .unwrap(); 1732 | terminal::enable_raw_mode()?; 1733 | } else { 1734 | graph(inputs, vars.clone(), options, watch, colors.clone(), true) 1735 | .join() 1736 | .unwrap(); 1737 | } 1738 | } else { 1739 | handles.push(graph( 1740 | inputs, 1741 | vars.clone(), 1742 | options, 1743 | watch, 1744 | colors.clone(), 1745 | false, 1746 | )); 1747 | } 1748 | } 1749 | } 1750 | } 1751 | Ok(()) 1752 | } 1753 | #[cfg(feature = "kalc-plot")] 1754 | fn find_it

(exe_name: P) -> Option 1755 | where 1756 | P: AsRef, 1757 | { 1758 | env::var_os("PATH").and_then(|paths| { 1759 | env::split_paths(&paths) 1760 | .filter_map(|dir| { 1761 | let full_path = dir.join(&exe_name); 1762 | full_path.is_file().then_some(full_path) 1763 | }) 1764 | .next() 1765 | }) 1766 | } 1767 | 1768 | fn setup_for_interactive( 1769 | colors: &Colors, 1770 | options: &mut Options, 1771 | stdout: &mut Stdout, 1772 | ) -> Result<(), Error> { 1773 | options.interactive = true; 1774 | terminal::enable_raw_mode()?; 1775 | print!( 1776 | "\x1b[G\x1b[K{}{}", 1777 | prompt(*options, colors), 1778 | if options.color.as_bool() { 1779 | &colors.text 1780 | } else { 1781 | "" 1782 | } 1783 | ); 1784 | stdout.flush()?; 1785 | Ok(()) 1786 | } 1787 | --------------------------------------------------------------------------------