fix(cli): render glyphs in static renderables

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 12:26:38 +00:00
parent e1edbc1f9b
commit 11ac2c62c6
6 changed files with 34 additions and 5 deletions

View file

@ -95,5 +95,5 @@ func StaticModel(text string) Model {
}
func (s *staticModel) View(_, _ int) string {
return s.text
return compileGlyphs(s.text)
}

View file

@ -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) {

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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")
}

View file

@ -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{}