-
Notifications
You must be signed in to change notification settings - Fork 593
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
[hb-view] Use Chafa for terminal graphics if available #2959
Conversation
Lovely! One minor suggestion. Can we keep including and call the |
Sure thing, it's done. |
This produces high-quality terminal graphics using symbols or sixels according to the detected terminal capabilities. Fixes #2430.
No suitable versions are available on these setups.
config = chafa_canvas_config_new (); | ||
chafa_canvas_config_set_canvas_mode (config, mode); | ||
chafa_canvas_config_set_pixel_mode (config, pixel_mode); | ||
chafa_canvas_config_set_cell_geometry (config, 10, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious. How are these numbers used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cell geometry is the pixel size of a single character cell, and the canvas geometry is the size of the canvas in character cells. The cell size is only used in sixel mode: Let's say you have a canvas that's 10 cells wide, and we supply that character cells are 10 pixels wide. Chafa will then produce a sixel image that's 100 pixels wide, scaling the input image if necessary.
I decided to use 10x20 because that's the fixed cell size of VT240 and VT340 terminals (and possibly Windows Terminal too when/if it gets sixel support).
This will lead to sixel output being a bit bigger than expected on modern Linux terminals (character cells tend to be bigger than 10x20, but the aspect is usually about the same). It would be possible to get the cell size with the TIOCGWINSZ
ioctl (.ws_xpixel and .ws_ypixel fields divided by .ws_col and .ws_row). The chafa
command-line tool does this, but I avoided it in this patch because it seemed minor and might make Harfbuzz less portable.
See https://github.com/hpjansson/chafa/blob/2af7edec1adfdf1825cfb0dba46e8aaed7504918/tools/chafa/chafa.c#L726-L753 for how I did it in chafa
. I can add something similar to hb-view
if you think it's worth it.
Also see here for a long and somewhat opinionated discussion of sixel/cell dimensions arcana :)
Humm. On my Mac terminal I'm getting bad rendering. This seems to be same as the chafa cmdline's default 24bit color which renders wrong as well: @hpjansson any ideas? |
I disabled the truecolor mode for now. |
Oh. It might be my bad $TERM:
|
Humm. I'm not setting it. |
Disabling the truecolor mode seems fine as a stopgap. Does your terminal set anything else in the environment that would make it possible for me to identify it? E.g. VTE sets COLORTERM and VTE_VERSION. The issue is that there's a whole bunch of terminals out there that support truecolor/directcolor but identify themselves as xterm-256color. Worst case, I'll have to bite the bullet and make Chafa more conservative when identifying the terminal. |
Here:
|
Great, thanks! I'll make an exception for it in the 1.6.1 release. |
Link with and use Chafa if available. This produces high-quality terminal graphics using symbols or sixels according to the detected terminal capabilities.
Fixes #2430.