Thread END Block innerhalb einer Subroutine
(11 answers)
Opened by Kuerbis at 2013-05-09 18:04
Das scheint zu funktionieren. Ist das so in Ordnung?
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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; |