Skip to main content

An interactive Terminal User Interface (TUI) for real-time algorithm and data structure visualization

Project description

๐ŸŒŒ lastcode

A sleek, terminal-based interactive visualizer for tree, graph, grid, and array algorithms. Built with Python and the 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

lastcode tree visualizer screenshot lastcode grid visualizer screenshot lastcode array visualizer screenshot
  • 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.

# 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.

# 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:

    git clone https://github.com/sunil-kumarr/lastcode.git
    cd lastcode
    
  2. Create and activate a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    
  3. Install the package in editable mode:

    pip install -e .
    

๐Ÿ•น๏ธ Usage

Run the Visualizer

Once installed via any option above, start the interactive engine from anywhere in your terminal:

lastcode

For a local source checkout, you can also run the module directly:

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:

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 0s (water) and 1s (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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lastcode_tui-0.1.2.tar.gz (142.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lastcode_tui-0.1.2-py3-none-any.whl (229.8 kB view details)

Uploaded Python 3

File details

Details for the file lastcode_tui-0.1.2.tar.gz.

File metadata

  • Download URL: lastcode_tui-0.1.2.tar.gz
  • Upload date:
  • Size: 142.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lastcode_tui-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1997a3b376b6db6c952963770e7012c9b65df1955e4d2be071961b10f75d06c1
MD5 f6131ff27ea4703ee2fab99efe08eb3b
BLAKE2b-256 c738da4dd7605ff45fedf5fbb01f4532e8af4ce438e612b61a241fd35c26192f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lastcode_tui-0.1.2.tar.gz:

Publisher: publish.yml on sunil-kumarr/lastcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lastcode_tui-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lastcode_tui-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 229.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lastcode_tui-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96cf7ca79be8bb5d5527864c230df35fc62889147e31fd7bb29503b252cf3131
MD5 023e1a97485a93fcae8b60ac19f6ff86
BLAKE2b-256 cf594f1736f4e20bfa933c363e3c8044e0633d002d24c8735437589679c3ec76

See more details on using hashes here.

Provenance

The following attestation bundles were made for lastcode_tui-0.1.2-py3-none-any.whl:

Publisher: publish.yml on sunil-kumarr/lastcode

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page