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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: handle tab control character in notebook output (#7275)
Cosmo Grantb0076a60c336
diff --git a/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts b/frontend/src/components/editor/output/__tests__/ansi-reduce.test.tsindex 4c42c14c87..dea92045f9 100644--- a/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts+++ b/frontend/src/components/editor/output/__tests__/ansi-reduce.test.ts@@ -47,6 +47,14 @@ describe("TerminalBuffer", () => {`);});+ test("control handles tab", () => {+ const buffer = new TerminalBuffer();+ buffer.writeChar("a");+ buffer.control("\t");+ buffer.writeChar("b");+ expect(buffer.render()).toMatchInlineSnapshot(`"a b"`);+ });+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.tsindex c0019547f8..a6d3eff17e 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). */+ /** Handle simple control characters (\n, \r, \t). */control(ch: string) {switch (ch) {case "\n":@@ -80,6 +80,9 @@ export class TerminalBuffer {case "\r":this.cursor.col = 0;break;+ case "\t":+ this.writeChar("\t");+ break;}}@@ -268,11 +271,11 @@ export class AnsiReducer {const ch = text[i];// Handle control characters- if (ch === "\n" || ch === "\r") {+ if (ch === "\n" || ch === "\r" || ch === "\t") {// Write accumulated text before the control characterif (i > start) {const segment = text.slice(start, i);- // Filter out characters below space (but we already have \n and \r handled)+ // Filter out characters below space (but we already have \n, \r, \t handled)const filtered = this.filterControlChars(segment);if (filtered.length > 0) {this.buffer.writeString(filtered);@@ -302,7 +305,7 @@ export class AnsiReducer {}}- /** Filter out control characters below space (except \n and \r which are handled separately). */+ /** Filter out control characters below space (except \n, \r, \t which are handled separately). */private filterControlChars(text: string): string {// Fast path: if no control chars, return as-islet hasControlChars = false;