When I run this script it works as wanted as long as I don't redirect STDOUT
to a file. When I redirect STDOUT
to a file, the output after the ENTER:
breaks. Why doesn't the script work any more if I redirect the STDOUT
to a file?
#!/usr/bin/env perl
use warnings;
use strict;
use Term::ReadKey;
use Unicode::GCString;
use Term::ANSIScreen qw( :all );
select( *STDERR );
$| = 1;
print YELLOW "YELLOW\n";
print RESET;
print "ENTER:";
my $dummy = <>;
print savepos;
my $str = '';
print_readline( $str );
for my $s ( 33 .. 126 ) {
$str .= ' ' . chr( $s ) x 5;
print_readline( $str );
}
print "\n";
sub print_readline {
my ( $str ) = @_;
my $gcs = Unicode::GCString->new( $str );
my $up = int( $gcs->columns() / ( GetTerminalSize )[0] );
print loadpos;
if ( $up ) {
print "\n" x $up, up( $up );
}
print cldown, savepos, $str;
}