pastel icon indicating copy to clipboard operation
pastel copied to clipboard

how to force colour output with a pager ?

Open simonmichael opened this issue 1 year ago • 6 comments

I love pastel, thanks!

Output is often long and I'd like to view it in a pager. I think pastel disables colour output when stdout is non-interactive. How can I force it not to ? I tried eg TERM=xterm-256color COLOR=always pastel -f list | less -R

simonmichael avatar May 18 '24 22:05 simonmichael

Oh, that is a bug.

-f should indeed force colors to be visible, even if the output is non-interactive. I'm pretty sure this worked before...

sharkdp avatar Jun 22 '24 20:06 sharkdp

Or maybe it only worked for pastel paint (where -f still works)

sharkdp avatar Jun 22 '24 20:06 sharkdp

FWIW I also have not been able to get the pastel color command to force colorization. pastel paint yes, pastel color and pastel list, no. I would also really appreciate this feature if it's possible

andelink avatar Sep 02 '24 19:09 andelink

I'm interested in this too, and I also love pastel! I wanted to use pastel as part of a color theme picker TUI. :) If you have fzf installed, here's a quick working demo of the same non-interactive mode not allowing the full typical output.

pastel random | pastel format | fzf --preview 'pastel color {}'

I also tried with pastel --color-mode 24bit --force-color color {} in the final preview step, no joy. Confirmed works with pastel paint {} 'quick brown fox lazy dog'

jessefarinacci avatar Nov 05 '24 17:11 jessefarinacci

@jessefarinacci I was also trying to use it in fzf! The pastel color output in the preview window would be very nice. I was working with palettes at the time so I was viewing multiple colors at once. The workaround I came up with was to use the other subcommands of pastel to generate previews. Not as nice, and also slower, but it's all I've got right now.

Below is an example screenshot and a zsh pipeline to reproduce. My input was files that stored palette definitions, so the below is a modified version to make it more sharable (basically all the input/formatting commands). Pardon the hackery with perl, it's to align table column lengths.

image

Code

I realize now it uses zsh-specific parameter expansion - sorry bash users

# zsh
pastel random -n25 \
  | pastel format hex \
  | rs 0 5 \
  | fzf \
    --bind 'enter:become:print -l ${(z):-{}}' \
    --preview-window right,75% \
    --preview "\
        print -l \${(z):-{}} \
          | xargs -S9999 -I% zsh -c '\
            fg=\$(pastel textcolor \"%\" | pastel mix gray -s RGB -f 0.2); \
            pastel -f paint \${fg} -n -o \"%\" \"\$(pastel format hex \"%\")~\"; \
            pastel -f paint \${fg} -n -o \"%\" \"\$(pastel format name \"%\")~\"; \
            pastel -f paint \${fg} -n -o \"%\" \"\$(pastel format rgb \"%\")~\"; \
            pastel -f paint \"%\" \"  $(curl -sS https://icanhazdadjoke.com)\"
          ' \
          | perl -p \
            -e 's/;(\d)(?!\d\d)/;0\$1/g;' \
            -e 's/;(\d\d)(?!\d)/;0\$1/g;' \
            -e 's/0?(38|48);00(2|5)(?=(;\d\d\d)+)/\$1;\$2/g' \
          | column -ts~ \
      " \
    | pastel -f color

I'm extremely color blind though so maybe I shouldn't be working with colors in the first place 😅

andelink avatar Jan 14 '25 22:01 andelink