Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions extensions/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Strip ANSI escape codes from a string.
* Used by multiple extensions to get plain text from rendered TUI output.
*/
export function stripAnsi(str: string): string {
// eslint-disable-next-line no-control-regex
return str.replace(/\x1B\[[0-9;]*m/g, "");
}
2 changes: 1 addition & 1 deletion extensions/prompt-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "node:path";
import os from "node:os";
import fs from "node:fs/promises";
import type { Dirent } from "node:fs";
import { stripAnsi } from "./lib/utils.js";

// =============================================================================
// Modes
Expand Down Expand Up @@ -966,7 +967,6 @@ class PromptEditor extends CustomEditor {
const mode = this.modeLabelProvider?.();
if (!mode) return lines;

const stripAnsi = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
const topPlain = stripAnsi(lines[0] ?? "");

// If the editor is scrolled, the built-in editor renders a scroll indicator on the top border.
Expand Down
Loading