Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Welcome alexx_sh,

I saw your post earlier, and I waited for some more knowledgeable Monk to tell you how to use curses. I haven't had too much luck using Perl curses, but I do have an editor I wrote several years ago that required handling function keys, so this code may be overkill for what you need. This works on AIX and most *nix systems, so test, test, test...

BEGIN { use POSIX qw(:termios_h); use sigtrap qw( INT ); $Signal = 0; our $config = qx/stty -g/; my ($term, $oterm, $echo, $noecho, $fd_stdin, $iterm, $raw, $allra +w); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON ; $noecho = $oterm & ~$echo; $iterm = $term->getiflag(); $raw = ICRNL; $allraw = $iterm & ~$raw; $SIG{INT} = \&TST_INT; sub TST_INT { our $Signal++; return; } sub cbreak { my $max = shift; $term->setlflag($noecho); $term->setiflag($allraw); $term->setcc(VMIN, 0); $term->setcc(VTIME, $max); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setiflag($iterm); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub getkey { my $tm = shift; $key = ""; $chr = ""; cbreak($tm); sysread(STDIN, $chr, 1); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); GETLOOP: #$# Need to test for multiple character Carr Return if ( $er == 22 ) { return(""); } if ( $chr ne "" ) { $key .= $chr; if ( ( length($key) == 2 )&&( ord($key) < 32 ) ) { if ( substr($key,0,1) eq substr($key,1,1) ) { chop($ +key); } } if ( ( length($key) > 1 )&&( exists $CRTinput{$key} ) ) { if ( $Debug >= 3 ) { PEMSG(3," GETKEY1:\t|$key|" +); } return $key; } if ( $chr ne $TERMCR ) { sysread(STDIN, $chr, 1); goto +GETLOOP; } } if ( ( $Debug >= 3 )&&( length($key) > 1 ) ) { PEMSG(3," G +ETKEY2:\t|$key|"); } # cooked(); return $key; } sub clrkey { my $char = ""; $term->setlflag($noecho); $term->setiflag($allraw); $term->setcc(VMIN, 0); $term->setcc(VTIME, 0); $term->setattr($fd_stdin, TCSANOW); sysread(STDIN, $char, 64); } } END { cooked(); qx/stty $config/; print "\n\n"; $|=1; }

Using the code in the BEGIN and END blocks allows the terminal to be reset to how we found at exit.

You get the character from the console/terminal/XTerminal by calling 'getkey();' like this:

$key = getkey(25);

Hope this helps!

Good Luck!

"Well done is better than well said." - Benjamin Franklin


In reply to Re: Eclipse and debug curses by flexvault
in thread Eclipse and debug curses by alexx_sh

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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 romping around the Monastery: (18)
    As of 2015-07-31 17:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (280 votes), past polls