From 22227aa0c5f59682db563f65f09985f82a696c12 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 17 Jun 2026 04:33:55 +0200 Subject: [PATCH] Add emoji prefixes to Warning and Error output --- README.md | 7 ++++--- internal/ui/ui.go | 12 ++++++------ internal/ui/ui_test.go | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7877bf9..1e6b23e 100644 --- a/README.md +++ b/README.md @@ -404,8 +404,8 @@ Message classes: | Complete | `》` (green) | column 0 | An operation just finished (past-tense verb) | | Info | `》` (white) | column 0 | Neutral status update | | Notice | `》` (cyan) | column 0 | Important note that is not a warning | -| Warning | `Warning:` (orange/yellow) | column 0 | Recoverable problem | -| Error | `ERROR:` (red) | column 0 | Operation aborted | +| Warning | `⚠️ Warning:` (orange/yellow) | column 0 | Recoverable problem | +| Error | `❌ ERROR:` (red) | column 0 | Operation aborted | | Progress | ` 》` (white) | column 2 | Heartbeat or per-item status during a long-running operation | Conventions: @@ -446,7 +446,8 @@ ANSI escapes inline: When `NO_COLOR` is set or output is not a TTY, all helpers return plain text and the marker prefixes (`》`, `Warning:`, `ERROR:`) emit without -ANSI escapes. +ANSI escapes. The emoji prefixes on Warning and Error are always emitted +regardless of color setting (emoji are not color). ## requirements diff --git a/internal/ui/ui.go b/internal/ui/ui.go index f0e8879..dc7f374 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -113,17 +113,17 @@ func (w *Writer) Notice(format string, args ...any) { w.emit(ansiCyan, Marker, "", format, args) } -// Warning prints "Warning: " in orange/yellow followed by the message. +// Warning prints "⚠️ Warning: " in orange/yellow followed by the message. func (w *Writer) Warning(format string, args ...any) { - prefix := w.paint(ansiYellow+ansiBold, "Warning: ") + prefix := "⚠️ " + w.paint(ansiYellow+ansiBold, "Warning: ") _, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...)) } -// Error prints "ERROR: " in red followed by the message. Goes to the same -// writer as everything else; callers that want stderr should construct a -// separate Writer for it. +// Error prints "❌ ERROR: " in red followed by the message. Goes to the +// same writer as everything else; callers that want stderr should +// construct a separate Writer for it. func (w *Writer) Error(format string, args ...any) { - prefix := w.paint(ansiRed+ansiBold, "ERROR: ") + prefix := "❌ " + w.paint(ansiRed+ansiBold, "ERROR: ") _, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...)) } diff --git a/internal/ui/ui_test.go b/internal/ui/ui_test.go index 8c3ce76..28860a1 100644 --- a/internal/ui/ui_test.go +++ b/internal/ui/ui_test.go @@ -22,8 +22,8 @@ func TestMessageMethodsPlain(t *testing.T) { {"Complete", func(w *Writer) { w.Complete("done %s", "thing") }, "》 done thing\n"}, {"Info", func(w *Writer) { w.Info("status") }, "》 status\n"}, {"Notice", func(w *Writer) { w.Notice("note") }, "》 note\n"}, - {"Warning", func(w *Writer) { w.Warning("oops") }, "Warning: oops\n"}, - {"Error", func(w *Writer) { w.Error("boom") }, "ERROR: boom\n"}, + {"Warning", func(w *Writer) { w.Warning("oops") }, "⚠️ Warning: oops\n"}, + {"Error", func(w *Writer) { w.Error("boom") }, "❌ ERROR: boom\n"}, {"Progress", func(w *Writer) { w.Progress("p") }, " 》 p\n"}, {"Banner", func(w *Writer) { w.Banner("hello") }, "hello\n"}, }