From edc47b07696fb56113909fffd0297dbbb6334fc0 Mon Sep 17 00:00:00 2001 From: hpa Date: Fri, 6 Apr 2001 00:06:38 +0000 Subject: [PATCH] Update to skip image file directives (^X...\n) --- sys2ansi.pl | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/sys2ansi.pl b/sys2ansi.pl index d4b47db..7c39e7e 100755 --- a/sys2ansi.pl +++ b/sys2ansi.pl @@ -6,29 +6,40 @@ # @ansicol = (0,4,2,6,1,5,3,7); +$getting_file = 0; + while ( read(STDIN, $ch, 1) > 0 ) { if ( $ch eq "\x1A" ) { # EOF last; } elsif ( $ch eq "\x0C" ) { # Clear screen - print "\x1b[2J"; + print "\x1b[2J" if ( !$getting_file ); } elsif ( $ch eq "\x0F" ) { # Attribute change - if ( read(STDIN, $attr, 2) == 2 ) { - $attr = hex $attr; - print "\x1b[0;"; - if ( $attr & 0x80 ) { - print "5;"; - $attr &= ~0x80; - } - if ( $attr & 0x08 ) { - print "1;"; - $attr &= ~0x08; + if ( !$getting_file ) { + if ( read(STDIN, $attr, 2) == 2 ) { + $attr = hex $attr; + print "\x1b[0;"; + if ( $attr & 0x80 ) { + print "5;"; + $attr &= ~0x80; + } + if ( $attr & 0x08 ) { + print "1;"; + $attr &= ~0x08; + } + printf "%d;%dm", + $ansicol[$attr >> 4] + 40, $ansicol[$attr & 7] + 30; } - printf "%d;%dm", - $ansicol[$attr >> 4] + 40, $ansicol[$attr & 7] + 30; } + } elsif ( $ch eq "\x18" ) { # Display image + # We can't display an image; pretend to be a text screen + # Ignore all input until end of line + $getting_file = 1; } elsif ( $ch eq "\x0D" ) { # Carriage return # Ignore - } else { + } elsif ( $ch eq "\x0A" ) { # Line feed + $getting_file = 0; print $ch; + } else { + print $ch if ( !$getting_file ); } } -- 2.7.4