aaronriekenberg / rust-parallel

Fast command line app in rust/tokio to run commands in parallel. Similar interface to GNU parallel or xargs plus useful features. Listed in Awesome Rust utilities.
MIT License
146 stars 7 forks source link

Stdout Color Support #6

Closed mbechto closed 1 year ago

mbechto commented 1 year ago

Steps to Reproduce

Run the following with rust-parallel 1.6.2:

rust-parallel sh -c ::: "diff --color <(echo hi) <(echo there)"

Expected Behaviour

The command output should contain colored text, since running the same command in the shell yields colored output.

Actual Behaviour

The command output does not contain colors:

image

aaronriekenberg commented 1 year ago

In the diff command above, if you change --color to --color=always does this fix the problem?

I see colored output with either of these commands (-s is equivalent to /bin/bash -c):

rust-parallel /bin/bash -c ::: "diff --color=always <(echo hi) <(echo there)"

rust-parallel -s ::: "diff --color=always <(echo hi) <(echo there)"

The default behavior of diff --color is to autodetect if the output is a terminal or not, and to only output colors if a terminal is detected. I suspect the pipes used by rust-parallel do not pass this "are we using a terminal" check and so this autodetection does not work.

But for me it looks like using --color=always to force use of color works.

From the diff man page: https://man7.org/linux/man-pages/man1/diff.1.html

--color[=WHEN]
  color output; WHEN is 'never', 'always', or 'auto'; plain
  --color means --color='auto'

Thanks!

mbechto commented 1 year ago

In the diff command above, if you change --color to --color=always does this fix the problem?

Yes, indeed it does. Sorry for the confusion, I forgot how the --color parameter works.

(-s is equivalent to /bin/bash -c):

Good to know!

Anyway, thanks for the help (and this great project!) 🙂

aaronriekenberg commented 1 year ago

Thank you @mbechto !

I appreciate your question and feedback, let me know if you run into other issues. 🙂

aaronriekenberg commented 1 year ago

@mbechto you might find this example useful based on your question: https://github.com/aaronriekenberg/rust-parallel/wiki/Examples#running-diff-on-all-files-in-2-directories

thanks! 🙂