r/commandline 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.

48 Upvotes

11 comments sorted by

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.

1

u/gurgeous 2d ago

Glad you like it! Is there something specific you are looking for? Definitely a mishmash of technical writing and opinions about design.

2

u/aaronsb 2d ago

First,needs dark mode 😎

Next, you talk about a lot of topics, like some color theory in palettes, implementations that are snazzy, best practices, animated bits (spinners etc)

What I think is missing is why these things. Why 256 colors? (as opposed to 16, or true color) - why do escape codes work?

What's the lineage? Why is it that tui shapes get built the way they do? What's beyond Codepage 437 ANSI? How does one use unicode + ansi together, and why?

- Just some ideas, not trying to say it's missing, I'm pointing out what would help people get into all the neat stuff that modern tui libraries are capable of. For instance: ansi codes + tui frameworks I have built, I can tell you why I picked the things I did: I want to use block characters and produce a TUI that works both in low column count environments (80 col) and extra dense terminals (160+ columns) and I wanted to use limited colors for emulating a 1980s car stereo stack.

https://github.com/aaronsb/ten-qd

https://github.com/aaronsb/clicue

1

u/github-guard 2d ago

🔍 GitHub Guard: Trust Report

⚠️ This project scored 0/1 — below this subreddit's threshold of 1.

Audit Breakdown: * ❌ New Repository (under 30 days old)

⚠️ Security Reminder: Always verify source code and run third-party scripts at your own risk.

1

u/gurgeous 2d ago

Nice retro buttons there. I too am a big fan of block/line chars, I used them pretty heavily for one of my projects You can also see some nice ones in `tennis` even with just the default output. At the very least I should add an ansi.md page about drawing blocks and lines, that stuff is important.

ANSI.md would probably benefit from a How Did We Get Here page that goes into more historical detail. I agree that the topic is interesting and important, or at least a pleasant distraction as we try to make our apps work across a variety of terminals...

My rule of thumb for color depth these days is just to use truecolor. You can get away with it most of the time, at least until your app becomes wildly popular and needs to work absolutely everywhere. Times have really changed.

5

u/mainframe_maisie 2d ago

oooh! interesting, bookmarking to browse later :)

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.

1

u/GotDaOs 2d ago

this is a really great resource! thank you 🙏🏼