2#include "../include/cm.h"
8
9
10
11
12
13
14
15
18
19
20
21
22
23
24
31
32
33
34
35
36
38 UiSurface *s = calloc(1,
sizeof(*s));
49 if (parent && parent
->win) {
71
72
73
85
86
87
88
89
90
96 return move_panel(s
->pan, y, x);
100
101
102
103
104
105
111 return wresize(s
->win, rows, cols);
115
116
117
118
127
128
129
130
139
140
141
142
151
152
153
154
164
165
166
167
168
169
173 return wmove(s
->win, y, x);
176
177
178
179
181 UiRuntime *ui = calloc(1,
sizeof(*ui));
187 if (ttyname_r(STDERR_FILENO, tty_name,
sizeof(tty_name)) != 0) {
188 Perror("ui_init: ttyname_r() failed");
192 tty_fp = fopen(tty_name,
"r+");
201 Perror("ui_init: newterm() failed");
208 Perror("Terminal does not support colors");
211 if (!can_change_color()) {
213 Perror("Terminal cannot change colors");
217 use_default_colors();
220 keypad(stdscr,
TRUE);
229 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
237
238
239
252
253
254
255
256
268
269
270
271
280
281
282
283
291
292
293
294
303
304
305
306
317
318
319
320
321
326 curs_set(visible ? 1 : 0);
330int ui_bkgrnd(UiSurface *s,
const UiStyle *style,
const char *c) {
334 wbkgrnd(s
->win, &cch);
342 wbkgrndset(s
->win, &cch);
346 UiStyle *style = calloc(1,
sizeof(*style));
349 wchar_t wc[2] = {L'\0', L'\0'};
354 getcchar(cch, wc, &attrs, &cpx,
nullptr);
355 style
->bold = (attrs & WA_BOLD) != 0;
356 style
->dim = (attrs & WA_DIM) != 0;
357 style
->italic = (attrs & WA_ITALIC) != 0;
359 style
->blink = (attrs & WA_BLINK) != 0;
360 style
->reverse = (attrs & WA_REVERSE) != 0;
361 style
->invis = (attrs & WA_INVIS) != 0;
362 extended_pair_content(cpx, &fg, &bg);
363 extended_color_content(fg, &rgb
.r, &rgb
.g, &rgb
.b);
364 style
->fg.r = (rgb
.r * 255) / 1000;
365 style
->fg.g = (rgb
.g * 255) / 1000;
366 style
->fg.b = (rgb
.b * 255) / 1000;
367 extended_color_content(bg, &rgb
.r, &rgb
.g, &rgb
.b);
368 style
->bg.r = (rgb
.r * 255) / 1000;
369 style
->bg.g = (rgb
.g * 255) / 1000;
370 style
->bg.b = (rgb
.b * 255) / 1000;
375 UiStyle *style = calloc(1,
sizeof(*style));
398 memset(&mbstate, 0,
sizeof(mbstate));
399 attrs |= style
->bold ? WA_BOLD : 0;
400 attrs |= style
->dim ? WA_DIM : 0;
401 attrs |= style
->italic ? WA_ITALIC : 0;
403 attrs |= style
->blink ? WA_BLINK : 0;
404 attrs |= style
->reverse ? WA_REVERSE : 0;
405 attrs |= style
->invis ? WA_INVIS : 0;
411 const cchar_t cch =
mkcc(cpx
, attrs
, c
);
UiSurface * ui_surface_win[MAXWIN]
UiSurface * ui_surface_box[MAXWIN]
UiSurface * ui_surface_win2[MAXWIN]
int ui_bkgrnd(UiSurface *, const UiStyle *, const char *)
int ui_bkgrnd_set(UiSurface *, const UiStyle *, const char *)
void ui_style_destroy(UiStyle *)
UiStyle * ui_style_from_cch(const cchar_t *)
cchar_t ui_style_to_cch(const UiStyle *, const char *)
int rgb_to_curses_clr(RGB *)
Get color index for RGB color.
cchar_t mkcc(int, attr_t, const char *)
Create a cchar_t with the specified color pair index.
int get_clr_pair(int, int)
Get color pair index for foreground and background colors.
int Perror(char *)
Display a simple error message window or print to stderr.
UiSurface * ui_surface_new(UiRuntime *ui, UiSurface *parent, UiRect rect)
Create a new UI surface.
int ui_surface_hide(UiSurface *s)
Hide a UI surface.
int ui_surface_clear(UiSurface *s)
Clear the contents of a UI surface.
void ui_get_screen_size(UiRuntime *ui, int *rows, int *cols)
Get the current screen size.
int ui_render(UiRuntime *ui)
Render the UI by updating panels and refreshing the screen.
void ui_surface_destroy(UiSurface *s)
Destroy a UI surface and free its resources.
int ui_surface_show(UiSurface *s)
Show a UI surface.
void ui_shutdown(UiRuntime *ui)
Shutdown the UI runtime and free its resources.
int ui_clear_screen(UiRuntime *ui)
Clear the entire screen.
int ui_surface_erase(UiSurface *s)
Erase the contents of a UI surface.
UiRuntime * ui_init(const UiConfig *cfg)
Initialize NCUrses.
int ui_cursor_move(UiSurface *s, int y, int x)
Move the cursor within a UI surface.
int ui_suspend(UiRuntime *ui)
Suspend the UI, restoring the terminal to its normal state.
int ui_resume(UiRuntime *ui)
Resume the UI after being suspended, reinitializing the screen.
int ui_surface_move(UiSurface *s, int y, int x)
Move a UI surface to a new position.
int ui_surface_resize(UiSurface *s, int rows, int cols)
Resize a UI surface to new dimensions.
int ui_cursor_enable(UiRuntime *ui, bool visible)
Enable or disable the cursor visibility.
struct UiSurface * parent
struct UiRuntime * runtime