dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.56k stars 112 forks source link

Possibility of refreshing terminfo cache? #2749

Open zhiayang opened 8 months ago

zhiayang commented 8 months ago

Is it possible to ask notcurses to refresh its internal terminfo cache during runtime? From what I can tell, it's only done by interrogate_terminfo during initialisation, and never again.

It's definitely slow, and I don't intend on doing it every frame, but the usecase for me is that sometimes the default background/foreground colour can change due to the terminal theme changing, and I'd like the program to respond to the changes without a restart --- even if it's not instantaneous (eg. if I restrict myself to reloading terminfo every second or something).

dankamongmen commented 8 months ago

so this has been a definite consideration for some time. i thought that several terminals generate a sequence to notify the application of this, but maybe that's just something i imagined, or asked for? i'd need to go look.

if there's no sequence generated, ideally such a change would result in a SIGWINCH. upon receipt of a SIGWINCH, we query the screen dimensions, and could theoretically query the back/foreground then, eliminating the need to poll (i'm definitely not adding notcurses-level support for polling). i suppose i could expose the initial queries to the app for it to run in a loop, but i really, really dislike that idea.

let me look around see whether i'm just hallucinating about a sequence sent by the terminal. if i am, i'll consider adding this to SIGWINCH handling, but i'd probably hide it behind a non-default notcurses_init() option. the big problem is that if we're going to blindly query these, we logically ought query the palette as well, which is a big nasty operation (O(n) on the size of the palette).

zhiayang commented 8 months ago

fwiw i'm using wezterm -- after a quick glance at the code, it doesn't seem like there's any special event being sent to the running program. I'm using window:set_config_overrides to change the colour_scheme via the lua api.

dankamongmen commented 8 months ago

the idea of the app polling this really makes me want to vomit. let me look back over my emails; i know i wanted a solution to this problem.

neurocyte commented 8 months ago

Is this what you were looking for? https://github.com/contour-terminal/contour/blob/f3c3334aa5c861348c5bbe8ffe572c872eef2e08/docs/vt-extensions/color-palette-update-notifications.md