Think about Loose Coupling | |
PerlMonks |
Tips and Pointers using ncurses with perlby odie (Sexton) |
on Sep 12, 2000 at 22:23 UTC ( [id://32154]=perltutorial: print w/replies, xml ) | Need Help?? |
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. 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". 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:
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. 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. =) 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.
Back to
Tutorials
|
|