🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.perl.misc
Article #9

Re: a question about TUIs and raw input from ttys

#9
From: Eli the Bearded
Date: Sun, 06 Dec 2026 07:27
68 lines
4023 bytes
In comp.lang.perl.misc, Ivan Shmakov  <ivan@siamics.netREMOVE.invalid> wrote:
> 	Not sure I understand how that can happen.  I'm pretty certain
> 	XTerm does /not/ use separate threads for keyboard input and
> 	cursor position reporting, so I fail to see how an ESC sequence
> 	generated in one part of the code can "corrupt" one generated
> 	elsewhere.

Nevertheless, running that function less frequently fixed things. It
could well be that the keyboard came in before the escape sequence, not
in the middle of it. My code would see a 'j' (say) where it expects ESC
and bail, but the 'j' would not be unread for other parts of the code to
look at.

>  > In C, I've used ncurses and it's a been a while, but at minimum it
>  > provides the escape sequence definitions for the keys like "UP".
> 
> 	"UP" (KEY_UP) is a number that fits "int" but not "char".
> 	When getch(3) is called, it can return such a number in place
> 	of the codes of the ESC sequence, but the ESC sequences it
> 	translates into numbers are still taken from the databases.
> 
> 	See, e. g., http://man.netbsd.org/getch.3 .

"If the keypad() flag has been set to TRUE, then getch() will assemble
multi-character key sequences into key symbols"

A non-default behavior, but true.

> 	That said, getch(3) /is/ part of the Curses library, indeed.

I checked local documentation, but I have very little since my last
OS install and didn't pursue re-installing the docs.

$ man getch
No manual entry for getch
$ man 3 getch
No manual entry for getch in section 3


> 	You've made your code the subject of a public discussion, and
> 	thus open to criticism.  Which is what I'm doing: pointing out
> 	that your code will be better were it to use the databases.

Point taken.

> 	I have to note, however, that the two Terminfo libraries that
> 	I'm (somewhat) familiar with both use binary formats for their
> 	databases - and those formats are /not/ compatible.  AFAIK,
> 	the only "portable" way to query these binary databases is to
> 	use terminfo(3) functions - either directly, or through tput(1)
> 	or infocmp(1).

I've used tput() in shell scripts before. And I know that some tools
(eg screen) put the terminal definition in the environment. On both
of the systems I have handy to test (Debian and NetBSD), I can get a
text version of the terminal with infocmp, which is easy enough (for
me) to parse. I have used systems, but not in decades, where the tool
was untic instead. And running infocmp once during startup is a level
of relying on other tools that I'd be comfortable with.

I'm not sure how far I'd want to go to supporting non-UTF-8 output
however. There probably are ways to display all the characters I'm using
a real VTxyz terminal (for some xyz), but it involves the alternate
character set options.

Elijah
------
parsing infocmp output might be fun
Technical Details
Message-ID: <eli$2612060143@qaz.wtf>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
References: <eli$2611290036@qaz.wtf> <wPRxP9j06Ip0AEM2@violet.siamics.net> <eli$2612040037@qaz.wtf> <zB_4TNOhVZyRdrnE@niodd.siamics.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!.POSTED.panix5.panix.com!qz!not-for-mail
From: Eli the Bearded <*@eli.users.panix.com>
Newsgroups: comp.lang.perl.misc
Subject: Re: a question about TUIs and raw input from ttys
Date: Sun, 6 Dec 2026 07:27:05 -0000 (UTC)
Organization: Some absurd concept
Message-ID: <eli$2612060143@qaz.wtf>
References: <eli$2611290036@qaz.wtf> <wPRxP9j06Ip0AEM2@violet.siamics.net> <eli$2612040037@qaz.wtf> <zB_4TNOhVZyRdrnE@niodd.siamics.net>
Injection-Date: Sun, 6 Dec 2026 07:27:05 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="panix5.panix.com:166.84.1.5";
	logging-data="14994"; mail-complaints-to="abuse@panix.com"
User-Agent: Vectrex rn 2.1 (beta)
X-Liz: It's actually happened, the entire Internet is a massive game of Redcode
X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix
X-US-Congress: Moronic Fucks.
X-Attribution: EtB
XFrom: is a real address
Encrypted: double rot-13