package My_Package; use warnings; use strict; use Term::ReadKey; use constant { HIDE_CURSOR => "\e[?25l", SHOW_CURSOR => "\e[?25h", }; sub init { my $self = bless $_[1], $_[0]; $self->{old_handle} = select( $self->{handle_out} ); $self->{backup_flush} = $|; $| = 1; print HIDE_CURSOR if $self->{hide_cursor}; Term::ReadKey::ReadMode 'ultra-raw'; return $self; } sub DESTROY { my $self = shift; print "\n\r"; Term::ReadKey::ReadMode 'restore'; print SHOW_CURSOR if $self->{hide_cursor}; $| = $self->{backup_flush}; select( $self->{old_handle} ); } sub my_routine { my $arg = shift; $arg->{handle_out} = *STDOUT; local $SIG{'INT'} = sub { my $signame = shift; die "SIG$signame\n"; }; #init_scr( $arg ); my $init = My_Package->init( $arg ); my $s; while ( 1 ) { my $c = ReadKey 0; if ( ! defined $c ) { #end_scr(); warn "EOT\n"; return; } next if $c eq "\e"; if ( $c eq "\cC" ) { #end_scr( $arg ); #print STDERR "^C"; kill( 'INT', $$ ); return; } elsif ( $c eq "\r" ) { #end_scr( $arg ); return $s; } else { $s .= $c; print $c; } } } 1;