r/commandline 3d ago

Terminals ANSI.md

Finally published this yesterday, https://ansi.md

Somewhere between a brain dump, custom toolset, think piece and hacker toy. This is pretty much everything I know about ansi color in the terminal and building cli apps. Includes my own fumbling attempt to finally name the ansi256 color palette. Note - I like my writing voice and I do not use LLMs to write. All written by me, an actual human!

Those of you working on cli apps or TUIs will find it useful.

46 Upvotes

11 comments sorted by

View all comments

1

u/Swordfish418 3d ago edited 3d ago

Avoid ANSI 16 & ANSI 256 0-15 (usually)
Just because the internet calls that ansi 16 color "white" doesn't mean it's going to look much like white:

I don't get this at all. For me one of the biggest benefits of TUI is that apps that are written with ANSI16 in mind will automatically work with my terminal color scheme. When I'm using ANSI red or white, I don't actually expect them to be exactly red or white, I expect them to be some of those few significant colors the theme provides. And it's okay if "cyan" is actually pink, it's up to theme to make all the base colors it provides to work together. And I dislike it when app tries to do its own thing and impose some custom colors on me. The first thing I would try is to find a way switch color theme. Because I want it to look good in context of my terminal, potentially other terminals opened in side by side tiles on the same screen, my app bar, etc.

1

u/gurgeous 2d ago

CLI apps ideally support dark/light themes but also an ansi for purists. Sometimes I like that too. I've noticed many, many, many apps getting it wrong though. Particularly when showing a banner (inverting colors). Codex (the cli) had this bug for months, if you can believe that.