https://github.com/sunil-kumarr/lastcode
A sleek, terminal-based interactive visualizer for tree, graph, grid, and array algorithms.
https://github.com/sunil-kumarr/lastcode
arrays dsa-algorithm dsa-learning-series dsa-practice graph-algorithms interview-preparation interview-questions leetcode neetcode python queue stack string terminal terminal-ui
Last synced: 5 days ago
JSON representation
A sleek, terminal-based interactive visualizer for tree, graph, grid, and array algorithms.
- Host: GitHub
- URL: https://github.com/sunil-kumarr/lastcode
- Owner: sunil-kumarr
- License: mit
- Created: 2026-05-24T05:32:49.000Z (20 days ago)
- Default Branch: main
- Last Pushed: 2026-05-24T09:49:51.000Z (20 days ago)
- Last Synced: 2026-05-24T11:26:48.258Z (20 days ago)
- Topics: arrays, dsa-algorithm, dsa-learning-series, dsa-practice, graph-algorithms, interview-preparation, interview-questions, leetcode, neetcode, python, queue, stack, string, terminal, terminal-ui
- Language: Python
- Homepage:
- Size: 354 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# đ lastcode
> A sleek, terminal-based interactive visualizer for tree, graph, grid, and array algorithms. Built with Python and the [Textual](https://github.com/Textualize/textual) framework.
`lastcode` allows you to trace, step-through, and animate classic coding interview problems directly in your terminal with beautiful ANSI visuals, real-time variable inspection, a code stepper, and step-by-step explanations.
---
## ⨠Features

* **Interactive ASCII Renderers**: Visualized trees, grids, and arrays respond dynamically as the algorithm executes.
* **Trace-Driven Replay**: Leverages Python's execution tracing (`sys.settrace`) to record and reconstruct step-by-step algorithm states.
* **Variable Inspector & Legend Panel**: Keeps track of current variables, recursions, pointers, and color-coded state transitions.
* **Integrated Code Stepper**: Highlights the exact line of Python code running at each step of execution.
* **Custom Input Support**: Modify tree structures, grid dimensions, and array contents live in the application using standard format notation.
* **Hot-Reloading Dev Runner**: Active development watcher watches `.py` and `.css` files and restarts the TUI instantly on change.
---
## đ¨ Color Palette & Themes
The visualizer runs a sleek, modern Tokyonight-inspired aesthetic:
* đ **Background**: `#252836` & `#1E2230`
* ⥠**Accent Blue**: `#7AA2F7`
* đŋ **Success Green**: `#9ECE6A`
* đ¸ **Warning/Pointer Yellow**: `#E0AF68`
* đš **Critical/Path Red**: `#F7768E`
---
## đ Installation & Getting Started
### Prerequisites
* **Python**: `>=3.11`
* **Package Manager**: `brew`, `pipx`, `pip`, or `uv`
### Option 1: macOS Homebrew (Recommended)
The cleanest way to install on macOS without interacting with system Python environments or virtual environments.
```bash
# 1. Tap the repository
brew tap sunil-kumarr/tap
# 2. Install the application cleanly
brew install lastcode-tui
```
### Option 2: via PyPI (`pipx` or `pip`)
Because modern operating systems enforce environment protections (PEP 668), installing standalone global terminal applications via standard `pip install` will often fail. Use `pipx` to run the tool in an isolated sandbox.
```bash
# Recommended for global installation:
pipx install lastcode-tui
# Alternatively, run instantly using uv without permanent installation:
uvx lastcode-tui
```
### Option 3: Local Development (Source Build)
If you are planning to contribute or modify the visualizer core:
1. Clone the repository:
```bash
git clone https://github.com/sunil-kumarr/lastcode.git
cd lastcode
```
2. Create and activate a virtual environment:
```bash
python3 -m venv .venv
source .venv/bin/activate
```
3. Install the package in editable mode:
```bash
pip install -e .
```
---
## đšī¸ Usage
### Run the Visualizer
Once installed via any option above, start the interactive engine from anywhere in your terminal:
```bash
lastcode
```
For a local source checkout, you can also run the module directly:
```bash
python -m lastcode
```
### Hot-Reloading for Development
If you are modifying code, stylesheets, or adding new problems, run the watcher script inside your source directory. It will instantly reload the application in the terminal when changes are saved:
```bash
python dev.py
```
---
## đŽ Keybindings & Controls
### đ Home / Menu Screen
| Key | Action |
| :--- | :--- |
| `â` / `â` | Navigate the problem list |
| `t` | Cycle topic filters (*tree, grid, graph, array, string, dp*) |
| `d` | Cycle difficulty filters (*easy, medium, hard*) |
| `Enter` | Launch the selected visualizer |
| `q` | Quit application |
### đ ī¸ Visualizer Screen
| Key | Action |
| :--- | :--- |
| `â` / `l` | **Step Forward** to the next execution frame |
| `â` / `h` | **Step Backward** to the previous execution frame |
| `Space` | **Play / Pause** auto-playback animation |
| `i` | **Edit Input** (Focuses input field to provide custom data structures) |
| `Enter` | **Submit** custom input (Parses, validates, and runs the visualizer on your input) |
| `Escape` | **Home / Cancel** input edit and return to main menu |
| `q` | **Quit** application |
---
## đī¸ Custom Input Formats
You can press `i` on any visualization screen to customize the input. Values are parsed securely using Python's `ast.literal_eval`.
### đŗ Binary Trees
Binary trees are represented using level-order lists.
* **Simple Binary Tree**: `[1, 2, 3, None, 4]` (representing a tree with root `1`, children `2` and `3`, and leaf `4` on the right of `2`).
* **Path-Sum Tree Problems**: `([1, 2, 3], 4)` (a tuple containing the tree array and target integer).
* *Note: Maximum tree size supported is 31 nodes.*
### đēī¸ Grids (Count Islands)
Grids are parsed as 2D lists of `0`s (water) and `1`s (land).
* **Format**: `[[1, 1, 0], [0, 1, 0], [1, 0, 1]]` (all rows must have equal width).
### đĸ Arrays & Strings
* **Two Sum**: `[2, 7, 11, 15], 9` (the array part, followed by a comma and target sum).
* **Valid Parentheses**: `(){}[]` (a simple string of bracket characters).
---
## đ Project Structure
```text
lastcode/
âââ dev.py # Hot-reloading watcher script
âââ pyproject.toml # Project dependencies and script endpoints
âââ lastcode/
â âââ main.py # Main entrypoint
â âââ app.py # Main visualizer screens and layout controllers
â âââ home.py # Home screen widgetry and filters
â âââ recorder.py # Core logic tracer (tracks call frames and values)
â âââ theme.py # Central design-system colors
â âââ problems/ # Interactive problems repository
â â âââ registry.py # Problem metadata & path registration
â â âââ bt_inorder.py # Binary Tree Inorder Traversal
â â âââ count_islands.py # Count Islands
â â âââ ... (20+ algorithm modules)
â âââ renderers/ # UI renderers
â â âââ base.py # Renderer protocol definitions
â â âââ tree.py # Tree structure layout & animation renderer
â â âââ grid.py # 2D Grid DFS/BFS layout renderer
â â âââ array.py # 1D Array tracker & stack renderer
â âââ widgets/ # Reusable textual widgets
â âââ ... # Scrubber bars, Legend keys, variable drawers
```
---
## đ License
This project is licensed under the MIT License.