Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

handle vertical tab and backspace escape characters (#7313)

Cosmo Grant258e894ccad7
diff --git a/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts b/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts
index dea92045f9..07c316937a 100644
--- a/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts
+++ b/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts
@@ -55,6 +55,34 @@ describe("TerminalBuffer", () => {
expect(buffer.render()).toMatchInlineSnapshot(`"a b"`);
});
+ test("control handles vertical tab", () => {
+ const buffer = new TerminalBuffer();
+ buffer.writeChar("a");
+ buffer.writeChar("b");
+ buffer.control("\v");
+ buffer.writeChar("c");
+ expect(buffer.render()).toMatchInlineSnapshot(`
+ "ab
+ c"
+ `); // This means we expect the "c" to be the column _after_ the "b"
+ });
+
+ test("control handles backspace", () => {
+ const buffer = new TerminalBuffer();
+ buffer.writeChar("a");
+ buffer.writeChar("b");
+ buffer.control("\b");
+ buffer.writeChar("X");
+ expect(buffer.render()).toMatchInlineSnapshot(`"aX"`);
+ });
+
+ test("control handles backspace at start of line", () => {
+ const buffer = new TerminalBuffer();
+ buffer.control("\b");
+ buffer.writeChar("a");
+ expect(buffer.render()).toMatchInlineSnapshot(`"a"`);
+ });
+
test("control handles carriage return", () => {
const buffer = new TerminalBuffer();
buffer.writeChar("a");
diff --git a/frontend/src/components/editor/output/ansi-reduce.ts b/frontend/src/components/editor/output/ansi-reduce.ts
index a6d3eff17e..dc18573d99 100644
--- a/frontend/src/components/editor/output/ansi-reduce.ts
+++ b/frontend/src/components/editor/output/ansi-reduce.ts
@@ -69,7 +69,7 @@ export class TerminalBuffer {
this.cursor.col += str.length;
}
- /** Handle simple control characters (\n, \r, \t). */
+ /** Handle simple control characters (\n, \r, \t, \b, \v). */
control(ch: string) {
switch (ch) {
case "\n":
@@ -83,6 +83,13 @@ export class TerminalBuffer {
case "\t":
this.writeChar("\t");
break;
+ case "\b":
+ this.cursor.col = Math.max(0, this.cursor.col - 1);
+ break;
+ case "\v":
+ this.cursor.row++;
+ this.ensureLine(this.cursor.row);
+ break;
}
}
@@ -271,11 +278,17 @@ export class AnsiReducer {
const ch = text[i];
// Handle control characters
- if (ch === "\n" || ch === "\r" || ch === "\t") {
+ if (
+ ch === "\n" ||
+ ch === "\r" ||
+ ch === "\t" ||
+ ch === "\b" ||
+ ch === "\v"
+ ) {
// Write accumulated text before the control character
if (i > start) {
const segment = text.slice(start, i);
- // Filter out characters below space (but we already have \n, \r, \t handled)
+ // Filter out characters below space (but we already have \n, \r, \t, \b, \v handled)
const filtered = this.filterControlChars(segment);
if (filtered.length > 0) {
this.buffer.writeString(filtered);
@@ -305,7 +318,7 @@ export class AnsiReducer {
}
}
- /** Filter out control characters below space (except \n, \r, \t which are handled separately). */
+ /** Filter out control characters below space (except \n, \r, \t, \b, \v which are handled separately). */
private filterControlChars(text: string): string {
// Fast path: if no control chars, return as-is
let hasControlChars = false;