2
3
4
5
6
7
8
9
10
11
13#define _XOPEN_SOURCE_EXTENDED 1
18#ifdef UAL_LEGACY_COMPAT
19#include "ui_ncurses_compat.h"
53const wchar_t *
bw_ra = L"\x2192";
54const wchar_t *
bw_la = L"\x2190";
55const wchar_t *
bw_ua = L"\x2191";
56const wchar_t *
bw_da = L"\x2193";
81
82
91 memset(caps, 0,
sizeof(*caps));
103
104
111 if (pfg == fg && pbg == bg)
119 return (EXIT_FAILURE);
121 rc = init_extended_pair(i, fg, bg);
127 return (EXIT_FAILURE);
135 init_extended_pair(pair, fg, bg);
142 rgb->r = (rgb->r * 1000) / 255;
143 rgb->g = (rgb->g * 1000) / 255;
144 rgb->b = (rgb->b * 1000) / 255;
147 extended_color_content(i, &tmp.r, &tmp.g, &tmp.b);
148 if (rgb->r == tmp.r && rgb->g == tmp.g && rgb->b == tmp.b)
157 init_extended_color(i, rgb->r, rgb->g, rgb->b);
168 extended_color_content(color_idx, &rgb.r, &rgb.g, &rgb.b);
169 rgb.r = (rgb.r * 255) / 1000;
170 rgb.g = (rgb.g * 255) / 1000;
171 rgb.b = (rgb.b * 255) / 1000;
176 sscanf(s,
"#%02x%02x%02x", &rgb.r, &rgb.g, &rgb.b);
180 int _color = (
int)color;
182 extended_color_content(_color, &_r, &_g, &_b);
190 init_extended_color(color, r, g, b);
195 int _pair = (
int)pair;
197 extended_pair_content(_pair, &_fg, &_bg);
203 init_extended_pair(pair, fg, bg);
210 rgb.r = (*color >> 16) & 0xff;
211 rgb.g = (*color >> 8) & 0xff;
212 rgb.b = *color & 0xff;
214 rgb.r = (rgb.r * 1000) / 255;
215 rgb.g = (rgb.g * 1000) / 255;
216 rgb.b = (rgb.b * 1000) / 255;
217 if (color_idx < 16) {
222 init_extended_color(color_idx, rgb.r, rgb.g, rgb.b);
227
228
232 sscanf(fg,
"#%02x%02x%02x", &rgb.r, &rgb.g, &rgb.b);
234 sscanf(bg,
"#%02x%02x%02x", &rgb.r, &rgb.g, &rgb.b);
242 rgb.r = (*fg >> 16) & 0xff;
243 rgb.g = (*fg >> 8) & 0xff;
246 rgb.r = (*bg >> 16) & 0xff;
247 rgb.g = (*bg >> 8) & 0xff;
251 wchar_t wstr[2] = {L'\0', L'\0'};
254 setcchar(&cc, wstr,
WA_NORMAL, cp,
nullptr);
259
260
262 setlocale(LC_ALL,
"");
263 ui = calloc(1,
sizeof(*
ui));
268 strncpy(tty_name, cfg
->tty_path,
sizeof(tty_name) - 1);
269 tty_name[
sizeof(tty_name) - 1] =
'\0';
271 if (ttyname_r(STDERR_FILENO, tty_name,
sizeof(tty_name)) != 0) {
287 set_term(
ui->screen);
289 if (!has_colors() || !can_change_color()) {
294 use_default_colors();
297 keypad(stdscr,
TRUE);
308 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
336 Perror("new_panel failed for stdsfc->mpan[BOX]");
347 for (
int i =
sfc_ptr; i >= 0; i--) {
353 if (
stdsfc->mpan[0] != NULL) {
354 hide_panel(
stdsfc->mpan[0]);
355 del_panel(
stdsfc->mpan[0]);
360 if (
ui->screen != NULL) {
361 delscreen(
ui->screen);
381 if (s->mpan[i] != NULL) {
382 hide_panel(s->mpan[i]);
383 del_panel(s->mpan[i]);
388 if (s->mwin[i] != NULL) {
411
412
414UiSurface *
ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x) {
417 UiSurface *s = calloc(1,
sizeof(*s));
431 if (parent && parent->mwin[p]) {
432 s->mwin[w] = derwin(parent->mwin[p], lines, cols, y, x);
438 s->mwin[w] = newwin(lines, cols, y, x);
443 s->mpan[w] = new_panel(s->mwin[w]);
453UiSurface *
ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x,
char *wtitle) {
454 UiSurface *s = calloc(1,
sizeof(*s));
463 if (parent && parent->mwin[p]) {
464 s->mwin[
BOX] = derwin(parent->mwin[p], lines + 2, cols + 2, y, x);
470 s->mwin[
BOX] = newwin(lines + 2, cols + 2, y, x);
475 s->mpan[
BOX] = new_panel(s->mwin[
BOX]);
477 delwin(s->mwin[
BOX]);
485 immedok(s->mwin[BOX],
true);
495 hide_panel(s->mpan[i]);
496 del_panel(s->mpan[i]);
510 s->mwin[w] = newpad(lines, cols);
511 if (s->mwin[w] ==
nullptr)
513 s->mwin[view_win] = subpad(s->mwin[
PAD], lines, cols, 0, 0);
514 if (s->mwin[view_win] ==
nullptr)
516 s->mpan[w] = new_panel(s->mwin[view_win]);
517 immedok(s->mwin[w],
true);
524 s->mwin[w] = derwin(s->mwin[p], lines, cols, y, x);
529 s->mpan[w] = new_panel(s->mwin[w]);
530 keypad(s->mwin[w],
true);
533 immedok(s->mwin[w],
true);
547 return move_panel(s->mpan[w], y, x);
555 wresize(s->mwin[w], lines + 2, cols + 2);
556 wresize(s->mwin[w + 1], lines, cols);
601 show_panel(s->mpan[w]);
610 top_panel(s->mpan[w]);
617 hide_panel(s->mpan[w]);
630 scrollok(s->mwin[w],
true);
632 scrollok(s->mwin[w],
false);
639 keypad(s->mwin[w],
true);
641 keypad(s->mwin[w],
false);
648 idlok(s->mwin[w],
true);
650 idlok(s->mwin[w],
false);
657 idcok(s->mwin[w],
true);
659 idcok(s->mwin[w],
false);
665 wsetscrreg(s->mwin[w], top, bottom);
668void ui_getyx(UiSurface *s, uint w, uint *lines, uint *cols) {
672 getyx(s->mwin[w], _lines, _cols);
673 *lines = (uint)(_lines);
674 *cols = (uint)(_cols);
679 getmaxyx(s->mwin[w], *lines, *cols);
684 return (
int)(getmaxy(s->mwin[w]));
690 return (
int)(getmaxx(s->mwin[w]));
708 wmove(s->mwin[w], y, x);
710 curs_set(visible ? 1 : 0);
719 curs_set(visible ? 1 : 0);
728 if (!s || !s->mwin[w])
730 return wmove(s->mwin[w], y, x);
732int ui_wmove(UiSurface *s, uint w, uint y, uint x) {
733 if (!s || !s->mwin[w])
735 return wmove(s->mwin[w], y, x);
738 curs_set(visibility);
744 wscrl(s->mwin[w], n);
756 wbkgrnd(s->mwin[w], cell);
763 wbkgrndset(s->mwin[w], cell);
770 wbkgrnd(s->mwin[w], cell);
777 wbkgrndset(s->mwin[w], cell);
781
782
786 getcchar(uc, wstr, attrs, &p, opts);
787 pair = (uint16_t *)&p;
792int ui_setcchar(cchar_t *wch,
const wchar_t *wc,
const attr_t attrs,
short pair,
const void *opts) {
794 return setcchar(wch, wc, attrs, pair, NULL);
797
798
814 wnoutrefresh(s->mwin[w]);
818
819
int ui_cursor_move(UiSurface *s, uint w, uint y, uint x)
UiRuntime * ui_init(const UiConfig *config)
void ui_getyx(UiSurface *s, uint w, uint *lines, uint *cols)
int ui_surface_hide(UiSurface *s, uint w)
int ui_bkgdset(UiSurface *s, uint w, const UiCell *cell)
UiSurface * ui_surface_new(uint w, UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x)
int ui_setscrreg(UiSurface *s, uint w, uint top, uint bottom)
int ui_scrollok(UiSurface *s, uint w, bool enable)
int ui_add_color_rgb(RGB *rgb)
int ui_wclear(UiSurface *s, uint w)
int ui_bkgd(UiSurface *s, uint w, const UiCell *cell)
void ui_surface_destroy(UiSurface *s)
int ui_surface_move(UiSurface *s, uint w, uint y, uint x)
int ui_idlok(UiSurface *s, uint w, bool enable)
int ui_wmove(UiSurface *s, uint w, uint y, uint x)
UiSurface * ui_surface[UI_SFC_MAX]
uint32_t ui_get_color(uint16_t color_idx)
int ui_werase(UiSurface *s, uint w)
void ui_get_screen_size(uint *lines, uint *cols)
void fast_exit(UiSurface *s)
RGB ui_hex_to_rgb(char *s)
int ui_wscrl(UiSurface *s, uint w, int rows)
UiCell ui_cell_from_ucp(const wchar_t *ucp, const uint32_t *fg, const uint32_t *bg)
int ui_curs_set(int visibility)
int ui_top_panel(UiSurface *s, uint w)
int ui_wnoutrefresh(UiSurface *s, uint w)
int ui_surface_resize(UiSurface *s, uint w, uint lines, uint cols)
int ui_surface_show(UiSurface *s, uint w)
UiSurface * ui_box_surface_new(UiSurface *parent, uint p, uint lines, uint cols, uint y, uint x, char *title)
int ui_keypad(UiSurface *s, uint w, bool enable)
int ui_cursor_enable(UiSurface *s, uint w, bool visible)
Disable (visible = false) or enable (visibile = true) the cursor at its current position on the surfa...
int ui_idcok(UiSurface *s, uint w, bool enable)
void ui_get_caps(UiCaps *caps)
Query the capabilities of the active backend.
UiBackend ui_get_backend()
Return which backend is powering this runtime.
int ui_surface_addpad(UiSurface *s, uint w, uint view_win, uint lines, uint cols)
void ui_getmaxyx(UiSurface *s, uint w, uint *lines, uint *cols)
int ui_cursor_enable_yx(UiSurface *s, uint w, uint y, uint x, bool visible)
Disable (visible = false) or enable (visibile = true) the cursor at a specified position on the surfa...
int ui_surface_addwin(UiSurface *s, uint w, uint p, uint lines, uint cols, uint y, uint x)
int ui_chg_color(uint16_t color_idx, uint32_t *color)
PANEL * ui_ncurses_surface_get_panel(const UiSurface *s, uint w)
Return the raw NCurses PANEL* underlying a surface.
int ui_chg_pair(uint pair, uint fg, uint bg)
int ui_pair_content(uint pair, uint *fg, uint *bg)
SCREEN * ui_ncurses_get_screen()
int ui_getmaxx(UiSurface *s, uint w)
int ui_bkgrndset(UiSurface *s, uint w, const UiCell *cell)
int ui_init_color(uint color, uint r, uint g, uint b)
int ui_init_pair(uint pair, uint fg, uint bg)
uint ui_add_pair(uint fg, uint bg)
int ui_getcchar(const UiCell *uc, wchar_t *wstr, attr_t *attrs, uint16_t *pair, void *opts)
int ui_color_content(uint color, uint *r, uint *g, uint *b)
int ui_pair_from_hex(const char *fg, const char *bg)
int ui_getmaxy(UiSurface *s, uint w)
int ui_bkgrnd(UiSurface *s, uint w, const UiCell *cell)
int ui_setcchar(cchar_t *wch, const wchar_t *wc, const attr_t attrs, short pair, const void *opts)
WINDOW * ui_ncurses_surface_get_win(const UiSurface *s, uint w)
Return the raw NCurses WINDOW* underlying a surface.
int border_draw(UiSurface *sfc)
void apply_gamma(RGB *rgb)
Apply gamma correction to RGB color.
int border_title(UiSurface *sfc, char *title)
Draw a box with a title around the specified window.
int Perror(char *emsg_str)
Display a simple error message window or print to stderr.
int display_error(char *msg0, char *msg1, char *msg2, char *msg3)
Display an error message window or print to stderr.
size_t ssnprintf(char *, size_t, const char *,...)
ssnprintf was designed to be a safer alternative to snprintf.
Runtime state for the NotCurses backend.
struct UiSurface * parent
struct UiRuntime * runtime
struct UiSurfaceMeta meta[SUB_SFC_MAX]