diff --git a/colcat.c b/colcat.c index 08cbd56..1dec9d7 100644 --- a/colcat.c +++ b/colcat.c @@ -85,8 +85,11 @@ int display(FILE *file) { counter = num_colours; // so that print starts at reverse=true } bool in_escape = false; + bool in_utf8_mbchar = false; bool vert_reverse = false; while (c != EOF) { + + if (c == '\n') { if (frequency && end) { if (counter % (end) == 0) { @@ -101,6 +104,13 @@ int display(FILE *file) { } reverse = false; } + + if ((c & 0b11000000) == 0b10000000) { + in_utf8_mbchar = true; + } else { + in_utf8_mbchar = false; + } + if (c == '\033') { in_escape = true; } else if (end_hue_ansi_code(c) && in_escape) { @@ -111,7 +121,7 @@ int display(FILE *file) { continue; } - if (!in_escape) { + if (!in_escape && !in_utf8_mbchar) { print_next_colour(counter); }