-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcolor.go
More file actions
48 lines (38 loc) · 936 Bytes
/
Copy pathcolor.go
File metadata and controls
48 lines (38 loc) · 936 Bytes
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
package argparse
import (
"fmt"
"os"
"strings"
)
type Color struct {
Code int // color code for text color or background color, normally within 30 ~ 49
Property int // property code, eg: 1 for bold, 4 for underline, etc.
}
type ColorSchema struct {
Usage Color
Description Color
GroupTitle Color
Command Color
Argument Color
Meta Color
Epilog Color
}
// Just black & white
var NoColor = &ColorSchema{}
// Default color schema
var DefaultColor = &ColorSchema{
Usage: Color{37, 1},
GroupTitle: Color{32, 1},
Command: Color{33, 1},
Argument: Color{36, 0},
Epilog: Color{37, 1},
}
func checkTerminalColorSupport() bool {
return strings.Contains(os.Getenv("TERM"), "color")
}
func wrapperColor(content string, color Color) string {
if color.Code == 0 && color.Property == 0 {
return content
}
return fmt.Sprintf("\033[0%d;%dm%s\033[00m", color.Property, color.Code, content)
}