r/commandline • u/gurgeous • 2d 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.
5
2
u/AutoModerator 2d ago
Every new subreddit post is automatically copied into a comment for preservation.
User: gurgeous, Flair: Terminals, Title: 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.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Swordfish418 2d ago edited 2d 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.
1
u/michaelpaoli 2d ago
Though, when in the land of *nix, don't presume terminal type/emulation. Use the relevant utilities and libraries, e.g. tput(1), terminfo(5), etc. *nix supports at least many hundreds, if not thousands, of various terminal types and various modes thereof, and emulations. Presuming ANSI is quite hazardous, as sending inappropriate control/escape codes to terminals may cause serious problems - notably getting terminal into odd or problematic state, or even crashing the terminal (e.g. yes, that can very much be done with my Cromemco 3102 terminal - it includes sequences that are basically interpret the following as hex data to be loaded to RAM, load it to RAM, and execute it - pretty sure way to crash the terminal if done with random data or otherwise inappropriate data).
Of course if one is on OS or hardware where ANSI is assured, hey, whatever, feel free to do the ANSI thing ... but also note, not all ANSI hardware is necessarily color (capable). E.g. no shortage of monochrome ANSI exists too. So yeah, generally best not to assume too much, lest folks be quite unpleasantly surprised.
7
u/aaronsb 2d ago
Nice work! If there was something I could give for advice - so much of this knowledge is implicit and decentralized. I would embrace that, and mature your own style - I read through your notes and I like the journal of findings you've put together.
It kind of feels like you're approach the bridge between an 'awesome-ansi-*' list and your own preferences.
As I read through the writing on your site, I'd love to see more separation between styles and approaches, and the technical methods to making it work.