willett wrote:
Advice sought on terminal input to a gpc program:
I'm trying to read character at a time from the terminal, to allow my program to respond to each keystroke when typed. Also, I don't want to hang waiting for input if nothing has been typed.
Thus I'm using IOSelectRead with a timeout. (excessive timeout, below, just for testing.) My test program below works, but keyboard typing is line buffered, that is, it doesn't know the user has typed anything (returns with SelectValue=1) unless a Return has been typed.
I don't want to use the CRT unit, because that disturbs terminal's processing of escape sequences, e.g. for VT102 ANSI sequences.
Not really disturbs. It interprets them and returns key codes for them (on input) or converts screen drawing to the sequences (on output).
(Incidentally, I'm running on Macintosh OSX, using terminal.
Are you sure your program will always run on this terminal? Not perhaps sometime on another machine, or just another terminal via ssh or so? Then CRT's (actually ncurses's) escape sequence interpretation may be beneficial.
But this question should be generic GPC/Unix.)
Generic Unix. Terminals by default do line buffering themselves (this is useful, so if the user types abd<backspace>c<enter>, a program that just does `ReadLn' etc. gets `abc' as expected).
If you really don't want to use CRT, you might have to do it yourself (probably in C, using a Pascal interface), see termios.
As for not waiting, IOSelectRead is correct.
Frank