aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--colorize.c8
-rwxr-xr-xtest.pl19
2 files changed, 24 insertions, 3 deletions
diff --git a/colorize.c b/colorize.c
index 3da2b6c..eb8f7c0 100644
--- a/colorize.c
+++ b/colorize.c
@@ -74,6 +74,7 @@
#define LF 0x01
#define CR 0x02
+#define PARTIAL 0x04
#define COUNT_OF(obj, type) (sizeof (obj) / sizeof (type))
@@ -1376,13 +1377,15 @@ read_print_stream (const char *attr, const struct color **colors, const char *fi
if (feof (stream))
{
if (*line != '\0')
- print_line (attr, colors, line, 0, true);
+ print_line (attr, colors, line, PARTIAL, true);
}
else if (*line != '\0')
{
char *p;
if ((clean || clean_all) && (p = strrchr (line, '\033')))
merge_print_line (line, p, stream);
+ else if (rainbow_fg || rainbow_bg)
+ print_line (attr, colors, line, PARTIAL, true);
else
print_line (attr, colors, line, 0, true);
}
@@ -1625,7 +1628,8 @@ print_line (const char *attr, const struct color **colors, const char *const lin
colors[color_iter] = (struct color *)&tables[color_iter].entries[index];
- rainbow_index = index + 1;
+ if (!(flags & PARTIAL))
+ rainbow_index = index + 1;
}
/* Foreground color code is guaranteed to be set when background color code is present. */
diff --git a/test.pl b/test.pl
index 8294e8f..375df03 100755
--- a/test.pl
+++ b/test.pl
@@ -13,7 +13,7 @@ use Getopt::Long qw(:config no_auto_abbrev no_ignore_case);
use Test::Harness qw(runtests);
use Test::More;
-my $tests = 36;
+my $tests = 38;
my $valgrind_cmd = '';
{
@@ -135,6 +135,23 @@ SKIP: {
is_deeply([split /\n/, qx(cat $infile2 | $valgrind_cmd$program none/none)], [split /\n/, $repeated], "read ${\length $repeated} bytes (BUF_SIZE=$BUF_SIZE{normal})");
+ SKIP: {
+ my $program_buf = tmpnam();
+ skip 'compiling failed (short buffer)', 2 unless system("$compiler -DTEST -DBUF_SIZE=$BUF_SIZE{short} -o $program_buf $source") == 0;
+
+ my $short_text = 'foo bar baz' x 2;
+
+ is(qx(printf %s "$short_text" | $valgrind_cmd$program_buf blue --rainbow-fg),
+ "\e[34mfoo bar ba\e[0m\e[34mzfoo bar b\e[0m\e[34maz\e[0m",
+ "partial line (BUF_SIZE=$BUF_SIZE{short}, rainbow-fg)");
+
+ is(qx(printf %s "$short_text" | $valgrind_cmd$program_buf blue/black --rainbow-bg),
+ "\e[40m\e[34mfoo bar ba\e[0m\e[40m\e[34mzfoo bar b\e[0m\e[40m\e[34maz\e[0m",
+ "partial line (BUF_SIZE=$BUF_SIZE{short}, rainbow-bg)");
+
+ unlink $program_buf;
+ }
+
{
my $colored_text = qx(printf '%s\n' "foo bar baz" | $valgrind_cmd$program red);
my $sequences = 0;