diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-06-26 20:55:49 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-06-26 20:55:49 -0400 |
commit | e231c8772b594dce52514882b549f412638585a2 (patch) | |
tree | 60fb76560989cab68bb363c43ed551d7362ab803 /src/chroot-tools | |
parent | 5c7b1e03c1a9a3405608a78c11823048a3f3ea2f (diff) |
chroot-tools/indent: fix issue 563
That is, lines wider than the terminal window got mangled.
Diffstat (limited to 'src/chroot-tools')
-rwxr-xr-x | src/chroot-tools/indent | 15 |
1 files 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; } } } |