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

image image image
  • 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

๐Ÿš€ Getting Started

Prerequisites

  • Python: >=3.11
  • Package Manager: pip (or uv for lightning-fast installation)

Installation

  1. Clone the repository:

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

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

    pip install -e .
    

๐Ÿ•น๏ธ Usage

Run the Visualizer

Start the application from anywhere using the installed shortcut:

lastcode

Or 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. 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.1.tar.gz (115.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.1-py3-none-any.whl (170.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lastcode_tui-0.1.1.tar.gz
  • Upload date:
  • Size: 115.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.1.tar.gz
Algorithm Hash digest
SHA256 9b6a93ba1303fac0cab61cfaeee32237d09aaa64a2cac618b82e4ca549449708
MD5 4498e3f7e9f90fb084bd5aa93df3044d
BLAKE2b-256 f2e4fdc63397ad0abd76ef8ff74252be6ca3341299bc1d73f32935b8422360ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for lastcode_tui-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: lastcode_tui-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 170.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e29c7f84cf1da71f5817dbf845dde1b56e3f102c985509d218a001bce519ac89
MD5 fa8a31c38b3ca92028ee4fbc2a8fce0b
BLAKE2b-256 00dc1e43d096ccb80e77969fc1d045e2bf8a4e0946df5301ed6dd74e375e270a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lastcode_tui-0.1.1-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