97 points · by graderjs · 4y ago · 31 comments
I can't even wrap my head around trying to in-place rotate a bitmap in C without pulling my hair out. This guy must do it in his sleep.
The subset of usable characters (glyphs) roughly defines how accurate the picture can be represented: if all you have is - and _ and you want to represent an horizontal pipe, it'll be ugly.
Of course it's more complicated than that, but caca uses ascii, while chafa uses a larger unicode range.
The example is illustrated in picture on https://github.com/csdvrx/derasterize where the left is the original basicidea.c using only unicode halfblocks, and the right has more candidate of different shapes.
Derasterize lets you select the width of the range you want to use, to improve encoding time say for video - but ideally, you would be able to test that whatever font you are using contains the glyphs you want.
The thing about sixel is it's only supported on old DEC glass terminals, xterm with a non-default configuration, mintty, and several emulators that are fairly unlikely to be preinstalled anywhere. So I struggle to imagine a scenario outside of the novelty of playing video media in a terminal where you'd use sixel for playing video over either a dedicated streaming API (raw video stream, networked X, VNC, waypipe) or accessing media over a networked filesystem (e.g. sshfs, which I regularly use to watch videos).
Images are a different matter, where the compromise makes more sense. Juxtaposing images with terminal output is a nifty feature. But the (IMO limited) utility of programs like caca and chafa is being "universal enough" that I can write a script that vomits a jpeg to some vague common denominator standard and it'll probably work for all my coworkers using a smorgasbord of emulators.
Uh, no?
Just start xterm (say from another xterm) with the correct flag. Sixels are also supported on the BSD console.
The lack of support in the likes of gnome-terminal is a willful and ugly political decision that I've already documented.
> Images are a different matter, where the compromise makes more sense.
Indeed, I love to do remote gnuplots
> I can write a script that vomits a jpeg to some vague common denominator standard and it'll probably work for all my coworkers using a smorgasbord of emulators.
This is the idea of tmux-sixel https://github.com/csdvrx/sixel-tmux : intercept sixels sequences and, if your terminal doesn't support it (or if you use the scrollback buffer, to save or RAM), render a unicode representation instead (like Chafa), but if it does, pass through the original sixel sequence.
I'm not sure why people expose themselves to something as bad and ugly in this day and age.
Even in 2016 you could use ffmpeg on a sixel-aware terminal like mintty or xterm: check https://www.youtube.com/watch?v=IkUTkqctP28
ffmpeg is a dependency of mplayer, but ffmpeg on it's own can't transcode or reinterpret video as ASCII. The reason for the exercise is only to show that video and graphics can be displayed on the command line within the limitations of the command line, namely, text only.
Chafa 1.8: Terminal graphics with a side of everything - https://news.ycombinator.com/item?id=28548120 - Sept 2021 (23 comments)
I don't exactly remember how that works. There is the alternate screen buffer:
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-T...
Maybe there was also a special sync terminal escape code or so.
Googling for it, it seems some other terminals implement this as well.
https://sw.kovidgoyal.net/kitty/protocol-extensions/
The intention is to document them well enough that other terminal emulators can implement them (which some have).
Among those is a graphics protocol, which is actually (optionally) used by chafa. Another is a keyboard protocol extension: which has been implemented by a number of editors and other terminals: notably neovim, kakoune, helix, wezterm, and foot.