Skip to content

Commit 7b7a19a

Browse files
authored
core: add coloring for boolean values (#1252)
1 parent eba34ed commit 7b7a19a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/human/marshal_func.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ func init() {
2727
marshalerFuncs.Store(reflect.TypeOf(uint32(0)), defaultMarshalerFunc)
2828
marshalerFuncs.Store(reflect.TypeOf(uint64(0)), defaultMarshalerFunc)
2929
marshalerFuncs.Store(reflect.TypeOf(string("")), defaultMarshalerFunc)
30-
marshalerFuncs.Store(reflect.TypeOf(bool(false)), defaultMarshalerFunc)
30+
marshalerFuncs.Store(reflect.TypeOf(bool(false)), func(i interface{}, opt *MarshalOpt) (string, error) {
31+
v := i.(bool)
32+
if v {
33+
return terminal.Style("true", color.FgGreen), nil
34+
}
35+
return terminal.Style("false", color.FgRed), nil
36+
})
3137
marshalerFuncs.Store(reflect.TypeOf(time.Time{}), func(i interface{}, opt *MarshalOpt) (string, error) {
3238
return humanize.Time(i.(time.Time)), nil
3339
})

0 commit comments

Comments
 (0)