From 88ec9264a962d7911c84f51f5e27d349e56b996e Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 06:38:45 +0000 Subject: [PATCH] fix(cli): strip ANSI from static frame output Co-Authored-By: Virgil --- pkg/cli/frame.go | 3 ++- pkg/cli/frame_test.go | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/cli/frame.go b/pkg/cli/frame.go index 82e8108..bb6ea3a 100644 --- a/pkg/cli/frame.go +++ b/pkg/cli/frame.go @@ -10,6 +10,7 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" "golang.org/x/term" ) @@ -428,6 +429,7 @@ func (f *Frame) String() string { if view == "" { return "" } + view = ansi.Strip(view) // Ensure trailing newline for non-TTY consistency if !strings.HasSuffix(view, "\n") { view += "\n" @@ -452,7 +454,6 @@ func (f *Frame) termSize() (int, int) { return 80, 24 // sensible default } - func (f *Frame) runLive() { opts := []tea.ProgramOption{ tea.WithAltScreen(), diff --git a/pkg/cli/frame_test.go b/pkg/cli/frame_test.go index b9d30e6..709f95d 100644 --- a/pkg/cli/frame_test.go +++ b/pkg/cli/frame_test.go @@ -145,6 +145,20 @@ func TestFrame_Bad(t *testing.T) { assert.Equal(t, "", f.String()) }) + t.Run("static string strips ANSI", func(t *testing.T) { + f := NewFrame("HCF") + f.out = &bytes.Buffer{} + f.Header(StatusLine("core dev", "18 repos")) + f.Content(StaticModel("body")) + f.Footer(KeyHints("q quit")) + + out := f.String() + assert.NotContains(t, out, "\x1b[") + assert.Contains(t, out, "core dev") + assert.Contains(t, out, "body") + assert.Contains(t, out, "q quit") + }) + t.Run("back on empty history", func(t *testing.T) { f := NewFrame("C") f.out = &bytes.Buffer{} @@ -276,7 +290,7 @@ func TestFrameFocus_Good(t *testing.T) { t.Run("Focus ignores invalid region", func(t *testing.T) { f := NewFrame("HCF") - f.Focus(RegionLeft) // Left not in "HCF" + f.Focus(RegionLeft) // Left not in "HCF" assert.Equal(t, RegionContent, f.Focused()) // unchanged }) @@ -550,4 +564,3 @@ func TestFrameMessageRouting_Good(t *testing.T) { }) }) } - -- 2.45.3