mirror of
https://github.com/xcat2/confluent.git
synced 2024-12-25 12:41:39 +00:00
Improve VT dump behavior
Ensure the resultant dump has consistently long lines. This will matter when we start rendering attributes on blanks. Additionally, simplify the code significantly taking advantage of first loop.
This commit is contained in:
parent
beab6a3c02
commit
03eb026b61
@ -1,4 +1,4 @@
|
||||
vtbufferd:
|
||||
vtbufferd: vtbufferd.c tmt.c
|
||||
gcc -O3 -o vtbufferd vtbufferd.c tmt.c
|
||||
|
||||
clean:
|
||||
|
@ -56,38 +56,26 @@ TMT *set_termentbyname(char *name) {
|
||||
void dump_vt(TMT* outvt) {
|
||||
const TMTSCREEN *out = tmt_screen(outvt);
|
||||
const TMTPOINT *curs = tmt_cursor(outvt);
|
||||
int line, idx, deferredlines, deferredspaces;
|
||||
bool printedline, skipnl;
|
||||
int line, idx, maxcol, maxrow;
|
||||
wprintf(L"\033[H\033[J");
|
||||
deferredlines = 0;
|
||||
skipnl = true;
|
||||
for (line = 0; line < out->nline; line++) {
|
||||
deferredspaces = 0;
|
||||
printedline = false;
|
||||
for (idx = 0; idx < out->ncol; idx++) {
|
||||
if (out->lines[line]->chars[idx].c == L' ') {
|
||||
deferredspaces += 1;
|
||||
} else {
|
||||
if (!printedline) {
|
||||
printedline = true;
|
||||
if (skipnl)
|
||||
skipnl = false;
|
||||
else
|
||||
wprintf(L"\r\n");
|
||||
}
|
||||
while (deferredlines) {
|
||||
wprintf(L"\r\n");
|
||||
deferredlines -= 1;
|
||||
}
|
||||
while (deferredspaces > 0) {
|
||||
wprintf(L" ");
|
||||
deferredspaces -= 1;
|
||||
}
|
||||
wprintf(L"%lc", out->lines[line]->chars[idx].c);
|
||||
maxcol = 0;
|
||||
maxrow = 0;
|
||||
for (line = out->nline - 1; line >= 0; --line) {
|
||||
for (idx = out->ncol - 1; idx > maxcol; --idx) {
|
||||
if (out->lines[line]->chars[idx].c != L' ') {
|
||||
if (maxrow < line)
|
||||
maxrow = line;
|
||||
maxcol = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!printedline)
|
||||
deferredlines += 1;
|
||||
}
|
||||
for (line = 0; line <= maxrow; line++) {
|
||||
for (idx = 0; idx <= maxcol; idx++) {
|
||||
wprintf(L"%lc", out->lines[line]->chars[idx].c);
|
||||
}
|
||||
if (line < maxrow)
|
||||
wprintf(L"\r\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
wprintf(L"\x1b[%ld;%ldH", curs->r + 1, curs->c + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user