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.
---------------------- program ios (input,output); import GPC; var SelectValue: Integer; microsec: Integer; SelectInput: array [1 .. 1] of PAnyFile = (@Input); begin SelectValue := IOSelectRead (SelectInput, 2000000); writeln('selectvalue=', SelectValue:5); end. ----------------------
I don't want to use the CRT unit, because that disturbs terminal's processing of escape sequences, e.g. for VT102 ANSI sequences. (Incidentally, I'm running on Macintosh OSX, using terminal. But this question should be generic GPC/Unix.)
How do I get 'input' to not line buffer? Or do I use another file? Or change the handle?
Thanks,
Willett Kempton Visible Software