A fast terminal calculator written in Rust. rustic-calc provides a keyboard-driven TUI for evaluating expressions, storing variables, reviewing history, and plotting expressions with one unknown variable.
- Interactive TUI built with
ratatui - Three panes for input, history, and variables
- Vim-style input editor with
Insert,Normal, andVisualmodes - Expression evaluation with operator precedence for:
+,-,*,/,^
- Parentheses support for grouped expressions (including nested groups)
- Unary minus support for negative values
- Variables via assignment syntax (
x=2+3) and reuse in later expressions - Implicit multiplication support (
7xbecomes7*x,2(a+b)becomes2*(a+b)) - History recall and selection from the history pane
- Automatic scatter plotting for expressions with exactly one unknown variable (sampled from
-10to10) - Inline error reporting for parse/evaluation issues
- Rust (2024 edition)
Clone the repository and build the project using Cargo:
git clone https://github.com/marc-niclas/rustic-calc.git
cd rustic-calc
cargo install --path .Run the calculator:
rcalc run3*4-1
b=2
a=b+5
7x+a # plots y = 7x + a for x in [-10, 10]
2(a+b) # implicit multiplication with parentheses
| Key | Action |
|---|---|
Ctrl+C |
Quit application |
| Key | Action |
|---|---|
Enter |
Submit expression |
Esc |
Switch from Insert to Normal mode |
Up Arrow |
Recall last expression (Insert mode) |
Backspace |
Delete previous character (Insert mode) |
Left / Right |
Move cursor (Insert mode) |
| Key | Action |
|---|---|
i / a / I / A |
Enter Insert mode (Vim-style) |
h / l or Left / Right |
Move cursor |
w / b |
Word motions |
0 / $ |
Line start / line end |
x |
Delete character under cursor |
v |
Enter Visual mode |
p / P |
Paste yanked text after / before cursor |
Tab / Shift+Tab |
Cycle focus: Input -> History -> Variables |
| Key | Action |
|---|---|
Up / Down |
Move selection |
Enter |
Load selected item into input |
i |
Return to input Insert mode |
Tab / Shift+Tab |
Cycle focus |
Left / Right |
Jump focus between History and Variables |
The project includes unit and integration tests for calculation, tokenization, variables, editor behavior, and TUI interactions.
cargo testThis project uses pre-commit to ensure code quality.
- Install pre-commit hooks:
prek install prek install -t commit-msg
- The CI pipeline runs
clippyandrustfmton every push.
src/main.rs: Application entrypointsrc/tui_app.rs: TUI state, key handling, and rendering orchestrationsrc/input_editor.rs: Vim-style line editor logicsrc/calculate.rs: Expression evaluationsrc/tokenize.rs: Tokenization and implicit multiplicationsrc/variables.rs: Variable assignment parsingsrc/widgets/: TUI pane widgets (help, input, history, variables, plot)tests/: Integration tests for calculator and TUI behavior
Distributed under the MIT License. See LICENSE for more information.
Built with Rust and Ratatui.
