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
package utils
import (
"fmt"
"io"
"strings"
)
func IgnoreErrWriteString(writer io.Writer, s string) {
_, _ = io.WriteString(writer, s)
}
const (
ColorEscape = "\033["
Green = "32m"
Red = "31m"
ColorEnd = ColorEscape + "0m"
Bold = "1"
)
const (
CharClear = "\x1b[H\x1b[2J"
CharTab = "\t"
CharNewLine = "\r\n"
CharCleanLine = '\x15'
)
func WrapperString(text string, color string, meta ...bool) string {
wrapWith := make([]string, 0)
metaLen := len(meta)
switch metaLen {
case 1:
wrapWith = append(wrapWith, Bold)
}
wrapWith = append(wrapWith, color)
return fmt.Sprintf("%s%s%s%s", ColorEscape, strings.Join(wrapWith, ";"), text, ColorEnd)
}
func WrapperTitle(text string) string {
return WrapperString(text, Green, true)
}
func WrapperWarn(text string) string {
text += "\n\r"
return WrapperString(text, Red)
}