fix(cli): render glyph shortcodes in output
All checks were successful
Security Scan / security (push) Successful in 22s
All checks were successful
Security Scan / security (push) Successful in 22s
This commit is contained in:
parent
cdc765611f
commit
dc30159392
3 changed files with 36 additions and 17 deletions
|
|
@ -38,7 +38,7 @@ func Text(args ...any) {
|
|||
|
||||
// Success prints a success message with checkmark (green).
|
||||
func Success(msg string) {
|
||||
fmt.Println(SuccessStyle.Render(Glyph(":check:") + " " + msg))
|
||||
fmt.Println(SuccessStyle.Render(Glyph(":check:") + " " + compileGlyphs(msg)))
|
||||
}
|
||||
|
||||
// Successf prints a formatted success message.
|
||||
|
|
@ -49,7 +49,7 @@ func Successf(format string, args ...any) {
|
|||
// Error prints an error message with cross (red) to stderr and logs it.
|
||||
func Error(msg string) {
|
||||
LogError(msg)
|
||||
fmt.Fprintln(os.Stderr, ErrorStyle.Render(Glyph(":cross:")+" "+msg))
|
||||
fmt.Fprintln(os.Stderr, ErrorStyle.Render(Glyph(":cross:")+" "+compileGlyphs(msg)))
|
||||
}
|
||||
|
||||
// Errorf prints a formatted error message to stderr and logs it.
|
||||
|
|
@ -86,7 +86,7 @@ func ErrorWrapAction(err error, verb string) {
|
|||
// Warn prints a warning message with warning symbol (amber) to stderr and logs it.
|
||||
func Warn(msg string) {
|
||||
LogWarn(msg)
|
||||
fmt.Fprintln(os.Stderr, WarningStyle.Render(Glyph(":warn:")+" "+msg))
|
||||
fmt.Fprintln(os.Stderr, WarningStyle.Render(Glyph(":warn:")+" "+compileGlyphs(msg)))
|
||||
}
|
||||
|
||||
// Warnf prints a formatted warning message to stderr and logs it.
|
||||
|
|
@ -96,7 +96,7 @@ func Warnf(format string, args ...any) {
|
|||
|
||||
// Info prints an info message with info symbol (blue).
|
||||
func Info(msg string) {
|
||||
fmt.Println(InfoStyle.Render(Glyph(":info:") + " " + msg))
|
||||
fmt.Println(InfoStyle.Render(Glyph(":info:") + " " + compileGlyphs(msg)))
|
||||
}
|
||||
|
||||
// Infof prints a formatted info message.
|
||||
|
|
@ -106,7 +106,7 @@ func Infof(format string, args ...any) {
|
|||
|
||||
// Dim prints dimmed text.
|
||||
func Dim(msg string) {
|
||||
fmt.Println(DimStyle.Render(msg))
|
||||
fmt.Println(DimStyle.Render(compileGlyphs(msg)))
|
||||
}
|
||||
|
||||
// Progress prints a progress indicator that overwrites the current line.
|
||||
|
|
@ -127,7 +127,7 @@ func ProgressDone() {
|
|||
|
||||
// Label prints a "Label: value" line.
|
||||
func Label(word, value string) {
|
||||
fmt.Printf("%s %s\n", KeyStyle.Render(i18n.Label(word)), value)
|
||||
fmt.Printf("%s %s\n", KeyStyle.Render(i18n.Label(word)), compileGlyphs(value))
|
||||
}
|
||||
|
||||
// Scanln reads from stdin.
|
||||
|
|
@ -140,14 +140,14 @@ func Scanln(a ...any) (int, error) {
|
|||
// cli.Task("php", "Running tests...") // [php] Running tests...
|
||||
// cli.Task("go", i18n.Progress("build")) // [go] Building...
|
||||
func Task(label, message string) {
|
||||
fmt.Printf("%s %s\n\n", DimStyle.Render("["+label+"]"), message)
|
||||
fmt.Printf("%s %s\n\n", DimStyle.Render("["+compileGlyphs(label)+"]"), compileGlyphs(message))
|
||||
}
|
||||
|
||||
// Section prints a section header: "── SECTION ──"
|
||||
//
|
||||
// cli.Section("audit") // ── AUDIT ──
|
||||
func Section(name string) {
|
||||
header := "── " + strings.ToUpper(name) + " ──"
|
||||
header := "── " + strings.ToUpper(compileGlyphs(name)) + " ──"
|
||||
fmt.Println(AccentStyle.Render(header))
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ func Section(name string) {
|
|||
// cli.Hint("install", "composer require vimeo/psalm")
|
||||
// cli.Hint("fix", "core php fmt --fix")
|
||||
func Hint(label, message string) {
|
||||
fmt.Printf(" %s %s\n", DimStyle.Render(label+":"), message)
|
||||
fmt.Printf(" %s %s\n", DimStyle.Render(compileGlyphs(label)+":"), compileGlyphs(message))
|
||||
}
|
||||
|
||||
// Severity prints a severity-styled message.
|
||||
|
|
@ -179,7 +179,7 @@ func Severity(level, message string) {
|
|||
default:
|
||||
style = DimStyle
|
||||
}
|
||||
fmt.Printf(" %s %s\n", style.Render("["+level+"]"), message)
|
||||
fmt.Printf(" %s %s\n", style.Render("["+compileGlyphs(level)+"]"), compileGlyphs(message))
|
||||
}
|
||||
|
||||
// Result prints a result line: "✓ message" or "✗ message"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
@ -99,3 +100,21 @@ func TestSemanticOutput(t *testing.T) {
|
|||
t.Error("Result(false) output empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSemanticOutput_GlyphShortcodes(t *testing.T) {
|
||||
UseASCII()
|
||||
|
||||
out := captureOutput(func() {
|
||||
Success("done :check:")
|
||||
Task(":cross:", "running :warn:")
|
||||
Section(":check: audit")
|
||||
Hint(":info:", "apply :check:")
|
||||
Label("status", "ready :warn:")
|
||||
})
|
||||
|
||||
for _, want := range []string{"[OK]", "[FAIL]", "[WARN]"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("expected output to contain %q, got %q", want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,35 +14,35 @@ func Sprint(args ...any) string {
|
|||
|
||||
// Styled returns text with a style applied.
|
||||
func Styled(style *AnsiStyle, text string) string {
|
||||
return style.Render(text)
|
||||
return style.Render(compileGlyphs(text))
|
||||
}
|
||||
|
||||
// Styledf returns formatted text with a style applied.
|
||||
func Styledf(style *AnsiStyle, format string, args ...any) string {
|
||||
return style.Render(fmt.Sprintf(format, args...))
|
||||
return style.Render(compileGlyphs(fmt.Sprintf(format, args...)))
|
||||
}
|
||||
|
||||
// SuccessStr returns success-styled string.
|
||||
func SuccessStr(msg string) string {
|
||||
return SuccessStyle.Render(Glyph(":check:") + " " + msg)
|
||||
return SuccessStyle.Render(Glyph(":check:") + " " + compileGlyphs(msg))
|
||||
}
|
||||
|
||||
// ErrorStr returns error-styled string.
|
||||
func ErrorStr(msg string) string {
|
||||
return ErrorStyle.Render(Glyph(":cross:") + " " + msg)
|
||||
return ErrorStyle.Render(Glyph(":cross:") + " " + compileGlyphs(msg))
|
||||
}
|
||||
|
||||
// WarnStr returns warning-styled string.
|
||||
func WarnStr(msg string) string {
|
||||
return WarningStyle.Render(Glyph(":warn:") + " " + msg)
|
||||
return WarningStyle.Render(Glyph(":warn:") + " " + compileGlyphs(msg))
|
||||
}
|
||||
|
||||
// InfoStr returns info-styled string.
|
||||
func InfoStr(msg string) string {
|
||||
return InfoStyle.Render(Glyph(":info:") + " " + msg)
|
||||
return InfoStyle.Render(Glyph(":info:") + " " + compileGlyphs(msg))
|
||||
}
|
||||
|
||||
// DimStr returns dim-styled string.
|
||||
func DimStr(msg string) string {
|
||||
return DimStyle.Render(msg)
|
||||
return DimStyle.Render(compileGlyphs(msg))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue