[svlug] Extended Keyboard Input Utility For Bash?
Tim Utschig
tim at tetro.net
Mon Mar 26 22:58:42 PDT 2007
On Mon, Mar 26, 2007 at 01:36:45PM -0700, Mark S Bilk wrote:
>
> In SuSE 9.3 it needs -lncurses for compiling.
libcurses is just symlink to libncurses on my system, so I guess that's
why -lcurses works.
> When I run it, it blanks the entire konsole or xterm window until I
> type the key, so I lose the context of whatever's been output to the
> screen while deciding what to type. Does this not happen on your
> system?
I should have described the environment I tested it with...
- Ubuntu 6.10 "Edgy" i386
- ncurses version 5.5-2ubuntu1
- Terminal emulators tested: gnome-terminal, linux console
I tested it in xterm just now and saw the behavior you described. Must
be some difference in the handling of the ncurses initialization since
gnome-terminal uses TERM=xterm. I'll try some more things with ncurses
next time I have some free time.
> I tried putting a select() call in the code before yours, to wait
> until the key is pressed, which stopped the blanking, but then it
> only gets the first byte of keypad escape sequences and only outputs
> "^[".
So it didn't wait for a key to be pressed before adding select?
getch() should block by default...
> Also, with the select call I have to press Enter to get it to accept
> whatever I type. So I inserted code to set the terminal to raw mode
> before the select (see below), which eliminates the need to press
> Enter, but it's still only putting out ^[ for keypad keys (except
> PgUp and PgDn).
I don't think you need raw mode. "man 3 raw" says it's just like cbreak
except characters that would normally generate signals are passed
through.
> Commenting out the dup and dup2 calls (which I don't understand) and
> calling it directly from the command line doesn't help.
I added the dup/dup2 calls since if you call the program from a script
using backticks, stdout won't be the tty and curses will fail to
initialize properly. stderr is an open file descriptor for the tty, and
is passed by the shell to the program unchanged, so I used it to set
stdout back to the tty during the curses calls.
--
- Tim Utschig <tim at tetro.net>
More information about the Svlug
mailing list