<?xml version="1.0" encoding="windows-1252"?>
<node id="996917" title="Re: Eclipse and debug curses" created="2012-10-02 16:52:56" updated="2012-10-02 16:52:56">
<type id="11">
note</type>
<author id="733061">
flexvault</author>
<data>
<field name="doctext">
&lt;p&gt;Welcome &lt;a href="http://www.perlmonks.org/?node_id=983189"&gt;alexx_sh&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;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... 
&lt;code&gt;

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, $allraw);
    $fd_stdin = fileno(STDIN);
    $term     = POSIX::Termios-&gt;new();
    $term-&gt;getattr($fd_stdin);
    $oterm    = $term-&gt;getlflag();
    $echo     = ECHO | ECHOK | ICANON ;
    $noecho   = $oterm &amp; ~$echo;
    $iterm    = $term-&gt;getiflag();
    $raw      = ICRNL;
    $allraw   = $iterm &amp; ~$raw;

    $SIG{INT} = \&amp;TST_INT;

    sub TST_INT
    {    our $Signal++;
        return;
     }

    sub cbreak
        { my $max = shift;
          $term-&gt;setlflag($noecho);
          $term-&gt;setiflag($allraw);
          $term-&gt;setcc(VMIN, 0);
          $term-&gt;setcc(VTIME, $max);
          $term-&gt;setattr($fd_stdin, TCSANOW);
         }
    sub cooked
        { $term-&gt;setlflag($oterm);
          $term-&gt;setiflag($iterm);
          $term-&gt;setcc(VTIME, 1);
          $term-&gt;setattr($fd_stdin, TCSANOW);
         }
    sub getkey
        { my $tm = shift; $key = ""; $chr = "";
          cbreak($tm);
          sysread(STDIN, $chr, 1);
          $term-&gt;setcc(VTIME, 0);
          $term-&gt;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 )&amp;&amp;( ord($key) &lt; 32 ) )
                { if ( substr($key,0,1) eq substr($key,1,1) ) { chop($key); }
                 }
              if ( ( length($key) &gt; 1 )&amp;&amp;( exists $CRTinput{$key} ) )
                {    if ( $Debug &gt;= 3 ) { PEMSG(3,"  GETKEY1:\t|$key|"); } 
                    return $key;
                 }
              if ( $chr ne $TERMCR ) {  sysread(STDIN, $chr, 1); goto GETLOOP; }
              
             }
          if  ( ( $Debug &gt;= 3 )&amp;&amp;( length($key) &gt; 1 ) ) { PEMSG(3,"  GETKEY2:\t|$key|"); }
    #      cooked();
          return $key;
    }
    sub clrkey
        { my $char = "";
          $term-&gt;setlflag($noecho);
          $term-&gt;setiflag($allraw);
          $term-&gt;setcc(VMIN, 0);
          $term-&gt;setcc(VTIME, 0);
          $term-&gt;setattr($fd_stdin, TCSANOW);
          sysread(STDIN, $char, 64);
        }
}
END
 { cooked();
    qx/stty $config/; print "\n\n";
    $|=1;
  }
&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;Using the code in the BEGIN and END blocks allows the terminal to be reset to how we found at exit.&lt;/p&gt;
&lt;p&gt;You get the character from the console/terminal/XTerminal by calling 'getkey();'
like this:
&lt;code&gt;
  $key = getkey(25);
&lt;/code&gt;

&lt;p&gt;Hope this helps!


&lt;/p&gt;
&lt;p&gt;Good Luck!&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-733061"&gt;
&lt;p&gt;&lt;b&gt;"Well done is better than well said." - Benjamin Franklin&lt;/b&gt;&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
996801</field>
<field name="parent_node">
996801</field>
</data>
</node>
