There's no escaping it: an exploration of ANSI codes
6 hours ago
- #ANSI codes
- #CLI design
- #terminal history
- ANSI escape codes are a nearly 50-year-old standard still used for terminal text formatting and interaction, such as colors, cursor movement, and progress bars.
- They work via control sequences starting with ESC and a left bracket (CSI), followed by commands like setting colors (e.g., \x1b[31m for red) and combining attributes with semicolons.
- Modern terminals extend the original 8 colors to 256 and 24-bit RGB, enabling advanced CLI interfaces, with tools like Spectre.Console and chalk simplifying their use.
- ANSI codes enable interactive terminal UIs in tools like Vim and htop via cursor positioning and screen manipulation, and the blog includes an interactive widget to experiment with sequences.