brito-cli 0.7.2 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/dock.js +55 -3
- package/package.json +1 -1
package/dist/ui/dock.js
CHANGED
|
@@ -23,6 +23,8 @@ export class Dock {
|
|
|
23
23
|
skipNL = false;
|
|
24
24
|
top = 1;
|
|
25
25
|
height = 0;
|
|
26
|
+
lastWidths = [];
|
|
27
|
+
lastCursor = { line: 0, col: 1 };
|
|
26
28
|
spinner = null;
|
|
27
29
|
busy = false;
|
|
28
30
|
promptOverride = null;
|
|
@@ -40,12 +42,59 @@ export class Dock {
|
|
|
40
42
|
dsr;
|
|
41
43
|
started = false;
|
|
42
44
|
onData = (d) => this.feed(d);
|
|
45
|
+
resizeTimer;
|
|
46
|
+
reflowing = false;
|
|
47
|
+
reflowAgain = false;
|
|
43
48
|
onResize = () => {
|
|
44
49
|
this.rows = process.stdout.rows || 24;
|
|
45
50
|
this.cols = process.stdout.columns || 80;
|
|
46
51
|
this.outRow = Math.min(this.outRow, this.rows);
|
|
47
|
-
|
|
52
|
+
clearTimeout(this.resizeTimer);
|
|
53
|
+
this.resizeTimer = setTimeout(() => void this.reflow(), 40);
|
|
48
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* O terminal re-quebra (reflow) o que já está na tela ao redimensionar: réguas largas viram 2 linhas
|
|
57
|
+
* e as posições guardadas ficam inválidas. Perguntamos onde o cursor foi parar, deduzimos onde o dock
|
|
58
|
+
* começa agora, apagamos dali para baixo e repintamos.
|
|
59
|
+
*/
|
|
60
|
+
async reflow() {
|
|
61
|
+
if (!this.started)
|
|
62
|
+
return;
|
|
63
|
+
if (this.reflowing) {
|
|
64
|
+
this.reflowAgain = true;
|
|
65
|
+
return;
|
|
66
|
+
} // um DSR por vez; refaz ao terminar
|
|
67
|
+
this.reflowing = true;
|
|
68
|
+
try {
|
|
69
|
+
do {
|
|
70
|
+
this.reflowAgain = false;
|
|
71
|
+
await this.reflowOnce();
|
|
72
|
+
} while (this.reflowAgain && this.started);
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
this.reflowing = false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async reflowOnce() {
|
|
79
|
+
const pos = await this.getCursor(true);
|
|
80
|
+
if (!this.started)
|
|
81
|
+
return;
|
|
82
|
+
if (!pos) {
|
|
83
|
+
process.stdout.write(this.paintSeq(false));
|
|
84
|
+
return;
|
|
85
|
+
} // sem resposta do terminal: não chuta posição
|
|
86
|
+
const [r] = pos;
|
|
87
|
+
const wrap = (w) => Math.max(1, Math.ceil(w / this.cols));
|
|
88
|
+
const above = this.lastWidths.slice(0, this.lastCursor.line).reduce((n, w) => n + wrap(w), 0)
|
|
89
|
+
+ Math.floor(Math.max(0, this.lastCursor.col - 1) / this.cols);
|
|
90
|
+
const top = Math.max(1, Math.min(this.rows, r - above));
|
|
91
|
+
this.outRow = top;
|
|
92
|
+
this.outCol = 1;
|
|
93
|
+
this.skipNL = false;
|
|
94
|
+
this.top = top;
|
|
95
|
+
this.height = 0;
|
|
96
|
+
process.stdout.write(`\x1b[${top};1H\x1b[J` + this.paintSeq(true));
|
|
97
|
+
}
|
|
49
98
|
constructor(opts) {
|
|
50
99
|
this.opts = opts;
|
|
51
100
|
if (opts.historyFile) {
|
|
@@ -83,6 +132,7 @@ export class Dock {
|
|
|
83
132
|
this.restoreTerminal();
|
|
84
133
|
process.stdin.off("data", this.onData);
|
|
85
134
|
process.stdout.off("resize", this.onResize);
|
|
135
|
+
clearTimeout(this.resizeTimer);
|
|
86
136
|
process.stdin.pause();
|
|
87
137
|
}
|
|
88
138
|
restoreTerminal() {
|
|
@@ -92,9 +142,9 @@ export class Dock {
|
|
|
92
142
|
}
|
|
93
143
|
catch { /* já fechado */ }
|
|
94
144
|
}
|
|
95
|
-
getCursor() {
|
|
145
|
+
getCursor(strict = false) {
|
|
96
146
|
return new Promise((resolve) => {
|
|
97
|
-
const t = setTimeout(() => { this.dsr = undefined; resolve([this.rows, 1]); }, 400);
|
|
147
|
+
const t = setTimeout(() => { this.dsr = undefined; resolve(strict ? null : [this.rows, 1]); }, 400);
|
|
98
148
|
this.dsr = (r, col) => { clearTimeout(t); this.dsr = undefined; resolve([r, col]); };
|
|
99
149
|
process.stdout.write("\x1b[6n");
|
|
100
150
|
});
|
|
@@ -316,6 +366,8 @@ export class Dock {
|
|
|
316
366
|
}
|
|
317
367
|
this.top = base;
|
|
318
368
|
this.height = h;
|
|
369
|
+
this.lastWidths = visibleLines.map((l) => Math.min(stringWidth(stripAnsi(l)), this.cols));
|
|
370
|
+
this.lastCursor = { line: Math.max(0, Math.min(h - 1, cursor.row - (out.length - h) - 1)), col: Math.min(cursor.col, this.cols) };
|
|
319
371
|
const row = base + cursor.row - (out.length - h);
|
|
320
372
|
s += `\x1b[${Math.min(row, this.rows)};${Math.min(cursor.col, this.cols)}H`;
|
|
321
373
|
return s;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brito-cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Coding-agent CLI with a code knowledge graph, memory and reviewable skills / CLI de agente de código com grafo de conhecimento, memória e skills revisáveis",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|