From e89972a396c5b71b27b54c841fe26a2e9e53f5be Mon Sep 17 00:00:00 2001 From: Matias Insaurralde Date: Wed, 16 Jul 2025 06:20:25 -0300 Subject: perf: move ANSI regex compilations to package level (#1040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matías Insaurralde --- packages/tui/internal/layout/overlay.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'packages/tui/internal/layout') diff --git a/packages/tui/internal/layout/overlay.go b/packages/tui/internal/layout/overlay.go index 48064c91a..08016e31c 100644 --- a/packages/tui/internal/layout/overlay.go +++ b/packages/tui/internal/layout/overlay.go @@ -15,6 +15,11 @@ import ( "github.com/sst/opencode/internal/util" ) +var ( + // ANSI escape sequence regex + ansiRegex = regexp.MustCompile(`\x1b\[[0-9;]*m`) +) + // Split a string into lines, additionally returning the size of the widest line. func getLines(s string) (lines []string, widest int) { lines = strings.Split(s, "\n") @@ -272,9 +277,6 @@ func combineStyles(bgStyle ansiStyle, fgColor *compat.AdaptiveColor) string { // getStyleAtPosition extracts the active ANSI style at a given visual position func getStyleAtPosition(s string, targetPos int) ansiStyle { - // ANSI escape sequence regex - ansiRegex := regexp.MustCompile(`\x1b\[[0-9;]*m`) - visualPos := 0 currentStyle := ansiStyle{} -- cgit v1.2.3