rapid1337.com

ANSI Escape Codes, the Short Version

2026-06-10 · [ code ] · by staff · C

The handful of escape sequences you actually use to colour a terminal.

<-- Starfield | [ Code ]

[ read in diskmag ]


Everything colourful in a terminal is just ESC [ followed by a few numbers and a letter. Here's the minimum viable cheat sheet.

#define RESET   "\x1b[0m"
#define BOLD    "\x1b[1m"
#define FG(n)   "\x1b[38;5;" #n "m"   /* 256-colour foreground */

printf(FG(213) BOLD "rapid1337" RESET "\n");

38;5;n selects a colour from the 256-colour cube; swap 38 for 48 and you set the background instead. That's 90% of what any TUI needs.

#c #terminal


<-- Starfield | [ Code ] | Rodland – Cracking Tutorial [FRENCH] -->