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

Add an option to force color output #11

Closed
SuperSandro2000 opened this issue Sep 22, 2020 · 16 comments
Closed

Add an option to force color output #11

SuperSandro2000 opened this issue Sep 22, 2020 · 16 comments
Labels
enhancement New feature or request

Comments

@SuperSandro2000
Copy link

When I pipe duf into less I want to preserve colors. Currently there is no option for that. Could an option like --color or --color=always be added?

@muesli muesli added the enhancement New feature or request label Sep 23, 2020
@muesli
Copy link
Owner

muesli commented Sep 23, 2020

Yeah, that's probably a good idea. I wonder if there's a global, existing environment variable for such a setting.

@SuperSandro2000
Copy link
Author

I wonder if there's a global, existing environment variable for such a setting.

Not that I know of or could find on the fast.

@muesli
Copy link
Owner

muesli commented Sep 23, 2020

Thanks for the research!. I think --color(=true) is good enough in this case.

@lfuelling
Copy link

That use-case applies to watch as well imo.

@muesli
Copy link
Owner

muesli commented Oct 10, 2020

Just occurred to me that setting COLORTERM to truecolor should already achieve that. I guess that's the environment variable I was looking for.

@jrwren
Copy link

jrwren commented Oct 13, 2020

COLORTERM=truecolor doesn't seem to force color when output isn't a tty, e.g. when piping to less. --color(=true) still seems like a good idea.

@muesli
Copy link
Owner

muesli commented Oct 14, 2020

@jrwren Oops, you're right, of course!

@muesli
Copy link
Owner

muesli commented Jul 4, 2021

Slight improvement and just a small heads up: you can enforce colored output by setting CLICOLOR_FORCE to true. There's still an issue: this will default to 256 ANSI colors instead of the RGB output.

@gsmitheidw
Copy link

gsmitheidw commented Aug 1, 2021

For some reason, on two systems I use - duf isn't producing any native colour. Can't understand why because colours in other programs and scripts are working fine (bash, exa, midnight commander etc). I can cheat doing stuff like this:

duf | less -R | ccze -A

But I don't understand why colours aren't working on some systems (both Debian based).

(less -R will preseve colours by the way for anybody who is finding colour codes instead of colour output)

@muesli
Copy link
Owner

muesli commented Aug 11, 2021

@gsmitheidw Which terminal are you using? Could you please report the value of these environment variables: TERM, COLORTERM.

@gsmitheidw
Copy link

gsmitheidw commented Aug 11, 2021

These aren't set on one system and are blank on the other:

  $ export | grep COLOR 
  declare -x COLOR
  declare -x COLORTERM

Maybe that's the issue, although duf colours are working on other systems they're not set so I don't know.

@bionade24
Copy link

Why is COLORTERM=truecolor set in one tmux window but not on the remote machine?
duf-cli-colors

@muesli
Copy link
Owner

muesli commented Feb 1, 2022

I've improved the color detection & output a bit and verified these settings should always work with the latest changes in duf:

# Enforce RGB / 24-bit color mode
CLICOLOR_FORCE=1 COLORTERM="truecolor" duf

# Enforce 8-bit / 256 color mode
CLICOLOR_FORCE=1 COLORTERM="yes" duf

Color output is however still limited to basic ANSI colors when printing to something other than a tty.

I'll close this issue as I think this is probably a good enough solution. Disagree? Let me know! 😃

@muesli muesli closed this as completed Feb 1, 2022
@bionade24
Copy link

Seems to work now after enforcing the 2 env vars. But from a pure technical aspect, I still wonder my liquidprompt, fd, bat & other tools don't have a problem without those vars at all and behave the same as if they weren't in a shell opened via ssh will duf thinks the terminal doesn't support colors. Both Term windows are still have TERM=screen just as shown in the picture above.

@muesli
Copy link
Owner

muesli commented Feb 5, 2022

@bionade24 Thanks for the feedback! I've just created a PR on termenv that should enable screen sessions to always support the ANSI256 profile: muesli/termenv#68

That means you won't have to set these env vars anymore in a future duf release.

@nafg
Copy link

nafg commented Aug 14, 2022

Could this be documented in --help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants