libk8sterm: rewritten ESC sequences parsing (some code cleanups, on-the-fly parsing...
[k8sterm.git] / src / x11drawcmdline.c
blob647301e615a06f14c708ce276c3ff7d18470da8a
1 static void xdrawcmdline (K8Term *term, K8TCmdLine *cmdline, int scry) {
2 K8TGlyph base;
3 int cpos = cmdline->cmdofs, bc = 0, x, sx;
4 int back = (cmdline->cmdMode == K8T_CMDMODE_INPUT ? 21 : 124);
5 int rslen = (cmdline->cmdMode == K8T_CMDMODE_INPUT ? cmdline->cmdreslen : 32760);
6 //
7 base.attr = K8T_ATTR_NORMAL|K8T_ATTR_FGSET|K8T_ATTR_BGSET;
8 base.fg = 255;
9 base.bg = back;
10 base.state = 0;
11 // hilighted
12 for (sx = x = 0; x < term->col && cmdline->cmdline[cpos] && cpos < rslen; ++x) {
13 int l = k8t_UTF8Size(cmdline->cmdline+cpos);
15 if (bc+l > K8T_DRAW_BUF_SIZ) {
16 k8t_drawString(term, term->drawbuf, &base, sx, scry, x-sx, bc);
17 bc = 0;
18 sx = x;
20 memcpy(term->drawbuf+bc, cmdline->cmdline+cpos, l);
21 cpos += l;
22 bc += l;
24 if (bc > 0) k8t_drawString(term, term->drawbuf, &base, sx, scry, x-sx, bc);
25 // user input
26 bc = 0;
27 base.fg = 220;
28 for (sx = x; x < term->col && cmdline->cmdline[cpos]; ++x) {
29 int l = k8t_UTF8Size(cmdline->cmdline+cpos);
31 if (bc+l > K8T_DRAW_BUF_SIZ) {
32 k8t_drawString(term, term->drawbuf, &base, sx, scry, x-sx, bc);
33 bc = 0;
34 sx = x;
36 memcpy(term->drawbuf+bc, cmdline->cmdline+cpos, l);
37 cpos += l;
38 bc += l;
40 if (bc > 0) k8t_drawString(term, term->drawbuf, &base, sx, scry, x-sx, bc);
42 if (x < term->col && cmdline->cmdMode == K8T_CMDMODE_INPUT) {
43 base.bg = base.fg;
44 base.fg = back;
45 k8t_drawString(term, " ", &base, x, scry, 1, 1);
46 ++x;
49 if (x < term->col) {
50 base.fg = 255;
51 base.bg = back;
52 memset(term->drawbuf, ' ', K8T_DRAW_BUF_SIZ);
53 while (x < term->col) {
54 sx = x;
55 x += K8T_DRAW_BUF_SIZ;
56 if (x > term->col) x = term->col;
57 k8t_drawString(term, term->drawbuf, &base, sx, scry, x-sx, x-sx);
61 k8t_drawCopy(term, 0, scry, term->col, 1);