-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorizers_int.go
53 lines (50 loc) · 1.24 KB
/
colorizers_int.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package glog
import (
"fmt"
"strings"
)
// IntAmount colors `n` as int and appends either the
// given singular (`n` == 1) or plural (`n` > 1 || `n` == 0).
//
// Related config setting(s):
//
// - `n` > 0: `LoggerConfig.ColorIntPositive`
// - `n` == 0: `LoggerConfig.ColorIntZero`
// - `n` < 0: `LoggerConfig.ColorIntNegative`
func IntAmount[I IntOrUint](n I, singular, plural string) string {
unit := singular
if n > 1 {
unit = plural
}
color := LoggerConfig.ColorIntPositive
if n < 0 {
color = LoggerConfig.ColorIntNegative
} else if n == 0 {
color = LoggerConfig.ColorIntZero
}
amount := Wrap(fmt.Sprintf("%d", n), color)
if n == 0 {
unit = plural
}
return fmt.Sprintf("%s %s", amount, unit)
}
// Int colors the given ints.
//
// Related config setting(s):
//
// - `n` > 0: `LoggerConfig.ColorIntPositive`
// - `n` == 0: `LoggerConfig.ColorIntZero`
// - `n` < 0: `LoggerConfig.ColorIntNegative`
func Int[I IntOrUint](n ...I) string {
res := []string{}
for _, num := range n {
color := LoggerConfig.ColorIntPositive
if num < 0 {
color = LoggerConfig.ColorIntNegative
} else if num == 0 {
color = LoggerConfig.ColorIntZero
}
res = append(res, Wrap(fmt.Sprintf("%d", num), color))
}
return strings.Join(res, ", ")
}