Browse Source

fix utf8 support

master
alistair 3 years ago
parent
commit
5c53afc4d4
  1. 12
      colcat.c

12
colcat.c

@ -85,8 +85,11 @@ int display(FILE *file) { @@ -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) { @@ -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) { @@ -111,7 +121,7 @@ int display(FILE *file) {
continue;
}
if (!in_escape) {
if (!in_escape && !in_utf8_mbchar) {
print_next_colour(counter);
}

Loading…
Cancel
Save