Skip to content

tui-apps/calc

Repository files navigation

live calc

A terminal calculator that answers as you type. There's no equals key; the result updates on every keystroke.

The live calc TUI showing "2 + 3 * sqrt(16) - pi = 10.85840735"

Run it

go run .

Start typing. ctrl+u clears the line, esc or ctrl+c quits. For a standalone binary, go build -o calc . instead.

What it handles

Arithmetic with the expected precedence (+ - * / % ^), parentheses, negatives, and scientific notation like 1e3. Powers are right-associative, so 2 ^ 3 ^ 2 is 512.

Functions: sqrt cbrt abs floor ceil round sin cos tan asin acos atan exp ln log log2. Constants: pi, e, tau.

(2 + 3) * 4          20
sqrt(16) + abs(-4)   8
2 * pi               6.283185307

Bad input (unmatched parens, divide by zero) shows an error in place and keeps going.

Layout

main.go is the Bubble Tea UI. eval.go is a standalone expression evaluator that uses only the standard library. eval_test.go tests it (go test ./...). See architecture.md for how the pieces fit.

The screenshot

It's a real frame, captured with freeze. The --frame flag renders one screen and exits so a run-and-exit tool can grab an otherwise interactive TUI:

go build -o calc .
freeze --execute "./calc --frame '2 + 3 * sqrt(16) - pi'" --window --padding 20 -o images/calc.png

Citation

If you use this project, please cite it. A machine-readable CITATION.cff is included; expand below for a BibTeX entry.

BibTeX
@software{Vulpes_calc_2026,
  author  = {Vulpes, Aesthetic},
  title   = {calc},
  year    = {2026},
  month   = jul,
  version = {0.1.0},
  url     = {https://github.com/tui-apps/calc}
}

Related

Part of the tui-apps collection

Six small, single-purpose terminal apps.

App What it does
calc live calculator (this repo)
algebra-visual function grapher
classical-ciphers cipher encoder and decoder
crypto-charts crypto price charts
totp TOTP authenticator
life Conway's Game of Life

Packages

 
 
 

Contributors

Languages