-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
list.go
57 lines (49 loc) · 1.12 KB
/
list.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
54
55
56
57
package cute
import "fmt"
/* CuteList (print lines dynamically) */
type CuteList struct {
Title string
TitleColor CuteColor
Lines []CuteLine
}
/* CluteLine (child of CuteList) */
type CuteLine struct {
Message any
MessageColor CuteColor
}
// constructor of list
func NewList(color CuteColor, title string) *CuteList {
return &CuteList{
TitleColor: color,
Title: title,
}
}
/* add message to list */
func (this *CuteList) Add(color CuteColor, message any) {
this.Lines = append(this.Lines, CuteLine{
MessageColor: color,
Message: message,
})
}
/* addf message to list */
func (this *CuteList) Addf(color CuteColor, message string, params ...any) {
this.Lines = append(this.Lines, CuteLine{
MessageColor: color,
Message: fmt.Sprintf(message, params...),
})
}
/* print list */
func (this *CuteList) Print() {
// set title color
colorize(this.TitleColor)
// print title
fmt.Println(drawTitle(this.Title))
for _, line := range this.Lines {
// set message color
colorize(line.MessageColor)
// print message
fmt.Println(drawMessage(line.Message))
}
// reset
colorize(ResetColor)
}