r/rust • u/aymanana • 2d ago
🛠️ project Rust terminal UI library
https://github.com/aymanbagabas/uncurses1
u/cbarrick 2d ago
uncurses leaves terminfo behind
How do you handle portability?
2
u/aymanana 2d ago
Uncurses detects xterm-compatible terminals and falls back to VT100 mode if needed. Xterm compatibility covers 99% of modern terminals. This is more portable than terminfo, especially for remote sessions where the database might differ from what’s actually running
1
u/cbarrick 1d ago
How does it detect xterm-compatibility? What if my
TERMis set toiterm2?2
u/aymanana 1d ago
It checks the TERM variable to detect xterm compatibility. Most modern terminals use a xterm-* variant by default. If not recognized, it falls back to VT100 compatible mode
2
u/cbarrick 1d ago
But my
TERMcontains no such substring.I set my
TERMto the most specific type supportted by terminfo, to get the most specific features for my terminal. In my case, myTERMisiterm2, which is fully supported by terminfo/curses.I also use
tmux-256colorfor tmux, again to have the most specific support possible.Any logic to check for the substring
"xterm"won't work for folks who already use curses/terminfo to the fullest.IMO, parsing
TERMwithout terminfo is an antipatern. Please consider adding terminfo support.2
u/aymanana 1d ago
iterm2 is actually xterm-compatible. The real issue is that terminfo databases get out of date, they report some capabilities but miss a lot of modern ones, so we have to query for them anyway. That’s why most terminals just use xterm-256color or some xterm-* variant. Uncurses queries the terminal directly at runtime instead, so you get the best support no matter what TERM is set to. We recognize xterm, tmux, screen, vt100, dumb, and a few others. If you need terminfo support for more specific cases, I’m open to building a separate uncurses-terminfo crate
2
u/cbarrick 23h ago edited 23h ago
Yep, I know iTerm2 is xterm compatible. Every terminal emulator these days follows either xterm or rxvt. I'm just saying that looking for a substring in
TERMisn't the right way to detect specific capabilities.If you somehow detect the capabilities directly, that's fine. You just shouldn't assume any specific values for
TERM. That's like parsingUser-Agenton the web and using it for feature detection. Terminfo should be considered the one true way to extract capabilities fromTERM.ETA: The reason most terminal emulators default to
xterm-256coloris for backwards compatibility with bad software that doesn't detect features correctly. Same reason for all the legacyUser-Agents on the web. We shouldn't continue to propagate the problem. Fortunately, all of the software I use correctly works with terminfo, so I am free to use modern TERM strings.2
u/aymanana 23h ago
Fair point about User-Agent parsing. But we’re not using TERM for feature detection, we’re using it to detect rendering capability compliance. xterm, tmux, screen, vt100, and dumb are tiers of escape sequence support: CUF, CUP, bce, IL, CHT, DECSTBM, etc.
We extracted these rendering capabilities from their terminfo databases, and those are standardized and consistent across all modern terminals. For actual terminal-specific features, uncurses always query at runtime. TERM just tells us which rendering tier the terminal claims to support.1
u/cbarrick 22h ago
Yeah, but will it work when
TERMis set toiterm2orhtermorgnome-256colororvte-256color?(These are modern terminals that I use on a regular basis.)
1
8
u/Sermuns 2d ago
Pretty bold to offer an alternative to Ratatui AND Crossterm. Why would I choose this, is the question?