[Israel.pm] Simple terminal manipulation

Madani, Srikanth, VF-DE Srikanth.Madani at vodafone.com
Thu Feb 2 06:51:16 PST 2006


> More complicated - use "Term::ANSIScreen", 

Thanks - that works fine, using the inherited functions savepos, loadpos
and cldown.

Here's snipped sample code:

__BEGIN__

use Term::ANSIScreen qw/:color :cursor :screen :keyboard/;

my $llf = 0; 
# Length (size in bytes, see caveat below) of the last fortune message

savepos; 
# Save cursor position
foreach (1..$counter) {
        my $lf = length( my $fortune = qx($fortune_program) ); 
	  # Length (size in bytes) of the current fortune message
        
	  $fortune .= " " x ($llf - $lf) if ($lf < $llf); 
	  # Pad blanks at the end if required
        
	  print $fortune;
        
	  sleep ( ($lf < 120) ? 2 : int($lf/40) ); 
	  # Give reader time to read
        
	  loadpos; 
	  # Load values from previously saved cursor position
        
	  cldown;  
	  # Delete lines below current cursor position
        
	  $llf = $lf;
}

__END__

If you're working with Unicode, then I guess you need to change the
length call to something like:

	do { use bytes; length(EXPR) }

as suggested by perldoc -f length.


Best regards,
Srikanth Madani

Dying is a wild night and a new road.
        -- Emily Dickinson




More information about the Perl mailing list