Open daurnimator opened 5 years ago
disagree this is something the stdlib needs, nice target for community package
I agree. Let's keep it small. Clearly we didn't need it for #2865 and I didn't need it in #12079 (introducing more escape sequences) either. I vote on closing this issue.
learly we didn't need it for #2865 and I didn't need it in #12079 (introducing more escape sequences) either.
https://github.com/ziglang/zig/pull/12079#discussion_r920710709
I'd like to make an argument for including this. Properly doing anything with a terminal beyond printing characters (and maybe ANSI escape sequences for 16 colors) requires querying the Terminfo database. I don't like it either.
From what I can tell, all Linux distros and all BSDs (except the courageous devs at NetBSD) have ceded all terminal handling, including Terminfo parsing (and I believe the database itself!), to one library: ncurses
. For this reason, ncurses
is the de facto standard for all text/terminal UIs (TUIs) above any other documentation or man pages that might exist. I find this situation somewhat galling and I'm glad to see that people are starting to create Terminfo parsing libraries in other languages:
So yes, the status quo is to either link to ncurses
, or have the community fill the gap despite the fact that this is arguably an operating system-level feature on par with, say, hostname resolution! (Again, I'm not a fan of this whole terminal situation, but it's what we've had for 40 years and it's what we'll likely continue to have for the foreseeable future.)
Having Terminfo database path resolution and parsing in the Zig Standard Library would give every Zig developer the immediate, portable ability to create to rich terminal applications. This would not require a huge amount of code. I think it would be particularly appropriate to have a minimal library module which would:
And by "most common and universal", I mean that we don't bother enumerating things like dF: Delay in milliseconds for form feed on hardcopy terminals
. If somebody wants that outrageous 1970s stuff, they can import ncurses/tinfo
like everybody else. :smiley:
@daurnimator This looks like an excellent start: https://github.com/ziglang/zig/pull/6150 Would you mind if I tried bringing it up to date with current Zig and added the text DB parsing? Or did you have your heart set on finishing that work?
I can test on Linuxes and BSDs, but I have no idea what the Windows situation is these days (other than the new Terminal application is much more POSIX-y).
Completely Ignorable Aside: In my personal opinion, the older and much simpler /etc/termcap
file would arguably make more sense in today's modern virtual terminal world. But it's been deprecated forever and only exists on some distros to support any ancient software which might require it. Terminfo is baroque and over-engineered for today's needs, but that's the current standard.
@daurnimator This looks like an excellent start: #6150 Would you mind if I tried bringing it up to date with current Zig and added the text DB parsing? > Or did you have your heart set on finishing that work?
Go for it.
Update: Have the binary format test working after some minor fixes to update against current Zig master in this branch: https://github.com/ratfactor/zig/tree/revenge-of-terminfo
Next: 1) Test against real-life terminfo dbs, 2) Text format parsing, 3) Figure out the Windows situation.
In order to make pretty terminal UIs (e.g. for #2865), you need to be able to read terminfo files.
I wrote a module that does this in lua: https://github.com/daurnimator/lua-tui/blob/master/tui/terminfo.lua which wouldn't be a bad thing to port to zig.