Skip to content

Commit df687da

Browse files
committed
fix(cli): make Hintf emit single atomic write to prevent interleaved output
Use color.CyanString/YellowString to build the full hint line in memory before writing, instead of two separate Fprintf calls that could be split by concurrent writes to the same writer. Signed-off-by: spencercjh <spencercjh@gmail.com>
1 parent e1a76e7 commit df687da

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

internal/cli/output.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import (
1010
)
1111

1212
var (
13-
green = color.New(color.FgGreen).FprintfFunc()
14-
red = color.New(color.FgRed, color.Bold).FprintfFunc()
15-
cyan = color.New(color.FgCyan).FprintfFunc()
16-
yellow = color.New(color.FgYellow).FprintfFunc()
17-
dim = color.New(color.Faint).FprintfFunc()
13+
green = color.New(color.FgGreen).FprintfFunc()
14+
red = color.New(color.FgRed, color.Bold).FprintfFunc()
15+
dim = color.New(color.Faint).FprintfFunc()
1816
)
1917

2018
func init() {
@@ -53,11 +51,11 @@ func Errorf(w io.Writer, format string, args ...any) {
5351
red(w, "❌ %s\n", msg)
5452
}
5553

56-
// Hintf prints a cyan hint prefix with yellow hint content.
54+
// Hintf prints a cyan hint prefix with yellow hint content as a single atomic write.
5755
func Hintf(w io.Writer, format string, args ...any) {
5856
msg := fmt.Sprintf(format, args...)
59-
cyan(w, "💡 Hint: ")
60-
yellow(w, "%s\n", msg)
57+
line := color.CyanString("💡 Hint: ") + color.YellowString("%s\n", msg)
58+
fmt.Fprint(w, line)
6159
}
6260

6361
// Statusf prints a neutral status message.

0 commit comments

Comments
 (0)