[poe-commits] poe/POE/Wheel ReadLine.pm,1.24,1.25
Brought to you by:
rcaputo
From: <rc...@us...> - 2002-11-19 18:44:08
|
Update of /cvsroot/poe/poe/POE/Wheel In directory sc8-pr-cvs1:/tmp/cvs-serv23477/POE/Wheel Modified Files: ReadLine.pm Log Message: Support le and ri in addition to LE and RI. We'll need to support Term::Info (or the moral equivalent) also, because many operating systems don't deign to include termcap. Bleah. Index: ReadLine.pm =================================================================== RCS file: /cvsroot/poe/poe/POE/Wheel/ReadLine.pm,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ReadLine.pm 26 Oct 2002 11:59:39 -0000 1.24 --- ReadLine.pm 19 Nov 2002 18:44:05 -0000 1.25 *************** *** 59,63 **** #------------------------------------------------------------------------------ - # Helper functions. # Build a hash of input characters and their "normalized" display --- 59,62 ---- *************** *** 83,87 **** } ! # Wipe the current input line. sub wipe_input_line { my %args = @_; --- 82,185 ---- } ! #------------------------------------------------------------------------------ ! # Gather information about the user's terminal. This just keeps ! # getting uglier. ! ! # Get the terminal speed for Term::Cap. ! my $ospeed = B38400; ! eval { ! my $termios = POSIX::Termios->new(); ! $termios->getattr(); ! $ospeed = $termios->getospeed() || B38400; ! }; ! ! # Get the current terminal's capabilities. ! my $term = $ENV{TERM} || 'vt100'; ! $termcap = Term::Cap->Tgetent( { TERM => $term, OSPEED => $ospeed } ); ! die "could not find termcap entry for ``$term'': $!" unless defined $termcap; ! ! # Require certain capabilites. ! $termcap->Trequire( qw( cl ku kd kl kr ) ); ! ! # Cursor movement. ! my $tc_left = "LE"; ! eval { $termcap->Trequire($tc_left) }; ! if ($@) { ! $tc_left = "le"; ! eval { $termcap->Trequire($tc_left) }; ! die "POE::Wheel::ReadLine requires a termcap that supports LE or le"; ! } ! ! my $tc_right = "RI"; ! eval { $termcap->Trequire($tc_right) }; ! if ($@) { ! $tc_right = "ri"; ! eval { $termcap->Trequire($tc_right) }; ! die "POE::Wheel::ReadLine requires a termcap that supports RI or ri"; ! } ! ! sub curs_move { ! my ($dir, $amount) = @_; ! ! if ($dir eq uc($dir)) { ! $termcap->Tgoto($dir, 1, $amount, $stdout); ! return; ! } ! ! for (1..$amount) { ! $termcap->Tgoto($dir, 1, 1, $stdout); ! } ! } ! ! # Some things are optional. ! eval { $termcap->Trequire( 'kE' ) }; ! $tc_has_ke = 1 unless $@; ! ! # o/` You can ring my bell, ring my bell. o/` ! my $bell = $termcap->Tputs( bl => 1 ); ! $bell = $termcap->Tputs( vb => 1 ) unless defined $bell; ! $tc_bell = (defined $bell) ? $bell : ''; ! ! # Arrow keys. These are required. ! $tck_up = preprocess_keystroke( 'ku' ); ! $tck_down = preprocess_keystroke( 'kd' ); ! $tck_left = preprocess_keystroke( 'kl' ); ! $tck_right = preprocess_keystroke( 'kr' ); ! ! # Insert key. ! eval { $termcap->Trequire( 'kI' ) }; ! if ($@) { $tck_insert = ''; } ! else { $tck_insert = preprocess_keystroke( 'kI' ); } ! ! # Delete key. ! eval { $termcap->Trequire( 'kD' ) }; ! if ($@) { $tck_delete = ''; } ! else { $tck_delete = preprocess_keystroke( 'kD' ); } ! ! # Home key. ! eval { $termcap->Trequire( 'kh' ) }; ! if ($@) { $tck_home = ''; } ! else { $tck_home = preprocess_keystroke( 'kh' ); } ! ! # End key. ! eval { $termcap->Trequire( 'kH' ) }; ! if ($@) { $tck_end = ''; } ! else { $tck_end = preprocess_keystroke( 'kH' ); } ! ! # Backspace key. ! eval { $termcap->Trequire( 'kb' ) }; ! if ($@) { $tck_backspace = ''; } ! else { $tck_backspace = preprocess_keystroke( 'kb' ); } ! ! # Terminal size. ! ($trk_cols, $trk_rows) = Term::ReadKey::GetTerminalSize($stdout); ! ! # Esc is the generic meta prefix. ! $meta_prefix{chr(27)} = 1; ! ! #------------------------------------------------------------------------------ ! # Helper functions. ! ! # Wipe the current input line. sub wipe_input_line { my %args = @_; *************** *** 89,104 **** # Clear the current prompt and input, and home the cursor. ! print $stdout $args{termcap}->Tgoto( 'LE', 1, ! ( ${ $args{self_cursor_display} } + length( ${ $args{self_prompt} } ) ) ! ); if ( $args{tc_has_ke} ) { print $stdout $args{termcap}->Tputs( 'kE', 1 ); } else { ! $args{wipe_length} = ! length( ${ $args{self_prompt} } ) + ! display_width( ${ $args{self_input} } ); ! print( $stdout ( ' ' x $args{wipe_length} ), ! $args{termcap}->Tgoto( 'LE', 1, $args{wipe_length} ) ); } } --- 187,204 ---- # Clear the current prompt and input, and home the cursor. ! curs_move( $tc_left, ! ( $ { $args{self_cursor_display} } + ! length( ${ $args{self_prompt} } ) ! ) ! ); if ( $args{tc_has_ke} ) { print $stdout $args{termcap}->Tputs( 'kE', 1 ); } else { ! $args{wipe_length} = ! length( $ { $args{self_prompt} } ) + ! display_width( $ { $args{self_input} } ); ! print $stdout ( ' ' x $args{wipe_length} ); ! curs_move($tc_left, $args{wipe_length}); } } *************** *** 123,138 **** my %args = @_; my $stdout = $args{stdout}; ! print( $stdout ${ $args{self_prompt} }, ! normalize( ${ $args{self_input} } ) ); ! if ( ${ $args{self_cursor_input} } != length( ${ $args{self_input} } ) ) { ! $args{termcap}->Tgoto( ! 'LE', 1, ! ( ! display_width( ${ $args{self_input} } ) - ! ${ $args{self_cursor_display} } ! ), ! $stdout ! ); } } --- 223,237 ---- my %args = @_; my $stdout = $args{stdout}; ! print( $stdout $ { $args{self_prompt} }, ! normalize( $ { $args{self_input} } ) ); ! if ( $ { $args{self_cursor_input} } != ! length( $ { $args{self_input} } ) ! ) { ! curs_move( $tc_left, ! ( display_width( $ { $args{self_input} } ) - ! $ { $args{self_cursor_display} } ! ) ! ); } } *************** *** 181,246 **** } - # Get the terminal speed for Term::Cap. - my $ospeed = B38400; - eval { - my $termios = POSIX::Termios->new(); - $termios->getattr(); - $ospeed = $termios->getospeed() || B38400; - }; - - # Get the current terminal's capabilities. - my $term = $ENV{TERM} || 'vt100'; - $termcap = Term::Cap->Tgetent( { TERM => $term, OSPEED => $ospeed } ); - die "could not find termcap entry for ``$term'': $!" unless defined $termcap; - - # Require certain capabilites. - $termcap->Trequire( qw( LE RI cl ku kd kl kr ) ); - - # Some things are optional. - eval { $termcap->Trequire( 'kE' ) }; - $tc_has_ke = 1 unless $@; - - # o/` You can ring my bell, ring my bell. o/` - my $bell = $termcap->Tputs( bl => 1 ); - $bell = $termcap->Tputs( vb => 1 ) unless defined $bell; - $tc_bell = (defined $bell) ? $bell : ''; - - # Arrow keys. These are required. - $tck_up = preprocess_keystroke( 'ku' ); - $tck_down = preprocess_keystroke( 'kd' ); - $tck_left = preprocess_keystroke( 'kl' ); - $tck_right = preprocess_keystroke( 'kr' ); - - # Insert key. - eval { $termcap->Trequire( 'kI' ) }; - if ($@) { $tck_insert = ''; } - else { $tck_insert = preprocess_keystroke( 'kI' ); } - - # Delete key. - eval { $termcap->Trequire( 'kD' ) }; - if ($@) { $tck_delete = ''; } - else { $tck_delete = preprocess_keystroke( 'kD' ); } - - # Home key. - eval { $termcap->Trequire( 'kh' ) }; - if ($@) { $tck_home = ''; } - else { $tck_home = preprocess_keystroke( 'kh' ); } - - # End key. - eval { $termcap->Trequire( 'kH' ) }; - if ($@) { $tck_end = ''; } - else { $tck_end = preprocess_keystroke( 'kH' ); } - - # Backspace key. - eval { $termcap->Trequire( 'kb' ) }; - if ($@) { $tck_backspace = ''; } - else { $tck_backspace = preprocess_keystroke( 'kb' ); } - - # Terminal size. - ($trk_cols, $trk_rows) = Term::ReadKey::GetTerminalSize($stdout); - - # Esc is the generic meta prefix. - $meta_prefix{chr(27)} = 1; - #------------------------------------------------------------------------------ # The methods themselves. --- 280,283 ---- *************** *** 358,362 **** if (@$self_put_buffer) { ! wipe_input_line( self_cursor_display => $self_cursor_display, self_input => $self_input, --- 395,399 ---- if (@$self_put_buffer) { ! wipe_input_line( self_cursor_display => $self_cursor_display, self_input => $self_input, *************** *** 365,382 **** tc_has_ke => $tc_has_ke, termcap => $termcap, ! ); ! flush_output_buffer( self_put_buffer => $self_put_buffer, stdout => $stdout, ! ## Please see file perltidy.ERR ! ); ! repaint_input_line( ! self_cursor_input => $self_cursor_input, ! self_input => $self_input, ! self_prompt => $self_prompt, ! stdout => $stdout, ! termcap => $termcap, ! ); ! } --- 402,418 ---- tc_has_ke => $tc_has_ke, termcap => $termcap, ! ); ! flush_output_buffer( self_put_buffer => $self_put_buffer, stdout => $stdout, ! ); ! repaint_input_line( ! self_cursor_display => $self_cursor_display, ! self_cursor_input => $self_cursor_input, ! self_input => $self_input, ! self_prompt => $self_prompt, ! stdout => $stdout, ! termcap => $termcap, ! ); } *************** *** 460,464 **** if ( $key eq '^A' or $key eq $tck_home ) { if ($$cursor_input) { ! $termcap->Tgoto( 'LE', 1, $$cursor_display, $stdout ); $$cursor_display = $$cursor_input = 0; } --- 496,500 ---- if ( $key eq '^A' or $key eq $tck_home ) { if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); $$cursor_display = $$cursor_input = 0; } *************** *** 474,478 **** $$cursor_input--; my $left = display_width(substr($$input, $$cursor_input, 1)); ! $termcap->Tgoto( 'LE', 1, $left, $stdout ); $$cursor_display -= $left; } --- 510,514 ---- $$cursor_input--; my $left = display_width(substr($$input, $$cursor_input, 1)); ! curs_move($tc_left, $left); $$cursor_display -= $left; } *************** *** 515,519 **** ); print $stdout $normal; ! $termcap->Tgoto( 'LE', 1, length($normal), $stdout ); } else { --- 551,555 ---- ); print $stdout $normal; ! curs_move($tc_left, length($normal)); } else { *************** *** 527,531 **** if ($$cursor_input < length($$input)) { my $right = display_width(substr($$input, $$cursor_input)); ! $termcap->Tgoto( 'RI', 1, $right, $stdout ); $$cursor_display += $right; $$cursor_input = length($$input); --- 563,567 ---- if ($$cursor_input < length($$input)) { my $right = display_width(substr($$input, $$cursor_input)); ! curs_move($tc_right, $right); $$cursor_display += $right; $$cursor_input = length($$input); *************** *** 580,584 **** display_width(substr($$input, $$cursor_input, 1)); substr($$input, $$cursor_input, 1) = ''; ! $termcap->Tgoto( 'LE', 1, $left, $stdout ); my $normal = ( normalize(substr($$input, $$cursor_input)) . --- 616,620 ---- display_width(substr($$input, $$cursor_input, 1)); substr($$input, $$cursor_input, 1) = ''; ! curs_move($tc_left, $left); my $normal = ( normalize(substr($$input, $$cursor_input)) . *************** *** 586,590 **** ); print $stdout $normal; ! $termcap->Tgoto( 'LE', 1, length($normal), $stdout ); $$cursor_display -= $kill_width; } --- 622,626 ---- ); print $stdout $normal; ! curs_move($tc_left, length($normal)); $$cursor_display -= $kill_width; } *************** *** 621,627 **** substr( $$input, $$cursor_input ) = ''; print( $stdout ! (" " x $kill_width), ! $termcap->Tgoto( 'LE', 1, $kill_width ) ); } else { --- 657,663 ---- substr( $$input, $$cursor_input ) = ''; print( $stdout ! (" " x $kill_width) ); + curs_move($tc_left, $kill_width); } else { *************** *** 636,640 **** $termcap->Tputs( 'cl', 1, $stdout ); print $stdout $$prompt, normalize($$input); ! $termcap->Tgoto( 'LE', 1, $left, $stdout ) if $left; next; } --- 672,676 ---- $termcap->Tputs( 'cl', 1, $stdout ); print $stdout $$prompt, normalize($$input); ! curs_move($tc_left, $left) if $left; next; } *************** *** 669,675 **** substr($$input, $$cursor_input - 1, 2) = $transposition; ! $termcap->Tgoto( 'LE', 1, $width_left, $stdout ); print $stdout normalize($transposition); ! $termcap->Tgoto( 'LE', 1, $width_left, $stdout ); } else { --- 705,711 ---- substr($$input, $$cursor_input - 1, 2) = $transposition; ! curs_move($tc_left, $width_left); print $stdout normalize($transposition); ! curs_move($tc_left, $width_left); } else { *************** *** 685,689 **** # Back up to the beginning of the line. if ($$cursor_input) { ! print $stdout $termcap->Tgoto( 'LE', 1, $$cursor_display ); $$cursor_display = $$cursor_input = 0; } --- 721,725 ---- # Back up to the beginning of the line. if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); $$cursor_display = $$cursor_input = 0; } *************** *** 696,700 **** my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } --- 732,736 ---- my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! curs_move($tc_left, $display_width); } *************** *** 718,722 **** # Back up the screen cursor; show the line's tail. my $delete_width = display_width($1); ! $termcap->Tgoto( 'LE', 1, $delete_width, $stdout ); print $stdout normalize(substr( $$input, $$cursor_input )); --- 754,758 ---- # Back up the screen cursor; show the line's tail. my $delete_width = display_width($1); ! curs_move($tc_left, $delete_width); print $stdout normalize(substr( $$input, $$cursor_input )); *************** *** 727,731 **** else { print $stdout ' ' x $delete_width; ! $termcap->Tgoto( 'LE', 1, $delete_width, $stdout ); } --- 763,767 ---- else { print $stdout ' ' x $delete_width; ! curs_move($tc_left, $delete_width); } *************** *** 734,738 **** my $display_width = display_width( substr($$input, $$cursor_input) ); ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } } --- 770,774 ---- my $display_width = display_width( substr($$input, $$cursor_input) ); ! curs_move($tc_left, $display_width); } } *************** *** 755,759 **** # Move cursor to start of input. if ($$cursor_input) { ! $termcap->Tgoto( 'LE', 1, $$cursor_display, $stdout ); } --- 791,795 ---- # Move cursor to start of input. if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); } *************** *** 766,770 **** my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } } --- 802,806 ---- my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! curs_move($tc_left, $display_width); } } *************** *** 792,796 **** # Move cursor to start of input. if ($$cursor_input) { ! $termcap->Tgoto( 'LE', 1, $$cursor_display, $stdout ); } --- 828,832 ---- # Move cursor to start of input. if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); } *************** *** 803,807 **** my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } } --- 839,843 ---- my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! curs_move($tc_left, $display_width); } } *************** *** 841,845 **** # Move cursor to start of input. if ($$cursor_input) { ! $termcap->Tgoto( 'LE', 1, $$cursor_display, $stdout ); } --- 877,881 ---- # Move cursor to start of input. if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); } *************** *** 852,856 **** my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } } --- 888,892 ---- my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! curs_move($tc_left, $display_width); } } *************** *** 883,887 **** # Move cursor to start of input. if ($$cursor_input) { ! $termcap->Tgoto( 'LE', 1, $$cursor_display, $stdout ); } --- 919,923 ---- # Move cursor to start of input. if ($$cursor_input) { ! curs_move($tc_left, $$cursor_display); } *************** *** 894,898 **** my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! $termcap->Tgoto( 'LE', 1, $display_width, $stdout ); } } --- 930,934 ---- my $display_width = display_width($$input); print $stdout ' ' x $display_width; ! curs_move($tc_left, $display_width); } } *************** *** 981,985 **** $$cursor_input += length($1); my $right = display_width($1); ! $termcap->Tgoto( 'RI', 1, $right, $stdout ); $$cursor_display += $right; } --- 1017,1021 ---- $$cursor_input += length($1); my $right = display_width($1); ! curs_move($tc_right, $right); $$cursor_display += $right; } *************** *** 1009,1013 **** } ! $termcap->Tgoto( 'LE', 1, $normal_remaining_length, $stdout ) if $normal_remaining_length; } --- 1045,1049 ---- } ! curs_move($tc_left, $normal_remaining_length) if $normal_remaining_length; } *************** *** 1023,1027 **** $$cursor_input -= length($1); my $kill_width = display_width($1); ! $termcap->Tgoto( 'LE', 1, $kill_width, $stdout ); $$cursor_display -= $kill_width; } --- 1059,1063 ---- $$cursor_input -= length($1); my $kill_width = display_width($1); ! curs_move($tc_left, $kill_width); $$cursor_display -= $kill_width; } *************** *** 1082,1089 **** if ($$cursor_display - display_width($previous)) { ! $termcap->Tgoto( 'LE', 1, ! $$cursor_display - display_width($previous), ! $stdout ! ); } print $stdout normalize($right . $space . $left); --- 1118,1124 ---- if ($$cursor_display - display_width($previous)) { ! curs_move( $tc_left, ! $$cursor_display - display_width($previous) ! ); } print $stdout normalize($right . $space . $left); *************** *** 1112,1116 **** $$prompt, normalize($$input) ); ! $termcap->Tgoto( 'LE', 1, $left, $stdout ) if $left; next; } --- 1147,1151 ---- $$prompt, normalize($$input) ); ! curs_move($tc_left, $left) if $left; next; } *************** *** 1136,1140 **** $$cursor_input += length($raw_key); $$cursor_display += length($key); ! $termcap->Tgoto( 'LE', 1, length($normal), $stdout ); } else { --- 1171,1175 ---- $$cursor_input += length($raw_key); $$cursor_display += length($key); ! curs_move($tc_left, length($normal)); } else { *************** *** 1158,1162 **** } print $stdout $rest; ! $termcap->Tgoto( 'LE', 1, length($rest), $stdout ); } } --- 1193,1197 ---- } print $stdout $rest; ! curs_move($tc_left, length($rest)); } } *************** *** 1252,1260 **** if ($self->[SELF_READING_LINE]) { repaint_input_line( ! self_cursor_input => $self_cursor_input, ! self_input => $self_input, ! self_prompt => $self_prompt, ! stdout => $stdout, ! termcap => $termcap, ); --- 1287,1296 ---- if ($self->[SELF_READING_LINE]) { repaint_input_line( ! self_cursor_display => $self_cursor_display, ! self_cursor_input => $self_cursor_input, ! self_input => $self_input, ! self_prompt => $self_prompt, ! stdout => $stdout, ! termcap => $termcap, ); |