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

how to force colour output with a pager ? #219

Open
simonmichael opened this issue May 18, 2024 · 5 comments
Open

how to force colour output with a pager ? #219

simonmichael opened this issue May 18, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@simonmichael
Copy link

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

@sharkdp sharkdp added the bug Something isn't working label Jun 22, 2024
@sharkdp
Copy link
Owner

sharkdp commented Jun 22, 2024

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
Copy link
Owner

sharkdp commented Jun 22, 2024

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

@andelink
Copy link

andelink commented Sep 2, 2024

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

@jessefarinacci
Copy link

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'

@andelink
Copy link

@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 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants