-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.go
151 lines (146 loc) · 2.68 KB
/
format.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package fmc
import (
"fmt"
"regexp"
"strings"
)
func screenCheck(word string) bool {
matched, err := regexp.MatchString(`!#`, word)
if err != nil {
fmt.Println(err)
}
return matched
}
func formatWithScreen(form string) string {
items := strings.Split(form, "!#")
var msg string
msg = formatWithoutScreen(items[0])
ln := len(items)
if 1 <= ln {
for i := 1; i < ln; i++ {
msg = msg + "#" + formatWithoutScreen(items[i])
}
} else {
msg = msg + "#"
}
return msg
}
func coloring(color, mess string) string {
var word string
switch color {
//aqua
case "bst":
word = format(aqua, mess)
case "bbt":
word = bformat(aqua, mess)
//black
case "0st":
word = format(black, mess)
case "0bt":
word = bformat(black, mess)
//blue
case "Bst":
word = format(blue, mess)
case "Bbt":
word = bformat(blue, mess)
//fuchsia
case "fst":
word = format(fuchsia, mess)
case "fbt":
word = bformat(fuchsia, mess)
//gray
case "1st":
word = format(gray, mess)
case "1bt":
word = bformat(gray, mess)
//green
case "Gst":
word = format(green, mess)
case "Gbt":
word = bformat(green, mess)
//lime
case "gst":
word = format(lime, mess)
case "gbt":
word = bformat(lime, mess)
//maroon
case "mst":
word = format(maroon, mess)
case "mbt":
word = bformat(maroon, mess)
//navy
case "nst":
word = format(navy, mess)
case "nbt":
word = bformat(navy, mess)
//olive
case "ost":
word = format(olive, mess)
case "obt":
word = bformat(olive, mess)
//purple
case "pst":
word = format(purple, mess)
case "pbt":
word = bformat(purple, mess)
//red
case "rst":
word = format(red, mess)
case "rbt":
word = bformat(red, mess)
//silver
case "sst":
word = format(silver, mess)
case "sbt":
word = bformat(silver, mess)
//teal
case "tst":
word = format(teal, mess)
case "tbt":
word = bformat(teal, mess)
//white
case "wst":
word = format(white, mess)
case "wbt":
word = bformat(white, mess)
//yellow
case "yst":
word = format(yellow, mess)
case "ybt":
word = bformat(yellow, mess)
//rest
case "RRR":
word = "\033[0m" + reset + mess
default:
word = mess
}
return word
}
func formatWithoutScreen(form string) string {
items := strings.Split(form, "#")
ilen := len(items)
if ilen < 0 {
return form
}
var msg string
msg = items[0]
for i := 1; i < ilen; i++ {
item := items[i]
if 4 <= len(item) {
color := item[0:3]
text := item[3:]
if text[:1] == " " {
text = item[4:]
}
msg = msg + coloring(color, text)
}
}
//fmt.Printf("msg: %s\n", msg)
return msg
}
func Sprint(form string) string {
if screenCheck(form) {
return formatWithScreen(form + "\033[0m" + reset)
}
return formatWithoutScreen(form + "\033[0m" + reset)
}