5 ms·
Part of the problem with colors is the recent trend of ignoring terminfo and TERM in favor of hard-coding escape sequences. Guilty packages include: * ipython
by quotemstr 2y ago
Part of the problem with colors is the recent trend of ignoring terminfo and TERM in favor of hard-coding escape sequences. Guilty packages include:
* ipython/prompt_toolkit (https://github.com/prompt-toolkit/python-prompt-toolkit https://github.com/prompt-toolkit/python-prompt-toolkit),
* chalk (https://github.com/chalk/chalk https://github.com/chalk/chalk),
* linenose (https://github.com/antirez/linenoise https://github.com/antirez/linenoise), and
* plenty of other random programs.
Please, let's just stop doing things this way. I understand that talking to libterminfo is annoying, but it produces a better result for everyone than everyone maintaining obsolete and incomplete databases mapping TERM values to capabilities.
That's not to say libterminfo is great either: we got into this mess partly because for (IIRC) ~10 years or so, the ncurses people stopped updating the terminal database with information about new capabilities like bracketed paste and 256 color support, forcing authors of programs wanting to use these features into using dirty hacks to detect or configure support --- and everyone has a different dirty hack!
Also, terminfo in inconvenient when jumping between machines. Who among kitty users, for example, has never experienced weirdness after ssh because the target machine doesn't have a terminfo file for "xterm-kitty"?
To fix this mess, we need to:
1. Define a new cross-terminal-emulator OSC sequence that instructs the terminal emulator to echo back THE WHOLE TERMINFO CAPABILITY STRING, in-band. No "user agent sniffing" with TERM. We detect features directly from now on.
2. Stop hard-coding random "ANSI" escapes. Use a library. Ask that library, "What does this terminal support? What strings do I use to accomplish what I want?" and then use it.
3. By default, don't output escape codes if output isn't a tty.
(#2 (by recognizing TERM=dumb) and #3 (because pipes) also address the problem of escape sequences ending up in the middle of output files and shell pipelines.
The terminal world is a mess right now. Continuing to live in squalor is a choice.
- Ferret7446 2y agoA lot of people now don't know how terminals work or even that terminfo exists. Unfortunately due to the progression of technology and education, a lot of foundational knowledge is not being learned. Terminals are probably one of the biggest losers in this area. Even many technically knowledgeable people only know of terminals as "that box that pops up where you can type commands". They cargo cult/copy-paste the common escape sequences. Most things work "good enough" now that they never have any reason to learn more.
- navi-desu 2y ago> 1. Define a new cross-terminal-emulator OSC sequence that instructs the terminal emulator to echo back THE WHOLE TERMINFO CAPABILITY STRING, in-band. No "user agent sniffing" with TERM. We detect features directly from now on. XTGETTCAP does that (kindof), it's implemented by xterm, kitty, and foot. xterm allows querying keyboard caps, plus a few others kitty adds to that querying all integer and string caps foot adds to that bools caps, meaning in foot you can query all of terminfo via it. what we need to do is bring other terminal emulators up to par with foot's XTGETTCAP, and then we can finally ditch libterminfo for good.
- quotemstr 2y ago> XTGETTCAP does that (kindof), it's implemented by xterm, kitty, and foot. Oh, cool. Agreed we need to bring other terminal emulators up to speed. I might as well do Emacs's.
- spudlyo 2y agoI'd like to re-emphasize point #3. FOR THE LOVE OF GOD, if you are going to spew random ANSI escape sequences to stdout, please, please, please, ensure[0] that it's a goddamn tty! [0]: https://www.man7.org/linux/man-pages/man3/isatty.3.html https://www.man7.org/linux/man-pages/man3/isatty.3.html
- kps 2y agoOne related: If you are a terminal emulator, and you default your TERM to xterm-somethingorother, it is on you to actually support xterm control sequences.