cacalabs / libcaca

💩 Colour ASCII Art Library
Do What The F*ck You Want To Public License
548 stars 70 forks source link

Blinking characters #47

Open trosendal opened 5 years ago

trosendal commented 5 years ago

This issue also appears here: (https://github.com/ranger/ranger/issues/1407) with a nice example. It can be reproduced in docker as follows. Start a docker from the official fedora 30 image:

docker run -it fedora:30 sh

Then inside the running docker:

dnf install -y caca-utils
curl https://cdn.pixabay.com/photo/2016/12/06/03/46/cat-1885511_640.jpg --output foo.jpg
cacaview foo.jpg

The characters in the cat's ears are blinking

TragicWarrior commented 5 years ago

@trosendal , I strongly suspect this is caused by an attempt by libcaca to emulate 16 colors on a 8 color terminal. It does this by setting the A_BOLD and A_BLINK attributes when the terminal says it only supports the standard 8 colors in order to emulate a 16 color palette. As the author of a terminal emulator, I was just getting ready to write up this very issue.

@samhocevar , while the strategy may work on some terminals, it definitely does not on others. instead, the cell blinks (as it actually should).

trosendal commented 5 years ago

@TragicWarrior I'm not sure how to affect the available colors in a terminal. When I view the above foo.jpg with cacaview in a gnome terminal I don't get the blinking so you may be right. Is it possible to get 16 colors in a terminal such as the docker example above? If it were possible to configure a docker container to show 16 colors perhaps we could illustrate that the problem is as you describe.

TragicWarrior commented 5 years ago

@trosendal , I don't have any experience with docker--I use lxc instead. My suspicion is that docker alters your environment variables TERM and COLORTERM. The TERM var is the most important. That is what ncurses reads at startup to determine how many colors are available. On most modern systems, these are set as follows:

COLORTERM=truecolor
TERM=xterm-256color

Once you know what TERM is set to you can query the terminfo database to see what ncurses is likely going to think you should have:

(using my string above from my environment)

infocmp xterm-256color |grep color

colors#0x100, cols#80, it#8, lines#24, pairs#0x7fff,

So on my xfce4 terminal, it supports 0x100 colors (256) which cause libcaca to initialize the 8 standard colors plus the 8 extended colors. At startup libcaca reads the ncurses COLORS variable--which is almost always based on ncurses reading the terminfo db. If the value of COLORS is < 16 then libcaca tries to emulate 16 colors by setting A_BOLD and A_BLINK on the standard 8 colors. This works in some cases. In others, it simply causes the affected cell to blink (which I would argue is the correct behavior). IMO, libcaca should not try to emulate 16 colors using this well-known, but unreliable trick.

TragicWarrior commented 5 years ago

@trosendal , It seems that the author is aware of the incompatibilty caused by this approach (emulating 16 colors).

https://github.com/cacalabs/libcaca/blob/master/NOTES

dmnc-net commented 3 years ago

Unfortunately the img2txt convertor generates blinking characters even if the picture pallete is very limited. I've scaled down the palette to index colors with max. of 4 colors in Gimp and the result is still blinking as hell :( I'm missing some option to use the limited palette with nearest colors for the output.

trosendal commented 3 years ago

@TragicWarrior is correct that this is apparently due to the 8 colour terminal. So I understand you want to fix it by scaling your colours to only those available in the current terminal, but for me it is fixed by just expanding my colours to 256. In line with my first test case, the following causes blinking:

docker run -it fedora:latest sh
dnf install -y caca-utils
curl https://cdn.pixabay.com/photo/2016/12/06/03/46/cat-1885511_640.jpg --output foo.jpg
cacaview foo.jpg

But this does not:

docker run -it fedora:latest sh
dnf install -y caca-utils
curl https://cdn.pixabay.com/photo/2016/12/06/03/46/cat-1885511_640.jpg --output foo.jpg
TERM=xterm-256color
cacaview foo.jpg
poetaman commented 2 years ago

I have the same problem!

christo commented 2 months ago

This happens for me using all the docker fedora examples above with and without setting TERM=xterm-256color. I've also tried it on a physical linux box running Ubuntu 22.04.4 - same problem. It also happens on MacOS Sonoma 14.6.1 with libcaca Version: 0.99.beta20, date: Oct 19 2021 installed with brew with a terminal emulator of either iTerm2 or the built-in Terminal, both when using tmux and without tmux.

FWIW I am using iTerm2 on the Mac to do the docker tests and the tmux tests and to ssh to the physical linux box (also using tmux). I'm not sure which parts are relevant here; the shell, OS environment it's running in, or something to do with the terminal etc.

Contrary to speculation above, I can't conclude it's simply a matter of setting TERM. In all cases I have TERM=xterm-256color.