acuvo-code 0.4.0 → 0.4.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/lib/input-box.mjs +30 -3
- package/package.json +1 -1
package/lib/input-box.mjs
CHANGED
|
@@ -213,10 +213,37 @@ export function splitKeys(chunk) {
|
|
|
213
213
|
*/
|
|
214
214
|
export function paint(output, state, { first = false } = {}) {
|
|
215
215
|
const { lines, cursorColumn } = renderBox(state);
|
|
216
|
-
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* ── ⚠️⚠️ THE CURSOR MATH, AND MY FIRST VERSION ATE THE SCREEN ──────────────
|
|
219
|
+
*
|
|
220
|
+
* Roman: *"it moves upwards every time you type a character then deletes the
|
|
221
|
+
* design you did."* Exactly right, and the arithmetic says why.
|
|
222
|
+
*
|
|
223
|
+
* After a paint the cursor rests on the INPUT line — line 2 of 3, not below
|
|
224
|
+
* the box. The first version began each repaint with `ESC[3A`, which is where
|
|
225
|
+
* it would be if the cursor were below. From line 2, moving up 3 lands ONE
|
|
226
|
+
* LINE ABOVE the top border — and the `ESC[0J` that follows clears from there
|
|
227
|
+
* to the bottom of the screen. So every keystroke crept upward and erased
|
|
228
|
+
* another line of the banner.
|
|
229
|
+
*
|
|
230
|
+
* ⭐ THE INVARIANT, WRITTEN DOWN BECAUSE IT IS THE WHOLE FUNCTION: this
|
|
231
|
+
* routine ENTERS with the cursor on the input line and LEAVES it there. So a
|
|
232
|
+
* repaint moves up exactly ONE line to reach the top border, and the final
|
|
233
|
+
* reposition moves up exactly one from the last line written.
|
|
234
|
+
*
|
|
235
|
+
* ╭────────╮ <- line 1 ESC[1A from the input line reaches here
|
|
236
|
+
* │› … │ <- line 2 cursor lives here, in and out
|
|
237
|
+
* ╰────────╯ <- line 3 cursor is here after writing; ESC[1A returns
|
|
238
|
+
*
|
|
239
|
+
* ⚠️ NO TRAILING NEWLINE. Writing one after the last border scrolls the
|
|
240
|
+
* viewport when the box is at the bottom of the screen, and every subsequent
|
|
241
|
+
* `up` is then off by a row for the rest of the session.
|
|
242
|
+
*/
|
|
243
|
+
const home = first ? '' : `\r${CSI}1A`;
|
|
217
244
|
output.write(
|
|
218
|
-
`${CSI}?25l${
|
|
219
|
-
`${CSI}
|
|
245
|
+
`${CSI}?25l${home}${CSI}0J${lines.join('\n')}` +
|
|
246
|
+
`${CSI}1A\r${CSI}${cursorColumn}G${CSI}?25h`,
|
|
220
247
|
);
|
|
221
248
|
}
|
|
222
249
|
|