-
Notifications
You must be signed in to change notification settings - Fork 51
/
themes.go
107 lines (91 loc) · 2.14 KB
/
themes.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
package main
import (
"fmt"
"github.com/kovetskiy/lorg"
"github.com/reconquest/colorgful"
"github.com/reconquest/loreley"
)
const (
themeDefault = `default`
themeDark = `dark`
themeLight = `light`
)
var (
statusBarThemeTemplate = `{bg %d}{fg %d}` +
`{bold}` +
`{if eq .Phase "lock"}{bg %d} LOCK{end}` +
`{if eq .Phase "connect"}{bg %[3]d} CONNECT{end}` +
`{if eq .Phase "exec"}{bg %d} EXEC{end}` +
`{if eq .Phase "wait"}{bg %d} WAIT{end}` +
`{if eq .Phase "upload"}{bg %d} UPLOAD{end}` +
`{nobold} ` +
`{from "" %d} ` +
`{fg %d}{bold}{printf "%%4d" .Success}{nobold}{fg %d}` +
`/{printf "%%4d" .Total} ` +
`{if .Fails}{fg %d}✗ {.Fails}{end} ` +
`{from "" %d}` +
`{if eq .Phase "upload"}{fg %d} ` +
`{printf "%%9s/%%s" .Written .Bytes} ` +
`{end}`
statusBarThemes = map[string]string{
themeDark: fmt.Sprintf(
statusBarThemeTemplate,
99, 7, 22, 1, 1, 25, 237, 46, 15, 214, -1, 140,
),
themeLight: fmt.Sprintf(
statusBarThemeTemplate,
99, 7, 22, 1, 1, 64, 254, 106, 16, 9, -1, 140,
),
themeDefault: fmt.Sprintf(
statusBarThemeTemplate,
234, 255, 22, 1, 1, 19, 245, 85, 255, 160, -1, 140,
),
}
logFormat = `${time} ${level:[%s]:right:true} %s`
)
func getLoggerTheme(theme string) (lorg.Formatter, error) {
switch theme {
case "default":
return colorgful.ApplyDefaultTheme(
logFormat,
colorgful.Default,
)
case "dark":
return colorgful.ApplyDefaultTheme(
logFormat,
colorgful.Dark,
)
case "light":
return colorgful.ApplyDefaultTheme(
logFormat,
colorgful.Light,
)
default:
return colorgful.Format(theme)
}
}
func getStatusBarTheme(theme string) (*loreley.Style, error) {
if format, ok := statusBarThemes[theme]; ok {
theme = format
}
style, err := loreley.CompileWithReset(theme, nil)
if err != nil {
return nil, err
}
return style, nil
}
func parseTheme(target string, args map[string]interface{}) string {
var (
theme = args["--"+target+"-format"].(string)
light = args["--colors-light"].(bool)
dark = args["--colors-dark"].(bool)
)
switch {
case light:
return themeLight
case dark:
return themeDark
default:
return theme
}
}