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

Eclipse and debug curses

by alexx_sh (Novice)
on Oct 02, 2012 at 05:38 UTC ( #996801=perlquestion: print w/replies, xml ) Need Help??
alexx_sh has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I try debug curses program in eclipse. I need to run getch() in non-blocking mode. Eclipse console ugly, doesn't support many esc code and non-blocking mode for read key.
#!/usr/bin/env perl use Curses; my $win = Curses->new or die "Can't get new window\n"; initscr(); noecho(); raw(); nodelay(1); $win->keypad(1); $win->addstr ("Try press key\n") while ((my $key = $win->getch()) ne ERR) { $win->addstr ("key $key\n"); #<-breackpoint }
If i try run this code with redirect console to /dev/pty/1 in eclipse debugger configuration. When i press key in /dev/pty/1 breackpoint doen't work and i can't see text. How setup eclipse to redirect stdin from /dev/pty/1 or maybe you can give me anower way to debug code with curses.

Replies are listed 'Best First'.
Re: Eclipse and debug curses
by flexvault (Monsignor) on Oct 02, 2012 at 20:52 UTC

    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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://996801]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-06-20 06:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.