Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Eclipse and debug curses

by flexvault (Prior)
on Oct 02, 2012 at 20:52 UTC ( #996917=note: print w/ replies, xml ) Need Help??


in reply to Eclipse and debug curses

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


Comment on Re: Eclipse and debug curses
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996917]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-07-03 17:20 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 (54 votes), past polls