Skip to content

Commit

Permalink
Strip ANSI control sequences from preformatted text.
Browse files Browse the repository at this point in the history
  • Loading branch information
psobolik committed Jan 10, 2025
1 parent 793f52e commit 82bffaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -272,7 +277,7 @@ function App() {
}
preformat = !preformat;
} else if (preformat) {
preformattedChildren.push(<span key={index}>{line}<br/></span>);
preformattedChildren.push(<span key={index}>{stripAnsiSequences(line)}<br/></span>);
} else switch (geminiLine.type) {
case LineType.Link:
const jimini_link = JiminiLink.parseString(geminiLine.text ?? "");
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2021", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

Expand Down

0 comments on commit 82bffaa

Please sign in to comment.