From 11ac2c62c60f056776d4a18cc525e76a7e3a2774 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 12:26:38 +0000 Subject: [PATCH] fix(cli): render glyphs in static renderables Co-Authored-By: Virgil --- pkg/cli/frame_components.go | 2 +- pkg/cli/frame_test.go | 7 +++++-- pkg/cli/layout.go | 2 +- pkg/cli/layout_test.go | 10 ++++++++++ pkg/cli/stream.go | 2 +- pkg/cli/stream_test.go | 16 ++++++++++++++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/pkg/cli/frame_components.go b/pkg/cli/frame_components.go index ec44ad1..628bd61 100644 --- a/pkg/cli/frame_components.go +++ b/pkg/cli/frame_components.go @@ -95,5 +95,5 @@ func StaticModel(text string) Model { } func (s *staticModel) View(_, _ int) string { - return s.text + return compileGlyphs(s.text) } diff --git a/pkg/cli/frame_test.go b/pkg/cli/frame_test.go index b97a558..5efbb97 100644 --- a/pkg/cli/frame_test.go +++ b/pkg/cli/frame_test.go @@ -233,8 +233,11 @@ func TestFrameComponents_GlyphShortcodes(t *testing.T) { } func TestStaticModel_Good(t *testing.T) { - m := StaticModel("hello") - assert.Equal(t, "hello", m.View(80, 24)) + restoreThemeAndColors(t) + UseASCII() + + m := StaticModel(":check: hello") + assert.Equal(t, "[OK] hello", m.View(80, 24)) } func TestFrameModel_Good(t *testing.T) { diff --git a/pkg/cli/layout.go b/pkg/cli/layout.go index e0acb48..fb5ffd6 100644 --- a/pkg/cli/layout.go +++ b/pkg/cli/layout.go @@ -68,7 +68,7 @@ type Renderable interface { type StringBlock string // Render returns the string content. -func (s StringBlock) Render() string { return string(s) } +func (s StringBlock) Render() string { return compileGlyphs(string(s)) } // Layout creates a new layout from a variant string. func Layout(variant string) *Composite { diff --git a/pkg/cli/layout_test.go b/pkg/cli/layout_test.go index 4fb42ad..df36740 100644 --- a/pkg/cli/layout_test.go +++ b/pkg/cli/layout_test.go @@ -23,3 +23,13 @@ func TestParseVariant(t *testing.T) { } } } + +func TestStringBlock_GlyphShortcodes(t *testing.T) { + restoreThemeAndColors(t) + UseASCII() + + block := StringBlock(":check: ready") + if got := block.Render(); got != "[OK] ready" { + t.Fatalf("expected shortcode rendering, got %q", got) + } +} diff --git a/pkg/cli/stream.go b/pkg/cli/stream.go index d78a442..0e4e8d0 100644 --- a/pkg/cli/stream.go +++ b/pkg/cli/stream.go @@ -141,5 +141,5 @@ func (s *Stream) Captured() string { if st, ok := s.out.(fmt.Stringer); ok { return st.String() } - return "" + panic("stream output writer does not support Capture") } diff --git a/pkg/cli/stream_test.go b/pkg/cli/stream_test.go index 3a528ce..e4d745c 100644 --- a/pkg/cli/stream_test.go +++ b/pkg/cli/stream_test.go @@ -2,6 +2,7 @@ package cli import ( "bytes" + "io" "strings" "testing" @@ -187,4 +188,19 @@ func TestStream_Bad(t *testing.T) { assert.Equal(t, "", buf.String()) }) + + t.Run("Captured panics when output is not stringable", func(t *testing.T) { + s := NewStream(WithStreamOutput(writerOnly{})) + assert.Panics(t, func() { + _ = s.Captured() + }) + }) } + +type writerOnly struct{} + +func (writerOnly) Write(p []byte) (int, error) { + return len(p), nil +} + +var _ io.Writer = writerOnly{} -- 2.45.3