hpjansson / chafa

📺🗿 Terminal graphics for the 21st century.
https://hpjansson.org/chafa/
GNU Lesser General Public License v3.0
2.97k stars 64 forks source link

More examples in documentation #92

Open EmperorPenguin18 opened 2 years ago

EmperorPenguin18 commented 2 years ago

I'm trying to learn how to use the C api. I've never worked with glib before and am having trouble figuring things out. I think some examples on top of the one in "Using Chafa in your Application" would be helpful. Specifically the kitty stuff is what I'm trying to use and that seems very different from that example.

hpjansson commented 2 years ago

Agreed, it could use some more examples and a walkthrough of how the components fit together.

In the meantime, here's a link to how Harfbuzz' hb-view uses Chafa to get sixel or symbol output depending on the terminal's capabilities: https://github.com/harfbuzz/harfbuzz/blob/8940409e3c108e2c26c0f22679eb3c6cea4fee9d/util/helper-cairo-ansi.hh

You could adapt it and add Kitty support by doing something similar for it as for sixels. Namely by adding something like this to the if-else ladder in there:

if (chafa_term_info_have_seq (term_info, CHAFA_TERM_SEQ_BEGIN_KITTY_IMMEDIATE_IMAGE_V1))
{
    pixel_mode = CHAFA_PIXEL_MODE_KITTY;
    mode = CHAFA_CANVAS_MODE_TRUECOLOR;
}

The call to chafa_canvas_config_set_pixel_mode() is the important part for your use case.

I'll add API at some point to simplify creating a canvas configuration from a ChafaTermInfo (to avoid applications having to call chafa_term_info_have_seq(...) themselves).

If there's anything else I can help with, feel free to ask here!

hpjansson commented 1 year ago

I added an example recently that adapts to the environment. The approach from there (plus a little extra finesse) is being used by Cue, which is a pretty sweet app.

Longer term, the goal is to convert this to a documentation section and add more convenience functions to the library that will cut down on the boilerplate.

EmperorPenguin18 commented 1 year ago

What I can't seem to figure out is how to combine these two examples: https://github.com/hpjansson/chafa/blob/master/tests/adaptive.c https://github.com/hpjansson/chafa/blob/master/tests/ncurses.c

I want to use ncurses in the kitty terminal. adaptive.c works in kitty, and ncurses.c does 256 color in ncurses, but I can't get the best of both worlds. What am I missing?

hpjansson commented 1 year ago

Unless I'm misunderstanding something, if you're trying to combine kitty or sixel graphics with ncurses, that's currently not possible except through bypassing the ncurses update mechanism. That would limit you in various ways and you'd have to issue the escape codes for the bypass manually.

The issue is that ncurses doesn't understand any of the graphics protocols, so it won't play along.

Ranger is a program using ncurses with the ability to bypass it - it lets you run an external program to print graphics into a predefined view. If you really want to do this, you could look at how it manages.

EmperorPenguin18 commented 1 year ago

In that case my original question is answered. Thanks so much for the help!

hpjansson commented 1 year ago

No problem. Do you mind if I keep this issue open? We still need more examples in the actual documentation :-)

EmperorPenguin18 commented 1 year ago

Oh okay sure. Maintainers usually want the opposite so I did it by habit.