Skip to content

Setup

Before writing any TUI code you need three things: Node.js, a terminal that supports ANSI, and the example repository cloned locally.

ToolVersionWhy
Node.js≥ 20Built-in readline, process.stdin raw mode
TypeScript≥ 5Types for Node built-ins
tsxlatestRun .ts files directly without a build step

Check your versions:

Terminal window
node --version # should print v20.x or higher

All runnable examples live in the examples/ directory at the root of this repo. They share a single package.json:

Terminal window
cd examples
npm install

This 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 with npx tsx <file>.ts.
  • @types/node — TypeScript types for Node.js built-ins.

Every example in this course is a standalone .ts file you can run immediately:

Terminal window
cd examples
npx tsx module-1/01-hello.ts

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.log always appends a newline (\n) at the end.
  • process.stdout.write gives 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.