4 ms·
Can It detect non terminal output and render normal ascii such as when pipe/redirect stdout/stderror to a file? or pipe to seed and avoid messing up with color
by kureikain 6y ago
Can It detect non terminal output and render normal ascii such as when pipe/redirect stdout/stderror to a file? or pipe to seed and avoid messing up with color code.
I recently release a tool with a nice table but many hate the format, the color and it even make `grep` impossible because color code make grep match every line :-(
- willm 6y agoYes, Rich will remove escape sequences when not writing to a terminal.
- spudlyo 6y agoman 3 isatty If you find yourself hard coding ANSI escape sequences in your program's output, please, please check to see if STDOUT is a tty first. This will prevent spewing escape sequences to a file. For extra credit, please consider using tput() and friends to emit escape sequences rather than hard coding them. This may seem stupid when nearly every terminal in the world is now effectively an ANSI terminal, but sometimes vision impaired folks (and others) are using intentionally limited terminals with their type set to "dumb". Good programs respect this, and conditionally output their escape sequences.
- JdeBP 6y ago* https://github.com/willmcgugan/rich/blob/837b6d7e85254f0047cb41a4cbe0e4b00f54809d/rich/console.py#L435 https://github.com/willmcgugan/rich/blob/837b6d7e85254f0047c... Note that it is possible to respect TERM=dumb without using termcap or terminfo, although this library does not do that.