As some of you know, TRPlayer currently uses the slang library to get
keyboard input from the user. This allowed me to implement keyboard
commands, including use of the cursor keys, relatively quickly, but there
are some problems:
1. On some systems (especially non-Linux systems), slang is a non-standard
library, one more thing for the user to install.
2. slang assumes that the terminal is VT100-compatible and therefore uses
hard-coded escape sequences instead of termcap or terminfo. This point may
be irrelevant if everyone is using a VT100-compatible terminal now.
3. When waiting for the characters in the escape sequence for an extended
key, slang has no timeout. In particular, this means that if you press
escape while TRPlayer is running, slang will wait for the next character,
the audio buffer will become empty, and the audio will stop until you press
another key. TRPlayer should beep instead.
4. slang reads its input directly from the terminal device (possibly
through /dev/tty), not from standard input. This means that even if you
redirect standard input to another device or file, slang reads from the
terminal on which the process started. TRPlayer works around this by
running in line mode (not using slang at all) when it notices that standard
input isn't a terminal. This allows TRPlayer to get its commands from
another process or file. This approach would backfire, though, if standard
input is redirected to another terminal. TRPlayer also has a
non-interactive mode which is turned on using the -n option.
The first alternative to slang that comes to mind is ncurses. In fact, I
looked at this before I chose to use slang. The problem with ncurses is
that the keyboard input functions are closely tied to the screen output
system. Whenever you call the getch or wgetch function in ncurses, it
refreshes the screen. So if I call getch or wgetch just after calling
initscr, ncurses will clear the screen, and I'll probably have to use
ncurses' screen output routines to output to the screen. I wanted the
output of TRPlayer to remain line-oriented, and I didn't want it to
automatically clear the screen. But these are just my preferences, and if
others think the ncurses library would be the best solution, that's what
I'll use.
The other alternative that comes to mind is to write one's own keyboard
input code. This code must be able to handle cursor movement keys, should
read from standard input, and should have a timeout feature as ncurses does.
Termcap/terminfo support would also be a good idea, though I suppose it's
not required. This would automatically solve problem #1, at the expense of
making TRPlayer larger.
What do you all think would be the best way to go here?
--
Matt Campbell <http://www.pobox.com/~mattcampbell/> ICQ #: 33005941