You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Take a program like this, which writes an ANSI escape code to stderr, flushing the buffer after each character is written:
importsys;
forcin"\033[;1mHi!\n":
sys.stderr.write( c )
sys.stderr.flush()
Stderr doesn't handle it properly. It tries to color every single character in red, but this breaks the original escape code.
With the program above, stderr prints "[;1mHi!" (in red):
$ python -c 'for c in "\\033[;1mHi!\n": import sys; sys.stderr.write(c); sys.stderr.flush()'
[;1mHi!
An explicit flush isn't even needed: writing the string character by character on an unbuffered stderr has the same effect:
$ python -uc 'for c in "\\033[;1mHi!\n": import sys; sys.stderr.write(c)'
[;1mHi!
Example in the wild
I ran into this issue while using GHCi, the Haskell's REPL. This is what you get when you input something wrong while stderred is loded:
ghci> variableNotInScope
[;1m<interactive>:3:1: [;1m[31merror:[0m[0m[;1m[0m[0m[;1m Variable not in scope: variableNotInScope[0m[0m
What should happen instead
I'm assuming that it's unnecessary to maintain the original stderr as-is, since stderred transforms it anyways with its own color codes.
Thus I think stderred should either remove all the ANSI escape code and all the non-printable characters (according to the term's character encoding) from the stderr, or otherwise keep the ANSI escape code intact without interlacing them with the stderred's escape code. Both solutions require detecting and buffering the escape codes.
The text was updated successfully, but these errors were encountered:
Issue
Take a program like this, which writes an ANSI escape code to stderr, flushing the buffer after each character is written:
Stderr doesn't handle it properly. It tries to color every single character in red, but this breaks the original escape code.
With the program above, stderr prints "[;1mHi!" (in red):
An explicit flush isn't even needed: writing the string character by character on an unbuffered stderr has the same effect:
Example in the wild
I ran into this issue while using GHCi, the Haskell's REPL. This is what you get when you input something wrong while stderred is loded:
What should happen instead
I'm assuming that it's unnecessary to maintain the original stderr as-is, since stderred transforms it anyways with its own color codes.
Thus I think stderred should either remove all the ANSI escape code and all the non-printable characters (according to the term's character encoding) from the stderr, or otherwise keep the ANSI escape code intact without interlacing them with the stderred's escape code. Both solutions require detecting and buffering the escape codes.
The text was updated successfully, but these errors were encountered: