fix(cli): render glyphs in static renderables
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
e1edbc1f9b
commit
11ac2c62c6
6 changed files with 34 additions and 5 deletions
|
|
@ -95,5 +95,5 @@ func StaticModel(text string) Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *staticModel) View(_, _ int) string {
|
func (s *staticModel) View(_, _ int) string {
|
||||||
return s.text
|
return compileGlyphs(s.text)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -233,8 +233,11 @@ func TestFrameComponents_GlyphShortcodes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStaticModel_Good(t *testing.T) {
|
func TestStaticModel_Good(t *testing.T) {
|
||||||
m := StaticModel("hello")
|
restoreThemeAndColors(t)
|
||||||
assert.Equal(t, "hello", m.View(80, 24))
|
UseASCII()
|
||||||
|
|
||||||
|
m := StaticModel(":check: hello")
|
||||||
|
assert.Equal(t, "[OK] hello", m.View(80, 24))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFrameModel_Good(t *testing.T) {
|
func TestFrameModel_Good(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ type Renderable interface {
|
||||||
type StringBlock string
|
type StringBlock string
|
||||||
|
|
||||||
// Render returns the string content.
|
// 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.
|
// Layout creates a new layout from a variant string.
|
||||||
func Layout(variant string) *Composite {
|
func Layout(variant string) *Composite {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,5 +141,5 @@ func (s *Stream) Captured() string {
|
||||||
if st, ok := s.out.(fmt.Stringer); ok {
|
if st, ok := s.out.(fmt.Stringer); ok {
|
||||||
return st.String()
|
return st.String()
|
||||||
}
|
}
|
||||||
return ""
|
panic("stream output writer does not support Capture")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -187,4 +188,19 @@ func TestStream_Bad(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "", buf.String())
|
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{}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue