-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.58 KB
/
main.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
package main
import (
"fmt"
"os"
"strings"
)
// Color codes
var ColorCodes = map[string]string{
"Reset": "\033[0m",
"Black": "\033[30m",
"Red": "\033[31m",
"Green": "\033[32m",
"Yellow": "\033[33m",
"Blue": "\033[34m",
"Magenta": "\033[35m",
"Cyan": "\033[36m",
"LightGray": "\033[37m",
"Gray": "\033[90m",
"LightRed": "\033[91m",
"LightGreen": "\033[92m",
"LightYellow": "\033[93m",
"LightBlue": "\033[94m",
"LightMagenta": "\033[95m",
"LightCyan": "\033[96m",
"White": "\033[97m",
"Orange": "\033[38;5;208m",
}
func main() {
if len(os.Args) > 2 {
ColorFromOutside := os.Args[1]
textColor := ""
if len(ColorFromOutside) > 8 {
textColor = ColorFromOutside[8:]
}
if len(os.Args) == 3 {
textFromOutside := os.Args[2]
printColored(textFromOutside, textColor)
fmt.Println("")
} else if len(os.Args) == 4 {
textFromOutside := os.Args[3]
subStringFromOutside := os.Args[2]
letterCount := strings.Count(textFromOutside, subStringFromOutside)
for i := 0; i < letterCount; i++ {
lenOfSubStr := len(subStringFromOutside)
idxOfSubStrInStr := strings.Index(textFromOutside, subStringFromOutside)
fmt.Print(textFromOutside[:idxOfSubStrInStr])
printColored(subStringFromOutside, textColor)
textFromOutside = textFromOutside[idxOfSubStrInStr+lenOfSubStr:]
}
fmt.Println(textFromOutside)
}
}
}
func printColored(text, textColor string) {
titleCase := strings.Title(textColor)
fmt.Print(ColorCodes[titleCase] + text + ColorCodes["Reset"])
}