@noobdemon/noob-cli 1.8.0 → 1.8.1
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/package.json +1 -1
- package/src/tui.js +13 -5
package/package.json
CHANGED
package/src/tui.js
CHANGED
|
@@ -213,6 +213,10 @@ export function createTui({ onLine, onInterrupt, onEOF, onShiftTab, completer }
|
|
|
213
213
|
// thêm "…".
|
|
214
214
|
let cursorScreenCol = 0;
|
|
215
215
|
let cursorScreenRow = 0;
|
|
216
|
+
let barRows = 1; // số dòng bar hiện tại; cập nhật bởi renderBar. placeCursor
|
|
217
|
+
// dùng để tính upBy — KHÔNG dùng totalRows (gồm cả top/menu
|
|
218
|
+
// rows phía trên) vì sẽ kéo cursor lên quá cao, lần commit
|
|
219
|
+
// kế tiếp ESC[J xóa luôn spinner+bar+dòng response trên cùng.
|
|
216
220
|
function renderBar() {
|
|
217
221
|
const promptW = visLen(promptLabel);
|
|
218
222
|
const budget = Math.max(4, cols() - promptW - 1);
|
|
@@ -226,6 +230,7 @@ export function createTui({ onLine, onInterrupt, onEOF, onShiftTab, completer }
|
|
|
226
230
|
|
|
227
231
|
// Vừa khung → 1 dòng như cũ, con trỏ map thẳng.
|
|
228
232
|
if (total <= budget) {
|
|
233
|
+
barRows = 1;
|
|
229
234
|
cursorScreenRow = 0;
|
|
230
235
|
cursorScreenCol = promptW + curCharPos;
|
|
231
236
|
return promptLabel + coloredInput();
|
|
@@ -275,6 +280,7 @@ export function createTui({ onLine, onInterrupt, onEOF, onShiftTab, completer }
|
|
|
275
280
|
const colInLine = Math.min(curCharPos - acc, lines[curLine].length);
|
|
276
281
|
cursorScreenRow = curLine;
|
|
277
282
|
cursorScreenCol = promptW + colInLine;
|
|
283
|
+
barRows = lines.length;
|
|
278
284
|
|
|
279
285
|
return lines.map((l, i) => (i === 0 ? promptLabel : indent) + l).join("\n");
|
|
280
286
|
}
|
|
@@ -341,16 +347,18 @@ export function createTui({ onLine, onInterrupt, onEOF, onShiftTab, completer }
|
|
|
341
347
|
// Sau khi vẽ xong các hàng, con trỏ đang ở CUỐI thanh (hàng cuối, cột cuối).
|
|
342
348
|
// Đưa về đúng (row, col) của con trỏ logic: \r về cột 0 → đi lên `upBy` hàng
|
|
343
349
|
// (nếu thanh wrap nhiều dòng) → dịch phải `cursorScreenCol` cột.
|
|
344
|
-
|
|
345
|
-
|
|
350
|
+
// upBy dùng `barRows` (số dòng BAR, set bởi renderBar) — KHÔNG dùng totalRows
|
|
351
|
+
// (gồm cả top/menu rows phía trên bar) vì sẽ kéo cursor lên quá cao.
|
|
352
|
+
const placeCursor = () => {
|
|
353
|
+
const upBy = barRows - 1 - cursorScreenRow;
|
|
346
354
|
let s = "\r";
|
|
347
355
|
if (upBy > 0) s += `${ESC}[${upBy}A`;
|
|
348
356
|
if (cursorScreenCol > 0) s += `${ESC}[${cursorScreenCol}C`;
|
|
349
357
|
return s;
|
|
350
358
|
};
|
|
351
359
|
function draw() {
|
|
352
|
-
const rs = rows(); // rows() → renderBar() cập nhật cursorScreenRow/Col
|
|
353
|
-
w(`${ESC}[?25l` + eraseSeq() + rs.join("\n") + placeCursor(
|
|
360
|
+
const rs = rows(); // rows() → renderBar() cập nhật cursorScreenRow/Col + barRows
|
|
361
|
+
w(`${ESC}[?25l` + eraseSeq() + rs.join("\n") + placeCursor() + `${ESC}[?25h`);
|
|
354
362
|
prevRows = rs.length;
|
|
355
363
|
drawn = true;
|
|
356
364
|
}
|
|
@@ -360,7 +368,7 @@ export function createTui({ onLine, onInterrupt, onEOF, onShiftTab, completer }
|
|
|
360
368
|
let s = `${ESC}[?25l` + eraseSeq();
|
|
361
369
|
s += block;
|
|
362
370
|
if (!block.endsWith("\n")) s += "\n";
|
|
363
|
-
s += rs.join("\n") + placeCursor(
|
|
371
|
+
s += rs.join("\n") + placeCursor() + `${ESC}[?25h`;
|
|
364
372
|
w(s);
|
|
365
373
|
prevRows = rs.length;
|
|
366
374
|
drawn = true;
|