Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forced colorization via an option #128

Open
Kshitiz-Sharma opened this issue Apr 6, 2020 · 1 comment
Open

Allow forced colorization via an option #128

Kshitiz-Sharma opened this issue Apr 6, 2020 · 1 comment

Comments

@Kshitiz-Sharma
Copy link

Log files are usually viewed on the console using tools like less.

Similar to rainbow, grep omits colors from its output if the destination is not console. However, it allows forcing it using --color=always. This combined with the -R switch in less allows viewing the output with colors and have the scroll, search options of less.

At the moment rainbow seems to want to dump the entire file to console. Unless this is mentioned in the documentation somewhere, and I've missed it.

@joelpurra
Copy link

@Kshitiz-Sharma: I agree, a --color[=WHEN] flag (never, always, default auto) would be great.

As a workaround, you can use the undocumented environment variables RAINBOW_ENABLE_STDOUT/RAINBOW_ENABLE_STDERR. Below using hexdump to verify the byte output instead of screenshots with color. Replace hexdump -c with cat to get the "real" colorized output.


With pipe from rainbow, piped to hexdump.

Note that the b would colored red without hexdump.

RAINBOW_ENABLE_STDOUT=true rainbow --red 'b' echo 'abc' | hexdump -c
0000000   a 033   [   3   1   m   b 033   [   3   9   m   c  \n 033   [
0000010   0   m                                                        
0000012

With pipe through rainbow, piped to hexdump.

echo 'abc' | RAINBOW_ENABLE_STDOUT=true rainbow --red 'b' | hexdump -c

Note that the b would colored red without hexdump.

0000000   a 033   [   3   1   m   b 033   [   3   9   m   c  \n 033   [
0000010   0   m                                                        
0000012

Watching a command, with output piped to rainbow

My use-case is watch --color. Note that --color is not available in all watch versions, but at least in the apt package procps from procps-ng v3.3.15.

Colorization works only with RAINBOW_ENABLE_STDOUT=true. Note that the output would be garbled without --color.

watch --color "echo 'abc' | RAINBOW_ENABLE_STDOUT=true rainbow --red 'b'"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants