Article View: comp.lang.perl.misc
Article #8Re: a question about TUIs and raw input from ttys
From: Ivan Shmakov
Date: Sat, 05 Dec 2026 17:25
Date: Sat, 05 Dec 2026 17:25
69 lines
4517 bytes
4517 bytes
>>>>> On 2026-12-04, Eli the Bearded wrote: >>>>> In comp.lang.perl.misc, Ivan Shmakov wrote: > Thanks for the write up. The actual issue was querying the terminal > for current cursor position excessively. That process is write an > escape sequence out, read what the terminal writes back. If you do > that several hundred times a second (left over code from earlier > development), then there's a good chance the human keyboard input > is just going to corrupt the cursor position output. 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. > I changed the code to read the cursor position once and things "feel" > good now, even without sysread. I suppose it's not impossible for a "read" call for one character to result in a read(2) syscall for just one byte, but I wouldn't rely on such behavior. It's certainly not what I observe on my own system, so perhaps it depends on the Perl version. Besides, perlfunc(1) cautions against it: perlfunc> WARNING: One should not attempt to mix buffered I/O (like perlfunc> "read" or "readline") with "select", except as permitted perlfunc> by POSIX, and even then only on POSIX systems. You have perlfunc> to use "sysread" instead. >> Unless I be mistaken, the Curses' main feature is that it maintains >> a screen buffer. Which is handy for fullscreen applications, but >> less applicable for things like Readline - where using Termcap / >> Terminfo support alone, rather than the entire Curses library, makes >> more sense. > 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 . That said, getch(3) /is/ part of the Curses library, indeed. I've suspected that there might be some lower-level equivalent to it, but don't see anything like that in the documentation. >> And it annoys me to no end when an application refuses to consult >> the databases and just uses hardcoded ESC sequences instead. > Yeah, I can sympathize. But I'm writing a game for my own entertainment > (both the writing and the playing), so if I'm going to use termcap / > terminfo, I'm going to write that myself. But I've not made a priority > out of it. 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. 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).
Technical Details
Message-ID:
<zB_4TNOhVZyRdrnE@niodd.siamics.net>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<eli$2611290036@qaz.wtf> <wPRxP9j06Ip0AEM2@violet.siamics.net> <eli$2612040037@qaz.wtf>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Ivan Shmakov <ivan@siamics.netREMOVE.invalid> Newsgroups: comp.lang.perl.misc Subject: Re: a question about TUIs and raw input from ttys Date: Sat, 5 Dec 2026 17:25:54 +0000 Organization: Dbus-free station. Lines: 69 Message-ID: <zB_4TNOhVZyRdrnE@niodd.siamics.net> References: <eli$2611290036@qaz.wtf> <wPRxP9j06Ip0AEM2@violet.siamics.net> <eli$2612040037@qaz.wtf> Injection-Date: Sat, 05 Dec 2026 17:45:14 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3290914"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l7toxVKti7geooyL5I1dH"; posting-host="f62950befa4974aebd1eb65403b6ed1d" Cancel-Lock: sha1:7aGbeTCcQc9rqw/nLWLPbgdJDg8= sha256:ohQV/c0DQFx4JL/ydsqXcRTIqA1Ueh+4NM3vJUqO498= sha1:OzakB3BajrlOqJaSjH2mpjmiQOE= sha256:uUc7E7qkzcc8kW2OdE7ucCAaV1aSqeWphYBkfbygg5Y= License: CC-BY-SA-3.0+ (original contributions only)