2
3
4
5
6
7
9#define _XOPEN_SOURCE_EXTENDED 1
22
23
28 wclrtobot(s->mwin[w]);
34 wclrtoeol(s->mwin[w]);
38
39
43 mvwaddch(s->mwin[w], y, x, c);
47int ui_draw_text(UiSurface *s, uint w, uint y, uint x,
const char *text) {
50 mvwaddstr(s->mwin[w], y, x, text);
54int ui_draw_text_n(UiSurface *s, uint w, uint y, uint x,
const char *text,
int n) {
57 mvwaddnstr(s->mwin[w], y, x, text, (
int)n);
64 uint l = strlen(text);
66 char *tmp_str = (
char *)malloc(n + 1);
69 strcpy(tmp_str, text);
70 for (
int i = l; i < (
int)n; i++) {
74 mvwaddstr(s->mwin[w], y, x, tmp_str);
77 mvwaddnstr(s->mwin[w], y, x, text, (
int)n);
87 waddwstr(s->mwin[w], wstr);
90int ui_mvwaddwstr(UiSurface *s, uint w, uint y, uint x,
const wchar_t *wstr) {
93 mvwaddwstr(s->mwin[w], y, x, wstr);
96int ui_waddnwstr(UiSurface *s, uint w,
const wchar_t *wstr,
int m) {
99 waddnwstr(s->mwin[w], wstr, m);
102int ui_mvwaddnwstr(UiSurface *s, uint w, uint y, uint x,
const wchar_t *wstr,
int m) {
105 mvwaddnwstr(s->mwin[w], y, x, wstr, m);
114 waddstr(s->mwin[w], text);
118int ui_mvaddstr(UiSurface *s, uint w, uint y, uint x,
const char *text) {
121 mvwaddstr(s->mwin[w], y, x, text);
125int ui_mvwaddch(UiSurface *s, uint w, uint y, uint x,
const char c) {
128 mvwaddch(s->mwin[w], y, x, c);
132int ui_mvwaddstr(UiSurface *s, uint w, uint y, uint x,
const char *text) {
135 mvwaddstr(s->mwin[w], y, x, text);
138int ui_mvwaddnstr(UiSurface *s, uint w, uint y, uint x,
const char *text,
int m) {
141 mvwaddnstr(s->mwin[w], y, x, text, m);
149 getmaxyx(s->mwin[w], maxy, maxx);
156 if (*str ==
'\0' || *str ==
'\n')
163 mvwaddnstr(s->mwin[w], y, x, tmp_str, m);
172 wadd_wchnstr(s->mwin[w], cell, 1);
178 mvwadd_wch(s->mwin[w], y, x, cell);
182 if (!s || !cmplx_buf)
184 wadd_wchstr(s->mwin[w], cmplx_buf);
189 if (!s || !cmplx_buf)
191 mvwadd_wchstr(s->mwin[w], y, x, cmplx_buf);
196 if (!s || !cmplx_buf)
198 wadd_wchnstr(s->mwin[w], cmplx_buf, n);
202 if (!s || !cmplx_buf)
204 mvwadd_wchnstr(s->mwin[w], y, x, cmplx_buf, n);
208
209
212 for (
int s = 0; s <=
sfc_ptr; s++) {
220
221
226 uint i = 0, j = 0, x = 0;
234 wchar_t wstr[2] = {L'\0', L'\0'};
235 UiCell *cmplx_buf = cmplx_buf_s;
237 memset(&mbstate, 0,
sizeof(mbstate));
238 while (in_str[i] !=
'\0') {
240 if (in_str[i] ==
'\033') {
241 if (in_str[i + 1] ==
'[') {
242 len = strcspn(&in_str[i],
"mK ") + 1;
243 memcpy(ansi_tok, &in_str[i], len + 1);
244 ansi_tok[len] =
'\0';
245 if (ansi_tok[0] ==
'\0') {
250 if (len == 0 || in_str[i + len - 1] ==
' ') {
253 }
else if (in_str[i + len - 1] ==
'K') {
264 if (in_str[i] ==
' ') {
267 setcchar(&cc, wstr, attr, cpx,
nullptr);
273 if (in_str[i] ==
'\0') {
276 if (in_str[i] ==
'\t') {
277 tab_spaces = tab_stop - j % tab_stop;
280 setcchar(&cc, wstr, attr, cpx,
nullptr);
281 for (uint z = 0; z < tab_spaces; z++) {
289 len = mbrtowc(wstr, &in_str[i], MB_CUR_MAX, &mbstate);
295 char_width = wcwidth(wstr[0]);
297 setcchar(&cc, wstr, attr, cpx,
nullptr);
306 setcchar(&cc, wstr,
WA_NORMAL, cpx,
nullptr);
317 int _fg_clr, _bg_clr;
319 char *ansi_p = ansi_str + 2;
320 extended_pair_content(*cpx, &_fg_clr, &_bg_clr);
321 fg = fg_clr = (uint)_fg_clr;
322 bg = fg_clr = (uint)_bg_clr;
324 tok = strtok((
char *)ansi_p,
";m");
325 bool a_toi_error =
false;
327 if (tok ==
nullptr || *tok ==
'\0')
333 if (t0 ==
'3' || t0 ==
'4') {
335 tok = strtok(
nullptr,
";m");
336 if (tok !=
nullptr) {
338 tok = strtok(
nullptr,
";m");
339 if (tok !=
nullptr) {
343 }
else if (*tok ==
'2') {
344 tok = strtok(
nullptr,
";m");
346 tok = strtok(
nullptr,
";m");
348 tok = strtok(
nullptr,
";m");
356 }
else if (t1 ==
'9') {
361 }
else if (t1 >=
'0' && t1 <=
'7') {
368 }
else if (t0 ==
'4') {
376 }
else if (t0 ==
'0') {
413 }
else if (len == 0) {
418 tok = strtok(
nullptr,
";m");
420 if (!a_toi_error && (fg_clr != fg || bg_clr != bg))
#define min(x, y)
min macro evaluates two expressions, returning least result
int ui_wadd_wch(UiSurface *s, uint w, const UiCell *cell)
int ui_draw_ch_yx(UiSurface *s, uint w, uint y, uint x, const char c)
int ui_wclrtobot(UiSurface *s, uint w)
int ui_mvwadd_wchstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_mvwaddnstr(UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_mvwaddstr(UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_wadd_wchnstr(UiSurface *s, uint w, const UiCell *cell, uint m)
int ui_add_color_rgb(RGB *rgb)
int ui_mvwaddnwstr(UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr, int m)
int ui_draw_text_n(UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_mvwadd_wchnstr(UiSurface *s, uint w, uint y, uint x, const UiCell *cell, uint m)
int ui_mvwaddch(UiSurface *s, uint w, uint y, uint x, const char c)
int ui_draw_text(UiSurface *s, uint w, uint y, uint x, const char *text)
int ui_waddnwstr(UiSurface *s, uint w, const wchar_t *wstr, int m)
int ui_mvaddstr(UiSurface *s, uint w, uint y, uint x, const char *text)
UiSurface * ui_surface[UI_SFC_MAX]
int ui_draw_text_fill(UiSurface *s, uint w, uint y, uint x, const char *text, int m)
int ui_waddstr(UiSurface *s, uint w, const char *text)
int ui_wclrtoeol(UiSurface *s, uint w)
int ui_wadd_wchstr(UiSurface *s, uint w, const UiCell *cell)
int ui_mvwadd_wch(UiSurface *s, uint w, uint y, uint x, const UiCell *cell)
int ui_mvwaddwstr(UiSurface *s, uint w, uint y, uint x, const wchar_t *wstr)
int ui_mvwaddstr_fill(UiSurface *s, uint w, uint y, uint x, const char *str, int m)
int ui_waddwstr(UiSurface *s, uint w, const wchar_t *wstr)
uint ui_add_pair(uint fg, uint bg)
int mbstr_to_cc(char *in_str, UiCell *cmplx_buf_s)
Convert a multibyte string to a complex character array.
void parse_ansi(char *ansi_str, attr_t *attr, uint *cpx)
Parse an ANSI SGR sequence and update attributes and color pair index.
RGB xterm256_idx_to_rgb(uint idx)
Convert XTerm 256 color index to RGB.
int a_toi(char *, bool *)
a safer alternative to atoi() for converting ASCII strings to integers.