fix(cli): strip ANSI from static frame output

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 06:38:45 +00:00
parent 5c8f08b60e
commit 88ec9264a9
2 changed files with 17 additions and 3 deletions

View file

@ -10,6 +10,7 @@ import (
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
"golang.org/x/term" "golang.org/x/term"
) )
@ -428,6 +429,7 @@ func (f *Frame) String() string {
if view == "" { if view == "" {
return "" return ""
} }
view = ansi.Strip(view)
// Ensure trailing newline for non-TTY consistency // Ensure trailing newline for non-TTY consistency
if !strings.HasSuffix(view, "\n") { if !strings.HasSuffix(view, "\n") {
view += "\n" view += "\n"
@ -452,7 +454,6 @@ func (f *Frame) termSize() (int, int) {
return 80, 24 // sensible default return 80, 24 // sensible default
} }
func (f *Frame) runLive() { func (f *Frame) runLive() {
opts := []tea.ProgramOption{ opts := []tea.ProgramOption{
tea.WithAltScreen(), tea.WithAltScreen(),

View file

@ -145,6 +145,20 @@ func TestFrame_Bad(t *testing.T) {
assert.Equal(t, "", f.String()) 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) { t.Run("back on empty history", func(t *testing.T) {
f := NewFrame("C") f := NewFrame("C")
f.out = &bytes.Buffer{} f.out = &bytes.Buffer{}
@ -276,7 +290,7 @@ func TestFrameFocus_Good(t *testing.T) {
t.Run("Focus ignores invalid region", func(t *testing.T) { t.Run("Focus ignores invalid region", func(t *testing.T) {
f := NewFrame("HCF") f := NewFrame("HCF")
f.Focus(RegionLeft) // Left not in "HCF" f.Focus(RegionLeft) // Left not in "HCF"
assert.Equal(t, RegionContent, f.Focused()) // unchanged assert.Equal(t, RegionContent, f.Focused()) // unchanged
}) })
@ -550,4 +564,3 @@ func TestFrameMessageRouting_Good(t *testing.T) {
}) })
}) })
} }