This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
/
theme.go
122 lines (106 loc) · 3.32 KB
/
theme.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package config
import (
"encoding/json"
"io"
"os"
"path/filepath"
"github.com/Bios-Marcel/cordless/tview"
tcell "github.com/gdamore/tcell/v2"
)
// Theme is a wrapper around the tview.Theme. This wrapper can be extended with
// additional theming properties and the underlying tview.Theme can still be
// applied to tview.Styles
type Theme struct {
*tview.Theme
BlockedUserColor tcell.Color
InfoMessageColor tcell.Color
BotColor tcell.Color
MessageTimeColor tcell.Color
DefaultUserColor tcell.Color
LinkColor tcell.Color
AttentionColor tcell.Color
ErrorColor tcell.Color
RandomUserColors []tcell.Color
}
var (
theme = createDefaultTheme()
)
// GetTheme returns a pointer to the currently loaded Theme.
func GetTheme() *Theme {
return theme
}
func createDefaultTheme() *Theme {
return &Theme{
Theme: &tview.Theme{
PrimitiveBackgroundColor: tcell.ColorBlack,
ContrastBackgroundColor: tcell.ColorBlue,
MoreContrastBackgroundColor: tcell.ColorGreen,
BorderColor: tcell.ColorWhite,
BorderFocusColor: tcell.ColorBlue,
TitleColor: tcell.ColorWhite,
GraphicsColor: tcell.ColorWhite,
PrimaryTextColor: tcell.ColorWhite,
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorGreen,
InverseTextColor: tcell.ColorBlue,
ContrastSecondaryTextColor: tcell.ColorDarkCyan,
},
BlockedUserColor: tcell.ColorGray,
InfoMessageColor: tcell.ColorGray,
BotColor: tcell.NewRGBColor(0x94, 0x96, 0xfc),
MessageTimeColor: tcell.ColorGray,
LinkColor: tcell.ColorDarkCyan,
DefaultUserColor: tcell.NewRGBColor(0x44, 0xe5, 0x44),
AttentionColor: tcell.ColorOrange,
ErrorColor: tcell.ColorRed,
RandomUserColors: []tcell.Color{
tcell.NewRGBColor(0xd8, 0x50, 0x4e),
tcell.NewRGBColor(0xd8, 0x7e, 0x4e),
tcell.NewRGBColor(0xd8, 0xa5, 0x4e),
tcell.NewRGBColor(0xd8, 0xc6, 0x4e),
tcell.NewRGBColor(0xb8, 0xd8, 0x4e),
tcell.NewRGBColor(0x91, 0xd8, 0x4e),
tcell.NewRGBColor(0x67, 0xd8, 0x4e),
tcell.NewRGBColor(0x4e, 0xd8, 0x7c),
tcell.NewRGBColor(0x4e, 0xd8, 0xaa),
tcell.NewRGBColor(0x4e, 0xd8, 0xcf),
tcell.NewRGBColor(0x4e, 0xb6, 0xd8),
tcell.NewRGBColor(0x4e, 0x57, 0xd8),
tcell.NewRGBColor(0x75, 0x4e, 0xd8),
tcell.NewRGBColor(0xa3, 0x4e, 0xd8),
tcell.NewRGBColor(0xcf, 0x4e, 0xd8),
tcell.NewRGBColor(0xd8, 0x4e, 0x9c),
},
}
}
// GetThemeFile returns the path to the theme file.
func GetThemeFile() (string, error) {
configDir, configError := GetConfigDirectory()
if configError != nil {
return "", configError
}
return filepath.Join(configDir, "theme.json"), nil
}
// LoadTheme reads the theme from the users configuration folder and stored it
// in the local state. It can be retrieved via GetTheme.
func LoadTheme() error {
themeFilePath, themeError := GetThemeFile()
if themeError != nil {
return themeError
}
themeFile, openError := os.Open(themeFilePath)
if os.IsNotExist(openError) {
return nil
}
if openError != nil {
return openError
}
defer themeFile.Close()
decoder := json.NewDecoder(themeFile)
themeLoadError := decoder.Decode(&theme)
//io.EOF would mean empty, therefore we use defaults.
if themeLoadError != nil && themeLoadError != io.EOF {
return themeLoadError
}
return nil
}