A sleek, interactive CLI calculator crafted with Python.
Cyberpunk Dark / Cyan / Emerald TUI • Modular Python Architecture • Zero-Division Guard • Session History
- 🎨 Cyberpunk Rich TUI — Built with
richfeaturing rounded neon borders, high-contrast Dark / Cyan / Emerald styling, and structured terminal tables. - 🛡️ Zero-Division & Input Guards — Explicit
DivisionByZeroErrorprotection for division (/) and modulo (%) operations alongside resilient numeric validation. - 🧠 Session Memory &
ansChaining — Automatically records timestamped calculations in an interactive history table and lets you chain results using theanskeyword. - 🧩 Clean Modular Architecture — Strict separation of concerns across
core.py(pure math),history.py(state & audit trail),ui.py(Rich presentation), andmain.py(CLI controller). - 🧪 Test-Driven Reliability — Verified by a comprehensive
pytestunit test suite covering arithmetic operations, edge cases, UI rendering, and interactive session flows.
Run the entire installation and launch calc-cli with a single command:
git clone https://github.com/4jeeh/calc-cli.git && cd calc-cli && pip install -e . && calc-cliWant to preview the full TUI showcase non-interactively?
python -m calc_cli.main --demo| Key | Shortcut | Operation | Description |
|---|---|---|---|
[1] |
+ / add
|
Addition | Compute |
[2] |
- / sub
|
Subtraction | Compute |
[3] |
* / mul
|
Multiplication | Compute |
[4] |
/ / div
|
Division | Compute |
[5] |
^ / pow
|
Exponentiation | Compute |
[6] |
% / mod
|
Modulo | Compute |
[H] |
hist |
Session History | Render the timestamped session calculation table |
[C] |
clear |
Clear History | Reset session history and clear the ans register |
[M] |
menu / ?
|
Show Menu | Re-display the navigation and shortcut table |
[Q] |
exit / quit
|
Quit Application | Exit calc-cli cleanly |
Pro Tip: Type
answhen prompted for the first or second number to automatically inject the previous calculation's result.
calc-cli/
├── src/
│ └── calc_cli/
│ ├── __init__.py # Package metadata & version
│ ├── core.py # Pure mathematical functions & DivisionByZeroError guard
│ ├── history.py # Immutable CalculationRecord & session history manager
│ ├── ui.py # Rich TUI panels, tables, and Dark/Cyan/Emerald theme
│ └── main.py # Interactive CLI loop & --demo showcase runner
├── tests/
│ ├── test_core.py # Unit tests for arithmetic & edge cases
│ ├── test_history.py # Unit tests for session history tracking
│ ├── test_main.py # Unit tests for CLI dispatcher & interactive loop
│ └── test_ui.py # Unit tests for Rich TUI component rendering
├── .gitignore # Standard Python gitignore
├── LICENSE # MIT License
├── pyproject.toml # Modern PEP 621 packaging & pytest/black config
├── requirements.txt # Runtime & test dependencies
└── README.md # Showcase documentation
Execute the pytest suite from the repository root:
pytestEvery developer's journey starts with a humble script. calc-cli began life as kalkulator.py—a 45-line introductory Computer Science (CS101) homework assignment written in a single procedural while True loop with basic print() and input() statements.
Rather than letting that early milestone gather dust, this repository reimagines what happens when foundational code is refactored with modern software engineering discipline:
- Decoupled Architecture: The monolithic script was decomposed into pure mathematical primitives (
core.py), stateful session tracking (history.py), declarative terminal rendering (ui.py), and an entrypoint controller (main.py). - Human-Centered Terminal UX: Plain stdout lines were replaced with a cyber-styled
richTUI featuring rounded panels, semantic color coding, operator shortcuts, andansresult chaining. - Engineering Rigor: String-based error returns were upgraded to typed exceptions (
DivisionByZeroError), backed by automatedpytestverification and PEP 621 packaging.
What started as a classroom exercise in basic control flow is now a clean, extensible, open-source command-line utility.
Distributed under the MIT License. See LICENSE for full details.