From Logic Gates to Production Terminal Emulators
Rebuild the computer from electrons to a GPU-accelerated terminal emulator — then contribute to Ghostty with genuine understanding.
After this course, you can explain every layer from transistor to GPU-accelerated terminal to a 5-year-old, implement a working terminal emulator from scratch, contribute to Ghostty with genuine understanding of the codebase, and transfer the knowledge to adjacent systems problems (vLLM KV-cache, kernel hacking, GPU programming).
8 lessons. From electrons to main(). From fork() to framebuffers. From VT100 escape sequences to Metal shaders. Everything wired together into a working terminal emulator.
This is not a survey course. Each concept has a hands-on project. After you build it, you read how the Ghostty authors built the same thing. The gap between "I read about it" and "I understand it" is implementation.
Context
- Assumes comfort with C and a willingness to read assembly, kernel interfaces, and GPU concepts
- Every concept is traced to its physical implementation (transistors for logic, page tables for virtual memory, Metal command buffers for rendering)
- Ghostty source is used as the reference implementation — after you build something, you study how production engineers solved the same problem
- Cross-domain bridges connect terminal emulation concepts to adjacent fields: vLLM KV-cache management, CUDA kernel programming, kernel hacking
- The voice is direct and engineering-first — no hand-waving, no "it just works," no abstraction without explanation
How to Use
- Lessons 1-5 build the foundation. Don't skip ahead. The terminal protocol (Lesson 6) makes no sense without understanding PTYs (Lesson 3). The GPU renderer (Lesson 7) is opaque without memory management (Lesson 4) and concurrency (Lesson 5).
- Each lesson ends with a project. Build it. Reading about
fork()and writingfork()are different activities. - After building each project, read the corresponding Ghostty source files listed at the end of each lesson. The contrast between your implementation and production code is where the deep learning happens.
- Lessons 6-8 are the terminal-specific stack. They depend on everything that came before.
- The final project,
toyterm, wires every piece together. You will have built and tested each component independently before integration day.
Project Arc
flowchart TD
minish["minish (Lesson 2)<br/>shell with fork/exec<br/>pipes, signals, jobs"]
ptycat["ptycat (Lesson 3)<br/>PTY inspector<br/>raw byte flow"]
toyterm["toyterm (Lesson 8)<br/>full terminal emulator<br/>GPU rendering, fonts"]
vtparse["vt-parse (Lesson 6)<br/>VT state machine<br/>CSI/OSC/SGR parser"]
renderdemo["render-demo (Lesson 7)<br/>GPU text rendering<br/>FreeType + HarfBuzz"]
minish --> vtparse
ptycat --> vtparse
ptycat --> renderdemo
vtparse --> toyterm
renderdemo --> toyterm
Each project is a component of the final toyterm. By the time you build toyterm, you have built and tested every piece independently.
Ghostty File Map
| Lesson | Source Files | What to learn |
|---|---|---|
| 1 | src/renderer/Metal.zig |
mmap for GPU buffers, cache-friendly cell grids |
| 2 | src/termio/Exec.zig, src/termio/Termio.zig |
fork/exec/PTY creation, signal handling |
| 3 | src/termio/Termio.zig |
termios, raw mode, window resize |
| 4 | (allocator patterns throughout) | Zig's explicit allocator passing |
| 5 | src/termio/mailbox.zig, src/Surface.zig |
Lock-free SPSC queue, thread orchestration |
| 6 | src/termio/StreamHandler.zig, src/terminal/Terminal.zig |
VT parser state machine, terminal state |
| 7 | src/renderer/, src/font/ |
Metal/OpenGL backends, font discovery and shaping |
| 8 | (all of the above) | Integration: how it all fits together |
Learning Principles
- Feynman test: If you can't explain it to a 5-year-old, you don't understand it yet.
- First principles: Start from what you know and build up — never accept "it just works."
- Implementation over reading: Every concept has a hands-on project.
- Ghostty as reference: After you build it, read how the pros did it.
- Cross-domain transfer: Memory allocators → vLLM KV-cache. Atomics → Ghostty mailbox. GPU pipeline → CUDA kernels.