@hackerrank/astra-cli 0.1.26 → 0.1.28
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/repl.js +28 -12
package/package.json
CHANGED
package/src/repl.js
CHANGED
|
@@ -264,11 +264,14 @@ export function computeVisualLines(buf, promptPrefix, cols = 80) {
|
|
|
264
264
|
|
|
265
265
|
/** Check if an escape sequence or key code is a newline-insertion shortcut (Shift+Enter, Option+Enter, etc.). */
|
|
266
266
|
export function isNewlineKey(s, pendingEsc = false) {
|
|
267
|
-
if (s
|
|
268
|
-
if (
|
|
269
|
-
if (
|
|
270
|
-
if (
|
|
271
|
-
if (s === "\
|
|
267
|
+
if (!s || typeof s !== "string") return false;
|
|
268
|
+
if (/^\x1b\[(?:13|10);[2-8]u$/.test(s)) return true;
|
|
269
|
+
if (/^\x1b\[27;[2-8];(?:13|10)~$/.test(s)) return true;
|
|
270
|
+
if (/^\x1b\[(?:13|10);[2-8]~$/.test(s)) return true;
|
|
271
|
+
if (s === "\x1bOM") return true;
|
|
272
|
+
if (s === "\x1b\r" || s === "\x1b\n" || s === "\x1b\x0d") return true;
|
|
273
|
+
if (pendingEsc && (s === "\r" || s === "\n" || s === "\x0d" || s === "\x0a")) return true;
|
|
274
|
+
if (s === "\x0a" || s === "\n") return true;
|
|
272
275
|
return false;
|
|
273
276
|
}
|
|
274
277
|
|
|
@@ -326,6 +329,8 @@ export class Screen {
|
|
|
326
329
|
this.out.write(`\x1b[1;${this.scrollBottom}r`); // scroll region = top area
|
|
327
330
|
this.out.write(`\x1b[${this.scrollBottom};1H`); // cursor at bottom of scroll area
|
|
328
331
|
this.out.write("\x1b[?2004h"); // enable bracketed paste mode
|
|
332
|
+
this.out.write("\x1b[>4;2m"); // enable modifyOtherKeys
|
|
333
|
+
this.out.write("\x1b[=1u"); // enable kitty keyboard protocol
|
|
329
334
|
if (this.inp.isTTY) this.inp.setRawMode(true);
|
|
330
335
|
this.inp.resume();
|
|
331
336
|
this.inp.setEncoding("utf8");
|
|
@@ -338,6 +343,8 @@ export class Screen {
|
|
|
338
343
|
this.inp.off("data", this._onData);
|
|
339
344
|
this.out.off("resize", this._onResize);
|
|
340
345
|
if (this.inp.isTTY) this.inp.setRawMode(false);
|
|
346
|
+
this.out.write("\x1b[>4;0m"); // disable modifyOtherKeys
|
|
347
|
+
this.out.write("\x1b[=0u"); // disable kitty keyboard protocol
|
|
341
348
|
this.out.write("\x1b[?2004l"); // disable bracketed paste mode
|
|
342
349
|
this.out.write("\x1b[r"); // reset scroll region
|
|
343
350
|
this.out.write(`\x1b[${this.rows};1H\n`); // move below footer
|
|
@@ -352,7 +359,8 @@ export class Screen {
|
|
|
352
359
|
/** Write a block of text into the scrolling region (may contain newlines). */
|
|
353
360
|
log(text) {
|
|
354
361
|
this.out.write(`\x1b[${this.scrollBottom};1H`); // park at bottom of scroll area
|
|
355
|
-
|
|
362
|
+
const formatted = String(text).replace(/\r?\n/g, "\r\n") + "\r\n";
|
|
363
|
+
this.out.write(formatted);
|
|
356
364
|
this.redraw();
|
|
357
365
|
}
|
|
358
366
|
|
|
@@ -371,12 +379,10 @@ export class Screen {
|
|
|
371
379
|
|
|
372
380
|
this.out.write("\x1b[s"); // save cursor
|
|
373
381
|
|
|
374
|
-
// Clear
|
|
375
|
-
|
|
376
|
-
for (let r = clearFrom; r <= this.rows; r++) {
|
|
382
|
+
// Clear only from footerTop down to terminal bottom
|
|
383
|
+
for (let r = this.footerTop; r <= this.rows; r++) {
|
|
377
384
|
this.out.write(`\x1b[${r};1H\x1b[2K`);
|
|
378
385
|
}
|
|
379
|
-
this._prevFooterTop = this.footerTop;
|
|
380
386
|
|
|
381
387
|
// Draw top divider rule at footerTop
|
|
382
388
|
this.out.write(`\x1b[${this.footerTop};1H`);
|
|
@@ -534,6 +540,15 @@ export class Screen {
|
|
|
534
540
|
}
|
|
535
541
|
}
|
|
536
542
|
|
|
543
|
+
// Double-ESC (or second ESC while first is latched) immediately clears input
|
|
544
|
+
if (s === "\x1b\x1b" || (this._pendingEsc && s === "\x1b")) {
|
|
545
|
+
this._clearEscLatch();
|
|
546
|
+
if (this.onClearInput) this.onClearInput();
|
|
547
|
+
this.buf = "";
|
|
548
|
+
this.redraw();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
|
|
537
552
|
// A Tab following a latched ESC -> mode toggle
|
|
538
553
|
if (this._pendingEsc && s === "\t" && this.onToggleMode) {
|
|
539
554
|
this._clearEscLatch();
|
|
@@ -558,7 +573,8 @@ export class Screen {
|
|
|
558
573
|
this._clearEscLatch();
|
|
559
574
|
}
|
|
560
575
|
|
|
561
|
-
// A lone ESC: latch briefly to disambiguate from split escape sequences
|
|
576
|
+
// A lone ESC: latch briefly to disambiguate from split escape sequences.
|
|
577
|
+
// If no other key arrives within 80ms, clear the input buffer.
|
|
562
578
|
if (s === "\x1b") {
|
|
563
579
|
this._pendingEsc = true;
|
|
564
580
|
clearTimeout(this._escTimer);
|
|
@@ -567,7 +583,7 @@ export class Screen {
|
|
|
567
583
|
if (this.onClearInput) this.onClearInput();
|
|
568
584
|
this.buf = "";
|
|
569
585
|
this.redraw();
|
|
570
|
-
},
|
|
586
|
+
}, 80);
|
|
571
587
|
return;
|
|
572
588
|
}
|
|
573
589
|
|