sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5k stars 97 forks source link

pastel pick doesn't display all colors #121

Closed nycex closed 1 year ago

nycex commented 4 years ago

When I run pastel pick in st or urxvt, i get a output like output_image even though when running this:

awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    }
    printf "\n";
}'

from https://gist.github.com/XVilka/8346728, I get a smooth gradient: gradient_image In alacritty, it seems to work though: alacritty_output_image

sharkdp commented 4 years ago

It appears that urxvt does not set the COLORTERM variable to truecolor, which is the only way how we can detect that a terminal emulator supports 24bit colors.

If you run pastel colorcheck, you should be able to clearly determine whether or 24bit is supported.

sharkdp commented 4 years ago

Don't you see a warning in the top output of pastel pick?

image

nycex commented 4 years ago

Well, I saw the warning and set the environment variable PASTEL_COLOR_MODE=24bit. With this enabled, I get the output in st and urxvt I showed earlier. But now that I tried, when I set COLORTERM=24bit or COLORTERM=truecolor, then it shows correctly all the colors like in alacritty. Maybe there is a problem with the check for PASTEL_COLOR_MODE

Edit: Btw it just works for st, I just looked into it and urxvt doesn't even support truecolor to my surprise.

sharkdp commented 4 years ago

Maybe there is a problem with the check for PASTEL_COLOR_MODE

It looks like there is, yes. I can reproduce it. Thank you for reporting this!

(Unrelated: in general, I suggest using a terminal which properly sets COLORTERM. This will also enable true color support in many other programs).

yugonline commented 3 years ago

Can you explain where to start? I can give this a go but I'm new to Rust. So I'll timebox it to not waste time.

sharkdp commented 3 years ago

@yugonline Sorry for the delay. Are you still interested in tackling this?

sharkdp commented 3 years ago

So to reproduce this, run:

COLORTERM="" PASTEL_COLOR_MODE=24bit pastel pick

It should show a smooth color palette (like for COLORTERM="truecolor" pastel pick), and not with a restricted color depth, like in the screenshot above.

Next, look into src/cli/colorpicker.rs and start here:

    let mut canvas = Canvas::new(
        width + 2 * config.padding,
        width + 2 * config.padding,
        Brush::from_environment(Stream::Stderr),
    );

The problem is the Brush::from_environment(Stream::Stderr) call which detects colordepth support by checking whether STDERR is an interactive terminal or not. Instead, it should also take into account environment variables. Search for COLORTERM and PASTEL_COLOR_MODE, to see how it is used in other places.

yugonline commented 3 years ago

Sounds good I'll take a look!