fix(cli): render glyphs in echo and progress
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
6192340ec0
commit
07bea81d4a
2 changed files with 9 additions and 4 deletions
|
|
@ -16,7 +16,7 @@ func Blank() {
|
||||||
// Echo translates a key via i18n.T and prints with newline.
|
// Echo translates a key via i18n.T and prints with newline.
|
||||||
// No automatic styling - use Success/Error/Warn/Info for styled output.
|
// No automatic styling - use Success/Error/Warn/Info for styled output.
|
||||||
func Echo(key string, args ...any) {
|
func Echo(key string, args ...any) {
|
||||||
fmt.Println(i18n.T(key, args...))
|
fmt.Println(compileGlyphs(i18n.T(key, args...)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print outputs formatted text (no newline).
|
// Print outputs formatted text (no newline).
|
||||||
|
|
@ -112,9 +112,9 @@ func Dim(msg string) {
|
||||||
// Progress prints a progress indicator that overwrites the current line.
|
// Progress prints a progress indicator that overwrites the current line.
|
||||||
// Uses i18n.Progress for gerund form ("Checking...").
|
// Uses i18n.Progress for gerund form ("Checking...").
|
||||||
func Progress(verb string, current, total int, item ...string) {
|
func Progress(verb string, current, total int, item ...string) {
|
||||||
msg := i18n.Progress(verb)
|
msg := compileGlyphs(i18n.Progress(verb))
|
||||||
if len(item) > 0 && item[0] != "" {
|
if len(item) > 0 && item[0] != "" {
|
||||||
fmt.Fprintf(os.Stderr, "\033[2K\r%s %d/%d %s", DimStyle.Render(msg), current, total, item[0])
|
fmt.Fprintf(os.Stderr, "\033[2K\r%s %d/%d %s", DimStyle.Render(msg), current, total, compileGlyphs(item[0]))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "\033[2K\r%s %d/%d", DimStyle.Render(msg), current, total)
|
fmt.Fprintf(os.Stderr, "\033[2K\r%s %d/%d", DimStyle.Render(msg), current, total)
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ func ProgressDone() {
|
||||||
|
|
||||||
// Label prints a "Label: value" line.
|
// Label prints a "Label: value" line.
|
||||||
func Label(word, value string) {
|
func Label(word, value string) {
|
||||||
fmt.Printf("%s %s\n", KeyStyle.Render(i18n.Label(word)), compileGlyphs(value))
|
fmt.Printf("%s %s\n", KeyStyle.Render(compileGlyphs(i18n.Label(word))), compileGlyphs(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scanln reads from stdin.
|
// Scanln reads from stdin.
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,13 @@ func TestSemanticOutput_GlyphShortcodes(t *testing.T) {
|
||||||
UseASCII()
|
UseASCII()
|
||||||
|
|
||||||
out := captureOutput(func() {
|
out := captureOutput(func() {
|
||||||
|
Echo(":check:")
|
||||||
Success("done :check:")
|
Success("done :check:")
|
||||||
Task(":cross:", "running :warn:")
|
Task(":cross:", "running :warn:")
|
||||||
Section(":check: audit")
|
Section(":check: audit")
|
||||||
Hint(":info:", "apply :check:")
|
Hint(":info:", "apply :check:")
|
||||||
Label("status", "ready :warn:")
|
Label("status", "ready :warn:")
|
||||||
|
Progress("check", 1, 2, ":warn: repo")
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, want := range []string{"[OK]", "[FAIL]", "[WARN]"} {
|
for _, want := range []string{"[OK]", "[FAIL]", "[WARN]"} {
|
||||||
|
|
@ -119,4 +121,7 @@ func TestSemanticOutput_GlyphShortcodes(t *testing.T) {
|
||||||
t.Fatalf("expected output to contain %q, got %q", want, out)
|
t.Fatalf("expected output to contain %q, got %q", want, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(out, "[WARN] repo") {
|
||||||
|
t.Fatalf("expected progress item shortcode to be rendered, got %q", out)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue