Subject: | After using Roguelike::Console, terminal keys don't show up |
After creating a Console object:
my $con = Games::Roguelike::Console->new;
When my Perl script ends, the terminal doesn't display my typed keys.
Analysis
Apparently, Console and/or Curses set the tty to -echo, which hides my keys.
Solution
Initializing the console messes up any signal handlers I've set up, so I just call reset_signals
after that.
The stty command is the key (pun intended) to displaying keys again.
sub reset_signals {
$SIG{INT} = sub {
undef $con;
# Allow terminal echo
if ($^O =~ /linux|darwin/) {
my $tty = POSIX::ttyname(1);
system "stty -f $tty icanon echo";
}
exit 0;
};
}
sub main {
$con = Games::Roguelike::Console::ANSI->new;
reset_signals;
# ...
}
Conclusion
Could you put the critical portions of reset_signals in Console's SIGINT handler?
Also, could you figure out the equivalent fix for Windows? stty is a Unix command.
Specs:
Roguelike::Console 0.4.256
Perl 5.10.0
Mac OS X 10.6.6
Cheers,
Andrew Pennebaker
http://www.yellosoft.us/