Skip to content

Commit 56b5d9c

Browse files
committed
tui/note: add warning note type
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
1 parent 3262107 commit 56b5d9c

1 file changed

Lines changed: 46 additions & 5 deletions

File tree

internal/tui/note.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,66 @@ var InfoHeader = Str{
1515
Fancy: aec.Bold.Apply(aec.LightCyanB.Apply(aec.BlackF.Apply("i")) + " " + aec.LightCyanF.Apply("Info → ")),
1616
}
1717

18-
func (o Output) PrintNote(format string, args ...any) {
18+
type options struct {
19+
header Str
20+
messageColor aec.ANSI
21+
}
22+
23+
type noteOptions func(o *options)
24+
25+
func withMessageColor(color aec.ANSI) noteOptions {
26+
return func(o *options) {
27+
o.messageColor = color
28+
}
29+
}
30+
31+
func withHeader(header Str) noteOptions {
32+
return func(o *options) {
33+
o.header = header
34+
}
35+
}
36+
37+
func (o Output) printNoteWithOptions(format string, args []any, opts ...noteOptions) {
1938
if o.isTerminal {
2039
// TODO: Handle all flags
2140
format = strings.ReplaceAll(format, "--platform", ColorFlag.Apply("--platform"))
2241
}
2342

24-
header := o.Sprint(InfoHeader)
43+
opt := &options{
44+
header: InfoHeader,
45+
messageColor: noColor{},
46+
}
2547

26-
_, _ = fmt.Fprint(o, "\n", header)
48+
for _, override := range opts {
49+
override(opt)
50+
}
51+
52+
h := o.Sprint(opt.header)
53+
54+
_, _ = fmt.Fprint(o, "\n", h)
2755
s := fmt.Sprintf(format, args...)
2856
for idx, line := range strings.Split(s, "\n") {
2957
if idx > 0 {
30-
_, _ = fmt.Fprint(o, strings.Repeat(" ", Width(header)))
58+
_, _ = fmt.Fprint(o, strings.Repeat(" ", Width(h)))
3159
}
3260

3361
l := line
3462
if o.isTerminal {
35-
l = aec.Italic.Apply(l)
63+
l = opt.messageColor.Apply(aec.Italic.Apply(l))
3664
}
3765
_, _ = fmt.Fprintln(o, l)
3866
}
3967
}
68+
69+
func (o Output) PrintNote(format string, args ...any) {
70+
o.printNoteWithOptions(format, args, withHeader(InfoHeader))
71+
}
72+
73+
var warningHeader = Str{
74+
Plain: " Warn -> ",
75+
Fancy: aec.Bold.Apply(aec.LightYellowB.Apply(aec.BlackF.Apply("w")) + " " + ColorWarning.Apply("Warn → ")),
76+
}
77+
78+
func (o Output) PrintWarning(format string, args ...any) {
79+
o.printNoteWithOptions(format, args, withHeader(warningHeader), withMessageColor(ColorWarning))
80+
}

0 commit comments

Comments
 (0)