Skip to content

Commit

Permalink
Send already colorized buffer to correct stream
Browse files Browse the repository at this point in the history
If the buffer had ansi escape codes, it was always sent to stdout.
With this fix, it's correctly sent to either stdout or stderr.
Close #24
  • Loading branch information
jalvesaq committed Aug 26, 2024
1 parent d783015 commit 910592d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/colorout.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,13 @@ void colorout_R_WriteConsoleEx (const char *buf, int len, int otype)
/* Do nothing if the output was already colorized by another package */
for(i = 0; i < len; i++)
if(buf[i] == 0x1b){
printf("%s", buf);
if (otype) {
fprintf(stderr, "%s", buf);
fflush(stderr);
} else {
printf("%s", buf);
fflush(stdout);
}
return;
}

Expand Down Expand Up @@ -748,9 +754,8 @@ void colorout_R_WriteConsoleEx (const char *buf, int len, int otype)
printf("%s\033[0m\n", newbuf);
else
printf("%s\033[0m", newbuf);

free(newbuf);
fflush(stdout);
free(newbuf);
}
free(bbuf);
}
Expand Down

0 comments on commit 910592d

Please sign in to comment.