Hacker News new | ask | show | jobs
by msla 2722 days ago
Cross-platform terminal coloring was solved in the 1980s with termcap and then terminfo, for every terminal that's even come close to seeing mainstream use and which had colors in the first place. The libraries are part of the ncurses library and are shipped with every OS this stuff would build on to begin with.

This also solves the problem of moving the cursor and drawing a screen in general.

4 comments

Eh, A lot of modern terminal emulators don't seem to bother providing termcap/info entries, or setting their own $TERM variables. In reality, most code just fires off ANSI sequences and hopes for the best. Looking quickly at the source for Hexyl, I think that's what the ansi_term library it uses does.

If anything, I've found doing this works better then trying to muck around with ncurses, which often gets actively mislead by incorrect terminfo entries.

ncurses wins once you use terminals beyond xterm.
Aren't termcap and terminfo linux (or maybe unix) only?
Both of them long predate Linux. They're definitely Unix-flavored, but so's the Berkeley sockets library, and that's available everywhere, too. Ultimately, they're a library which is packaged with a database, and nothing about them is very system-specific except the terminal information in the database.

https://en.wikipedia.org/wiki/Terminfo

termcap was written by Bill Joy in 1978. terminfo dates back to 1982.
termcap is supported on FreeBSD, at the least.
termcap/terminfo styling is limited to features like underline, bold and reverse. No coloring, per se.
"man terminfo | grep color" shows that pretty clearly to not be the case. There's plenty of codes for setting colors.
It's entirely possible termcap and terminfo have been allowing applications to color their output for longer than you've been alive.
The downvotes prove how much HN hates history, I suppose.