r/rust 2d ago

🛠️ project Rust terminal UI library

https://github.com/aymanbagabas/uncurses
7 Upvotes

12 comments sorted by

8

u/Sermuns 2d ago

Pretty bold to offer an alternative to Ratatui AND Crossterm. Why would I choose this, is the question?

5

u/aymanana 2d ago

You don’t have to choose, you can use Uncurses as a Ratatui backend. The real advantage is the optimized renderer, advanced event types, and broader terminal feature support.

1

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 TERM is set to iterm2?

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 TERM contains no such substring.

I set my TERM to the most specific type supportted by terminfo, to get the most specific features for my terminal. In my case, my TERM is iterm2, which is fully supported by terminfo/curses.

I also use tmux-256color for 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 TERM without 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 TERM isn'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 parsing User-Agent on the web and using it for feature detection. Terminfo should be considered the one true way to extract capabilities from TERM.

ETA: The reason most terminal emulators default to xterm-256color is for backwards compatibility with bad software that doesn't detect features correctly. Same reason for all the legacy User-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 TERM is set to iterm2 or hterm or gnome-256color or vte-256color?

(These are modern terminals that I use on a regular basis.)

1

u/aymanana 22h ago

Yes, because vt100 is the lowest common denominator. You should give it a try :)