Setup
Before writing any TUI code you need three things: Node.js, a terminal that supports ANSI, and the example repository cloned locally.
Requirements
Section titled “Requirements”| Tool | Version | Why |
|---|---|---|
| Node.js | ≥ 20 | Built-in readline, process.stdin raw mode |
| TypeScript | ≥ 5 | Types for Node built-ins |
tsx | latest | Run .ts files directly without a build step |
Check your versions:
node --version # should print v20.x or higherInstall the Example Dependencies
Section titled “Install the Example Dependencies”All runnable examples live in the examples/ directory at the root of this repo. They share a single package.json:
cd examplesnpm installThis installs:
chalk— terminal string styling (colors, bold, italic). Thin wrapper around ANSI codes. We use it so we can focus on structure rather than memorizing every escape sequence.ansi-escapes— cursor movement, screen clearing, and other ANSI operations as readable functions.tsx— TypeScript executor. Run any example withnpx tsx <file>.ts.@types/node— TypeScript types for Node.js built-ins.
Running an Example
Section titled “Running an Example”Every example in this course is a standalone .ts file you can run immediately:
cd examplesnpx tsx module-1/01-hello.tsTerminal Compatibility
Section titled “Terminal Compatibility”This course targets any modern terminal that supports 256-color ANSI. That covers:
- Linux: Any modern terminal emulator (Konsole, GNOME Terminal, Alacritty, Kitty, WezTerm)
- macOS: Terminal.app (macOS 10.14+), iTerm2, Warp
- Windows: Windows Terminal with WSL2
If you are on Windows without WSL, some examples involving raw mode may need small adjustments — we will note these when they come up.
A Note on process.stdout.write vs console.log
Section titled “A Note on process.stdout.write vs console.log”You will see process.stdout.write(...) throughout this course instead of console.log(...).
The difference matters for TUIs:
console.logalways appends a newline (\n) at the end.process.stdout.writegives you exact control — no automatic newline.
When you are drawing UI elements at specific cursor positions, an unwanted newline shifts everything down. So we use process.stdout.write for all rendering.