From e231c8772b594dce52514882b549f412638585a2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 26 Jun 2014 20:55:49 -0400 Subject: chroot-tools/indent: fix issue 563 That is, lines wider than the terminal window got mangled. --- src/chroot-tools/indent | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/chroot-tools/indent b/src/chroot-tools/indent index ffec4d5..9a6247f 100755 --- a/src/chroot-tools/indent +++ b/src/chroot-tools/indent @@ -20,6 +20,7 @@ use warnings; use strict; + use constant BUFFER_SIZE => 40; binmode(STDIN); binmode(STDOUT); @@ -27,7 +28,11 @@ binmode(STDOUT); exit(1) if ($#ARGV != 0); my $indent = $ARGV[0]; -my $print_indent = 1; +# 0: no indent has been printed for this line, an indent WILL need to be printed +# 1: an indent needs to be printed for this line IFF there is any more output on it +# 2: no indent (currently) needs to be printed for this line +my $print_indent = 0; + my $buffer; my $size; my $c; @@ -37,16 +42,16 @@ while (1) { for (0..$size-1) { $c = substr($buffer, $_, 1); if ($c eq "\n") { - syswrite(STDOUT, $indent) if ($print_indent); + syswrite(STDOUT, $indent) if ($print_indent == 0); syswrite(STDOUT, $c, 1); - $print_indent = 1; + $print_indent = 0; } elsif ($c eq "\r") { syswrite(STDOUT, $c, 1); $print_indent = 1; } else { - syswrite(STDOUT, $indent) if ($print_indent); + syswrite(STDOUT, $indent) if ($print_indent < 2); syswrite(STDOUT, $c, 1); - $print_indent = 0; + $print_indent = 2; } } } -- cgit v1.2.2