tammoippen / plotille

Plot in the terminal using braille dots.
MIT License
398 stars 17 forks source link

hex colors not showing up when parsing terminal results #41

Closed journeytosilius closed 3 years ago

journeytosilius commented 3 years ago

Hi, we are trying to figure out why we are not getting hex values for the plotille results when parsing the output with hd on a terminal, do you know why this might happen ?

example :

I plot, setting all lines to 4bit "names" / "bright-green" the output on the terminal is correct, with all lines in green.

But when I parse it with hd I get no color code in hex :

echo ⢀⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⢰⠃⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | hd
00000000  e2 a2 80 e2 a1 8f e2 a0  80 e2 a0 80 e2 a0 80 e2  |................|
00000010  a0 80 e2 a0 80 e2 a0 80  e2 a0 80 e2 a0 80 e2 a0  |................|
00000020  80 e2 a0 80 e2 a0 80 e2  a0 80 e2 a0 80 e2 a1 87  |................|
00000030  e2 a0 80 e2 a0 80 e2 a2  b0 e2 a0 83 e2 a1 8e e2  |................|
00000040  a0 80 e2 a0 80 e2 a0 80  e2 a0 80 e2 a0 80 e2 a0  |................|
00000050  80 e2 a0 80 e2 a0 80 e2  a0 80 e2 a0 80 0a        |..............|
0000005e

do you know why this happens ?

tammoippen commented 3 years ago

plotille tries to figure out, if it actually should print colors. Have a look at the color-module: https://github.com/tammoippen/plotille/blob/master/plotille/_colors.py#L80 f

if it does not detect a terminal context (tty), you usually do not want to print colors, e.g. when piping into another program or redirecting into a file (those color codes are only relevant for the terminal).

If you want to inspect the codes, then write the returned str from Figure.show() into a file from within python.

i think i will add a toggle to force color output in #39 .

journeytosilius commented 3 years ago

thanks and yes please ! this is important since if we want to embed it on an TUI, the color codes are very important

journeytosilius commented 3 years ago

fixed it locally by removing the tty check, thanks for pointing it out :)