perltutorial
odie
I just started out with ncurses for the first time. It is
hard enough to use the manuals/tutorials written for C. To
make it worse, some functions have been renamed or might
simply be nonexistant. I have only scratched the surface of
the ncurses module, but I have a few pointers, that will
save the ones new to CPANs Curses module some time.<BR><BR>
1) The functions to read from STDIN are (as usual) blocking.
This means, the program will halt on fx. getch() until
input is recieved. There are a few ways to make it nonblocking
according to the manual. I have found only one that does
not cause problems: Use the function halfdelay(ms). The
function will wait for ms milliseconds on a getch(), and
if no input is recieved, getch() will return "-1".<BR><BR>
2) To use color, simply use start_color and define a few
color pairs with the function init_pair(pairnr, fg, bg)
where fg is the foreground and bg is background. Colors are
from 0 to 7. (Black, Red, Green, Yellow, Blue, Magenta, Cyan,
White). To use the colors, I have found only two supported
functions: attron(ATTR) and attroff(ATTR). "man attr" will
show what attributes can be toggled with the functions. To
print a line in green, on yellow, you simply use the ATTR COLOR_PAIR(n). Do like this:
<CODE>init_pair(1,2,3); # Initiate pair. Pair 0 reserved for mono.
attron(COLOR_PAIR(2)); # Start color.
addstr(15, 30, "MOOOO!");# print string at 30,15. Always use (y,x).
attroff(COLOR_PAIR(2)); # End color.</CODE><BR><BR>
3) The above is also a good example for this point: Some
functions have been slightly renamed. attron/attroff is
named attr_on/attr_off in C and therefore in all manuals. This can make it difficult to find
the correct manpages.<BR><BR>
4) I am still looking for a way to hide the cursor. The C
man pages have the function curs_set(<mode>). Unfortunately
the CPAN Curses seems unable to support this. If anyone finds
a way, please let me know. =)<BR><BR>
As I said, I barely even scratched ncurses surface, but I
hope this will save the ones new to both ncurses and C ( like
me ) a few hours of agony.