News for hackers. Stuff that matters.
Re:Some Terminal Frustrations by quotemstr on Sunday February 09, 2025 @06:00PM (#42995025)
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),

* chalk (https://github.com/chalk/chalk),

* linenose (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.

Re:Some Terminal Frustrations by Ferret7446 on Monday February 10, 2025 @02:09AM (#42997674)
A 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.

Re:Some Terminal Frustrations by zokier on Monday February 10, 2025 @11:54AM (#43002386)
In what universe is terminfo "foundational knowledge"
Re:Some Terminal Frustrations by quesera on Monday February 10, 2025 @01:03PM (#43003180)
The Unix universe obviously.
Re:Some Terminal Frustrations by navi-desu on Monday February 10, 2025 @08:51AM (#43000293)
> 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.

Re:Some Terminal Frustrations by quotemstr on Monday February 10, 2025 @01:34PM (#43003525)
> 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.

Re:Some Terminal Frustrations by spudlyo on Monday February 10, 2025 @09:32AM (#43000713)
I'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

Re:Some Terminal Frustrations by kps on Monday February 10, 2025 @10:20AM (#43001310)
One 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.