Project 5: The Raw Mode Terminal (Text Editor Base)

A program that enters “Raw Mode”. It disables the terminal’s default behavior (echoing characters, line buffering, handling Ctrl+C). You will read input byte-by-byte and render output manually, moving the cursor using VT100 escape sequences. This is the foundation of vim or nano.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Rust
Difficulty Level 3: Advanced
Time Estimate 1 week
Knowledge Area TTY / Termios
Tooling termios.h
Prerequisites C basics, Bitwise operations.

What You Will Build

A program that enters “Raw Mode”. It disables the terminal’s default behavior (echoing characters, line buffering, handling Ctrl+C). You will read input byte-by-byte and render output manually, moving the cursor using VT100 escape sequences. This is the foundation of vim or nano.

Why It Matters

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

Core Challenges

  • Termios Struct: Modifying flags ECHO, ICANON, ISIG.
  • Escape Sequences: Sending \x1b[2J to clear screen.
  • Restoring State: If your program crashes in Raw Mode, your terminal is broken. You must implement atexit handlers.

Key Concepts

  • Cooked vs Raw Mode: Canonical vs Non-canonical input.
  • Control Characters: What Ctrl+C (3) and Enter (10/13) actually send.
  • VT100/ANSI Codes: Controlling the cursor.

Real-World Outcome

$ ./raw_term
(Screen clears)
[Type 'q' to quit]
You pressed: 'a' (97)
You pressed: 'Ctrl+C' (3) - Not exiting!
...

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_LINUX_UNIX_INTERNALS_DEEP_DIVE.md
  • “The Linux Programming Interface”