Skip to content

marconae/crabculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

41 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

crabculator Logo

CrabCulator

Rust CI codecov License: MIT

A terminal-based calculator with a text-editor experience

Features β€’ Installation β€’ Usage β€’ Syntax β€’ License


Overview

Crabculator is a terminal-based calculator application that provides a text-editor-like experience for writing and evaluating math expressions. Write multiple lines of calculations, define variables, and see results update live as you type.

Features

  • TUI β€” terminal-based user interface
  • Real-time evaluation β€” Results update instantly as you type
  • Variable support β€” Define variables (e.g., a = 5 + 3)
  • Math functions β€” Built-in functions like sqrt, sin, cos, tan, log, ln, abs, floor, ceil
  • Constants β€” Access pi and e directly in expressions
  • Inline error display β€” Red underlined tokens with clear error explanations
  • Full editor navigation β€” Cursor movement and editing anywhere in the document
  • Session persistence β€” Variables persist across sessions

Installation

From source

Requires Rust 2024 edition.

git clone https://github.com/marconae/crabculator.git
cd crabculator
cargo install --path .

The binary will be available at target/release/crabculator.

Usage

Launch the application:

crabculator

Keyboard shortcuts

Key Action
Arrow keys Move cursor
Home / End Jump to line start/end
Ctrl+H Toggle help overlay
Ctrl+R Clear buffer
Ctrl+C / Ctrl+Q Exit

Expression Syntax

Basic arithmetic

5 + 3          β†’ 8
10 - 4         β†’ 6
6 * 7          β†’ 42
15 / 3         β†’ 5
17 % 5         β†’ 2
(5 + 3) * 2    β†’ 16

Variables

a = 5 + 3      β†’ 8
b = a * 2      β†’ 16
total = a + b  β†’ 24

Variables persist across sessions and are stored in ~/.crabculator/state.json.

Built-in functions

Category Function Description
Basic sqrt(x) Square root
cbrt(x) Cube root
abs(x) Absolute value
pow(base, exp) Power
Trig sin(x), cos(x), tan(x) Trigonometric (radians)
asin(x), acos(x), atan(x) Inverse trigonometric
atan2(y, x) Two-argument arctangent
Hyperbolic sinh(x), cosh(x), tanh(x) Hyperbolic functions
asinh(x), acosh(x), atanh(x) Inverse hyperbolic
Log/Exp ln(x) Natural logarithm
log(x), log10(x) Base-10 logarithm
log2(x) Base-2 logarithm
exp(x) Exponential (e^x)
exp2(x) Power of 2 (2^x)
Rounding floor(x), ceil(x) Round down/up
round(x) Round to nearest
Utility min(a, b), max(a, b) Minimum/maximum
hypot(a, b) Hypotenuse (sqrt(aΒ² + bΒ²))

Constants

Constant Value
pi 3.14159...
e 2.71828...

Example session

radius = 5
area = pi * radius^2    β†’ 78.5398...
circumference = 2 * pi * radius    β†’ 31.4159...

a = 3
b = 4
hypotenuse = sqrt(a^2 + b^2)    β†’ 5

License

Free and open-source under MIT.


Build with πŸ¦€ Rust and made with ❀️ by marconae – blogging on deliberate.codes.

About

Tiny calculator TUI written in Rust πŸ¦€

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages