diff --git a/confluent_vtbufferd/tmt.c b/confluent_vtbufferd/tmt.c index 19569281..76b7e700 100644 --- a/confluent_vtbufferd/tmt.c +++ b/confluent_vtbufferd/tmt.c @@ -310,7 +310,7 @@ handlechar(TMT *vt, char i) DO(S_ARG, "P", dch(vt)) DO(S_ARG, "S", scrup(vt, 0, P1(0))) DO(S_ARG, "T", scrdn(vt, 0, P1(0))) - DO(S_ARG, "X", clearline(vt, l, c->c, P1(0))) + DO(S_ARG, "X", clearline(vt, l, c->c, P1(0) + c->c)) DO(S_ARG, "Z", while (c->c && t[--c->c].c != L'*')) DO(S_ARG, "b", rep(vt)); DO(S_ARG, "c", CB(vt, TMT_MSG_ANSWER, "\033[?6c")) diff --git a/confluent_vtbufferd/tmt.h b/confluent_vtbufferd/tmt.h index ae0ddbb9..d3487f18 100644 --- a/confluent_vtbufferd/tmt.h +++ b/confluent_vtbufferd/tmt.h @@ -65,7 +65,7 @@ typedef struct TMT TMT; typedef enum{ - TMT_COLOR_DEFAULT = -1, + TMT_COLOR_DEFAULT = 0, TMT_COLOR_BLACK = 1, TMT_COLOR_RED, TMT_COLOR_GREEN, diff --git a/confluent_vtbufferd/vtbufferd.c b/confluent_vtbufferd/vtbufferd.c index 9d6b085f..a77e2be1 100644 --- a/confluent_vtbufferd/vtbufferd.c +++ b/confluent_vtbufferd/vtbufferd.c @@ -57,7 +57,19 @@ void dump_vt(TMT* outvt) { const TMTSCREEN *out = tmt_screen(outvt); const TMTPOINT *curs = tmt_cursor(outvt); int line, idx, maxcol, maxrow; - wprintf(L"\033[H\033[J"); + bool bold = false; + bool dim = false; + bool underline = false; + bool blink = false; + bool reverse = false; + bool invisible = false; + bool intensitychg = false; + tmt_color_t fg = TMT_COLOR_DEFAULT; + tmt_color_t bg = TMT_COLOR_DEFAULT; + wchar_t sgrline[30]; + size_t srgidx = 0; + char colorcode = 0; + wprintf(L"\033c"); maxcol = 0; maxrow = 0; for (line = out->nline - 1; line >= 0; --line) { @@ -72,6 +84,72 @@ void dump_vt(TMT* outvt) { } for (line = 0; line <= maxrow; line++) { for (idx = 0; idx <= maxcol; idx++) { + sgrline[0] = L'\x00'; + intensitychg = false; + if (out->lines[line]->chars[idx].a.bold != bold) { + bold = out->lines[line]->chars[idx].a.bold; + intensitychg = true; // Can't unbold without changing dim + } + if (out->lines[line]->chars[idx].a.dim != dim) { + dim = out->lines[line]->chars[idx].a.dim; + intensitychg = true; // Can't undim without changing bold + } + if (intensitychg) { + intensitychg = false; + wcscat(sgrline, L"22;"); + if (bold) + wcscat(sgrline, L"1;"); + if (dim) + wcscat(sgrline, L"2;"); + } + if (out->lines[line]->chars[idx].a.underline != underline) { + underline = out->lines[line]->chars[idx].a.underline; + if (underline) + wcscat(sgrline, L"4;"); + else + wcscat(sgrline, L"24;"); + } + if (out->lines[line]->chars[idx].a.blink != blink) { + blink = out->lines[line]->chars[idx].a.blink; + if (blink) + wcscat(sgrline, L"5;"); + else + wcscat(sgrline, L"25;"); + } + if (out->lines[line]->chars[idx].a.reverse != reverse) { + reverse = out->lines[line]->chars[idx].a.reverse; + if (reverse) + wcscat(sgrline, L"7;"); + else + wcscat(sgrline, L"27;"); + } + if (out->lines[line]->chars[idx].a.invisible != invisible) { + invisible = out->lines[line]->chars[idx].a.invisible; + if (invisible) + wcscat(sgrline, L"8;"); + else + wcscat(sgrline, L"28;"); + } + if (out->lines[line]->chars[idx].a.fg != fg) { + fg = out->lines[line]->chars[idx].a.fg; + if (fg == TMT_COLOR_DEFAULT) + colorcode = 39; + else + colorcode = 29 + fg; + swprintf(sgrline + wcslen(sgrline), 4, L"%d;", colorcode); + } + if (out->lines[line]->chars[idx].a.bg != bg) { + bg = out->lines[line]->chars[idx].a.bg; + if (bg == TMT_COLOR_DEFAULT) + colorcode = 49; + else + colorcode = 39 + bg; + swprintf(sgrline + wcslen(sgrline), 4, L"%d;", colorcode); + } + if (sgrline[0] != 0) { + sgrline[wcslen(sgrline) - 1] = 0; // Trim last ; + wprintf(L"\033[%lsm", sgrline); + } wprintf(L"%lc", out->lines[line]->chars[idx].c); } if (line < maxrow)