AuHau / toggl-cli

A simple command-line interface for toggl.com
https://toggl.uhlir.dev
Other
360 stars 69 forks source link

Add `--colors=always` option for passing to `click` #239

Open haluzpav opened 2 years ago

haluzpav commented 2 years ago

When I do var="$(toggl now)" and then echo $var, the output is not colored, as when I do just toggl now. This works with other commands, tldr for example.

If this is caused by some misconfiguration or twisted expectations on my side, I'm sorry. Please let me know. 🙂

Screenshot 2022-03-30 at 19 50 07

haluzpav commented 2 years ago

I guess it's because we want plain text when e.g. outputing to a file, huh? I figured out how to bypass that for my use-case with unbuffer. So let me rephrase the issue:

It's be nice if toggl had a --colors=always parameter. 😁

StanczakDominik commented 1 year ago

Here's the relevant bit of click docs, a color flag to click.echo:

color (Optional[bool]) – Force showing or hiding colors and other styles. By default Click will remove color if the output does not look like an interactive terminal.

So this is definitely possible, but would require a replacement of, most likely, every single call to click.echo ( a quick rg echo | wc -l puts this at 61 occurences) with something like toggl.helpers.echo (placement to be discussed!), which would be a thin wrapper around click.echo that checks the config (from toggl/utils/config.py?) for a new --colors flag (None by default) and passes that.

@haluzpav, would you be open to submitting a pull request? 🙂