Make lolcat interleave nicely with non-colored stderr
This works by making lolcat always reset the color at the end of a line on its input, and only setting a new color immediately before printing the first character on the next line. This way, assuming that whatever process is piped into lolcat follow the standard convention where stdout is buffered line-wise, and only writes full lines to stderr, a process that outputs to both stdout and stderr but that has only stdout piped through lolcat (as most people would do) would have it's stderr output interleave nicely uncolored with the lolcat-colored stdout output. This won't always work, but it gets us most of the way there with little effort and negligible (2 extra escape sequences per line of output) performance overhead. Thanks to github user @kolayne for reporting this as an issue!
This commit is contained in:
parent
dc3ddf3950
commit
f2c26ed7a7
1 changed files with 3 additions and 0 deletions
3
lolcat.c
3
lolcat.c
|
|
@ -390,8 +390,11 @@ int main(int argc, char** argv)
|
|||
if (c == '\n') {
|
||||
l++;
|
||||
i = 0;
|
||||
cc = -1;
|
||||
if (invert) {
|
||||
wprintf(L"\033[49m");
|
||||
} else {
|
||||
wprintf(L"\033[0m");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue