-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormattedString.go
71 lines (55 loc) · 1.88 KB
/
FormattedString.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// FormattedString
package main
import (
"github.com/daviddengcn/go-colortext"
)
type FmtStrCollection struct {
fmtedStrings []FormattedString
currentColor ct.Color
}
func newFormattedStringCollection() *FmtStrCollection {
fsc := new(FmtStrCollection)
fsc.fmtedStrings = make([]FormattedString, 0, 1)
fsc.currentColor = ct.White
return fsc
}
func (fsc *FmtStrCollection) addMessage(color ct.Color, msg string) {
fsc.fmtedStrings = append(fsc.fmtedStrings, newFormattedString2(color, msg))
}
func (fsc *FmtStrCollection) addMessage2(msg string) {
fsc.fmtedStrings = append(fsc.fmtedStrings, newFormattedString2(ct.White, msg))
}
func (fsc *FmtStrCollection) addMessages(appendFsc *FmtStrCollection) {
fsc.fmtedStrings = append(fsc.fmtedStrings, appendFsc.fmtedStrings...)
}
func (fsc *FmtStrCollection) addMessages2(msgs []FormattedString) {
fsc.fmtedStrings = append(fsc.fmtedStrings, msgs...)
}
type FormattedString struct {
Color ct.Color
Value string
}
func newFormattedString(msg string) FormattedString {
return FormattedString{Color: ct.White, Value: msg}
}
func newFormattedString2(color ct.Color, msg string) FormattedString {
return FormattedString{Color: color, Value: msg}
}
func newFormattedStringSplice(msg string) []FormattedString {
fs := make([]FormattedString, 0, 1)
fs = append(fs, FormattedString{Color: ct.White, Value: msg})
return fs
}
func newFormattedStringSplice2(color ct.Color, msg string) []FormattedString {
fs := make([]FormattedString, 0, 1)
fs = append(fs, FormattedString{Color: color, Value: msg})
return fs
}
func addMessageToSplice(splice []FormattedString, msg string) []FormattedString {
temp := FormattedString{Color: ct.White, Value: msg}
return append(splice, temp)
}
func addMessageToSplice2(splice []FormattedString, color ct.Color, msg string) []FormattedString {
temp := FormattedString{Color: color, Value: msg}
return append(splice, temp)
}