Project 1: ANSI Paint

A simple “paint” program where you move the cursor with arrow keys and press the spacebar to “draw” a colored block at the cursor’s position, all by printing raw ANSI escape codes.

Quick Reference

Attribute Value
Primary Language Python
Alternative Languages C, Go, Rust
Difficulty Level 1: Beginner
Time Estimate Weekend
Knowledge Area Terminal Control / Escape Codes
Tooling Any standard terminal
Prerequisites Basic programming in any language.

What You Will Build

A simple “paint” program where you move the cursor with arrow keys and press the spacebar to “draw” a colored block at the cursor’s position, all by printing raw ANSI escape codes.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Disabling canonical mode and echo → maps to reading keystrokes instantly without waiting for Enter
  • Parsing multi-byte escape codes for arrow keys → maps to understanding that special keys are not single characters
  • Manually tracking cursor position → maps to managing your own UI state
  • Sending the correct codes to move the cursor and change color → maps to direct terminal manipulation

Key Concepts

  • Terminal Modes (canonical, raw): “The Linux Programming Interface” Chapter 62 - Terminals
  • ANSI Escape Codes: ANSI escape code (Wikipedia)
  • Non-blocking I/O: Python tty and termios modules documentation

Real-World Outcome

(Terminal Output)

    +----------------------------------------+
    |                                        |
    |                                        |
    |          ███                           |
    |          █  █                          |
    |          ███                           |
    |                                        |
    |                 █████                  |
    |                                        |
    +----------------------------------------+
  Current Color: RED | Position: (18, 9) | Press 'q' to quit

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_TUI_PROGRAMMING_PROJECTS.md
  • “The Linux Programming Interface” by Michael Kerrisk