Hacker News new | past | comments | ask | show | jobs | submit login

I sometimes do that, but the output loses the color it had, which can make parsing it a bit tricky (although the less noisy new format will help a bit with that)



Use less -R to preserve color escape sequences when paging in less.


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).


You 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.


This 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.


cargo build --color always | less -R should work with recent cargo, alternativly `cargo rustc --color always -- --color always 2>&1 | less -R` works as well.


Thanks, I never knew this trick! This is working for me with "cargo build", but not "cargo test" unfortunately




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: