todoist icon indicating copy to clipboard operation
todoist copied to clipboard

Color always

Open alecandido opened this issue 2 years ago • 3 comments

Add --color=always option (or settings), in order to be able to pipe colors in pagers.

At the moment, if the output is redirected, colors are stripped.

alecandido avatar Jan 14 '22 12:01 alecandido

What are you piping in to? less? I would assume that less is stripping the color, although with my minimal testing and very minimal knowledge of the inner workings of less I'm not able to get less -R or less -r to work on MacOS

HacDan avatar Apr 26 '22 19:04 HacDan

On Ubuntu (but I guess on any Linux distro) this works wonderfully:

exa --color=always | less -r

(just used exa since ls was the simplest thing came in my mind, but too simple to enforce colors).

P.S.: even less -R works perfectly, of course

alecandido avatar Apr 26 '22 20:04 alecandido

Using lsd--color=always I was able to confirm that on MacOS using less -R (or less -r for that matter) keeps colors in tact. I'll look into what was used for formatting output to see if this is possible. I would think it is but I'm obviously not the author, just an enthusiast who likes fiddling with Go.

HacDan avatar Apr 26 '22 20:04 HacDan

The issue is in the color library, I opened an issue on them: https://github.com/fatih/color/issues/179

nabaco avatar Jan 05 '23 02:01 nabaco

When I dug into this, iirc, the color library supported it, it was a matter of adding another flag to todoist-cli and working that in. I had started but never finished. I'll take a look again tonight.

HacDan avatar Jan 05 '23 11:01 HacDan

if someone wants to test the patch I just submitted, that would be helpful. It works for me when piping to less -R. No changes needed to use.

I decided against expanding on the CLI options as there is a way to get a more flat-file-friendly output with the --csv option. Thoughts are welcome.

HacDan avatar Jan 06 '23 03:01 HacDan

I confirm it is working also for me. Thanks :)

alecandido avatar Jan 06 '23 08:01 alecandido