Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: 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:
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.


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.

In reply to Tips and Pointers using ncurses with perl by odie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2014-09-01 22:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (17 votes), past polls