diff --git a/pkg/cli/strings.go b/pkg/cli/strings.go index 4c82712..8252c46 100644 --- a/pkg/cli/strings.go +++ b/pkg/cli/strings.go @@ -14,11 +14,17 @@ func Sprint(args ...any) string { // Styled returns text with a style applied. func Styled(style *AnsiStyle, text string) string { + if style == nil { + return compileGlyphs(text) + } return style.Render(compileGlyphs(text)) } // Styledf returns formatted text with a style applied. func Styledf(style *AnsiStyle, format string, args ...any) string { + if style == nil { + return compileGlyphs(fmt.Sprintf(format, args...)) + } return style.Render(compileGlyphs(fmt.Sprintf(format, args...))) } diff --git a/pkg/cli/styles_test.go b/pkg/cli/styles_test.go index 949c138..b127a59 100644 --- a/pkg/cli/styles_test.go +++ b/pkg/cli/styles_test.go @@ -222,3 +222,17 @@ func TestPad_Good(t *testing.T) { assert.Equal(t, "hello", Pad("hello", 3)) assert.Equal(t, "東京 ", Pad("東京", 6)) } + +func TestStyled_Good_NilStyle(t *testing.T) { + restoreThemeAndColors(t) + UseASCII() + + assert.Equal(t, "hello [OK]", Styled(nil, "hello :check:")) +} + +func TestStyledf_Good_NilStyle(t *testing.T) { + restoreThemeAndColors(t) + UseASCII() + + assert.Equal(t, "value: [WARN]", Styledf(nil, "value: %s", ":warn:")) +}