From 82bffaaa1c1d6396cbe875f49a5065dafe0a8f41 Mon Sep 17 00:00:00 2001 From: Paul Sobolik Date: Fri, 10 Jan 2025 15:31:47 -0500 Subject: [PATCH] Strip ANSI control sequences from preformatted text. --- src/App.tsx | 7 ++++++- tsconfig.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 5f4cdf0..20d8105 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -259,6 +259,11 @@ function App() { return <> } const formatGeminiSuccess = (success: Success) => { + const stripAnsiSequences = (line: string): string => { + // Ought not be in there anyway... + const re = /\x1b\[[\x20-\x3f]*[\x40-\x7e]*/g; + return line.replaceAll(re, ""); + } let preformattedChildren: React.ReactNode[] = []; let preformat = false; const lines: React.ReactNode[] = []; @@ -272,7 +277,7 @@ function App() { } preformat = !preformat; } else if (preformat) { - preformattedChildren.push({line}
); + preformattedChildren.push({stripAnsiSequences(line)}
); } else switch (geminiLine.type) { case LineType.Link: const jimini_link = JiminiLink.parseString(geminiLine.text ?? ""); diff --git a/tsconfig.json b/tsconfig.json index d8bd313..bc5f0d8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], + "lib": ["ES2021", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true,