-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorformat.go
41 lines (37 loc) · 921 Bytes
/
colorformat.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
package main
import (
"bytes"
)
const (
COLOR_NONE = "\033[0m"
COLOR_RED = "\033[31;5;124m"
COLOR_BLUE = "\033[34;5;124m"
)
type ColorFormatFunc func(line string, indexes []int) string
func GrepColorRedFormat(line string, indexes []int) string {
if len(indexes) > 1 {
if indexes[0] == indexes[1] {
return line
}
buff := &bytes.Buffer{}
buff.WriteString(line[0:indexes[0]])
buff.WriteString(COLOR_RED)
buff.WriteString(line[indexes[0]:indexes[1]])
buff.WriteString(COLOR_NONE)
buff.WriteString(line[indexes[1]:])
return buff.String()
}
return line
}
func GrepColorBLUEFormat(line string, indexes []int) string {
if len(indexes) > 1 {
buff := &bytes.Buffer{}
buff.WriteString(line[0:indexes[0]])
buff.WriteString(COLOR_BLUE)
buff.WriteString(line[indexes[0]:indexes[1]])
buff.WriteString(COLOR_NONE)
buff.WriteString(line[indexes[1]:])
return buff.String()
}
return line
}