Skip to content
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

More examples in documentation #92

Open
EmperorPenguin18 opened this issue May 26, 2022 · 7 comments
Open

More examples in documentation #92

EmperorPenguin18 opened this issue May 26, 2022 · 7 comments
Labels
docs Documentation good first issue help wanted Extra attention is needed
Milestone

Comments

@EmperorPenguin18
Copy link

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
Copy link
Owner

hpjansson commented May 26, 2022

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 hpjansson added the help wanted Extra attention is needed label Aug 20, 2022
@hpjansson
Copy link
Owner

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.

@hpjansson hpjansson added this to the 1.16 milestone Aug 15, 2023
@EmperorPenguin18
Copy link
Author

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
Copy link
Owner

hpjansson commented Nov 17, 2023

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
Copy link
Author

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

@hpjansson
Copy link
Owner

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

@EmperorPenguin18
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation good first issue help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants