3 ms·
This only helps if the program that pipes into less doesn't do terminal detection to decide that it doesn't want to output ANSI color escapes into a pipe (to le
by heinrich5991 10y ago
This only helps if the program that pipes into less doesn't do terminal detection to decide that it doesn't want to output ANSI color escapes into a pipe (to less).
- abbeyj 10y agoYou may sometimes be able to work around this by using `expect` which creates a pseudoterminal attached to the program's stdout instead of a pipe. For example, say the program you want to run is `ls --color=auto`. This produces color when stdout is a terminal but no color when stdout is a pipe. If we just did: ls --color=auto | less -R we'd see no color. Instead we can run ls under expect: expect -c "spawn -noecho ls --color=auto; expect" | less -R and color abounds. There may be an easier way to accomplish this. If anybody has ideas, chime in.
- saghm 10y agoThis partially works for me with "cargo test"; it also seems to print a control character ('^O') after every colored string, as well as at very beginning of the output. Additionally, after a certain amount of output (maybe 1.5 times my terminal height), it prints an ellipsis and stops printing anything new. Thanks a bunch for pointing me towards `expect`, though! I hadn't used it before, and I'll definitely do some experimenting with it to see if I can get my desired output with it.
- bennofs 10y agocargo build --color always | less -R should work with recent cargo, alternativly `cargo rustc --color always -- --color always 2>&1 | less -R` works as well.