@@ -23,6 +23,7 @@ import (
23 "github.com/charmbracelet/crush/internal/config"
23 "github.com/charmbracelet/crush/internal/config"
24 "github.com/charmbracelet/crush/internal/csync"
24 "github.com/charmbracelet/crush/internal/csync"
25 "github.com/charmbracelet/crush/internal/fsext"
25 "github.com/charmbracelet/crush/internal/fsext"
26+ "github.com/charmbracelet/x/ansi"
28// regexCache provides thread-safe caching of compiled regex patterns
29// regexCache provides thread-safe caching of compiled regex patterns
@@ -161,8 +162,8 @@ func NewGrepTool(workingDir string, config config.ToolGrep) fantasy.AgentTool {
162 if match.lineNum > 0 {
163 if match.lineNum > 0 {
163 lineText := match.lineText
164 lineText := match.lineText
164− if len(lineText) > maxGrepContentWidth {
165+ if ansi.StringWidth(lineText) > maxGrepContentWidth {
165− lineText = lineText[:maxGrepContentWidth] + "..."
166+ lineText = ansi.Truncate(lineText, maxGrepContentWidth, "...")
167 if match.charNum > 0 {
168 if match.charNum > 0 {
168 fmt.Fprintf(&output, " Line %d, Char %d: %s\n", match.lineNum, match.charNum, lineText)
169 fmt.Fprintf(&output, " Line %d, Char %d: %s\n", match.lineNum, match.charNum, lineText)