Add super basic theming support
MODIFY
app/app.go
app/app.go
@@ -40,7 +40,10 @@ func Run() {
log.Fatalf("Unable to determine configuration directory (%s)\n", configErr.Error())
}
- defineColorTheme()
+ themeLoadingError := config.LoadTheme()
+ if themeLoadingError == nil {
+ tview.Styles = *config.GetTheme().Theme
+ }
app := tview.NewApplication()
splashScreen := tview.NewTextView()

DELETE
app/app_nonwindows.go
-// +build !windows
-
-package app
-
-import (
- "github.com/Bios-Marcel/tview"
- "github.com/gdamore/tcell"
-)
-
-func defineColorTheme() {
- tview.Styles.PrimitiveBackgroundColor = tcell.NewRGBColor(70, 70, 70)
- tview.Styles.ContrastBackgroundColor = tcell.NewRGBColor(104, 142, 196)
- tview.Styles.MoreContrastBackgroundColor = tcell.NewRGBColor(79, 79, 79)
- tview.Styles.BorderColor = tcell.NewRGBColor(213, 220, 229)
- tview.Styles.BorderFocusColor = tcell.NewRGBColor(104, 142, 196)
- tview.Styles.TitleColor = tcell.ColorWhite
- tview.Styles.GraphicsColor = tcell.ColorWhite
- tview.Styles.PrimaryTextColor = tcell.ColorWhite
- tview.Styles.SecondaryTextColor = tcell.ColorWhite
- tview.Styles.TertiaryTextColor = tcell.ColorWhite
- tview.Styles.InverseTextColor = tcell.NewRGBColor(104, 142, 196)
- tview.Styles.ContrastSecondaryTextColor = tcell.NewRGBColor(104, 142, 196)
-}

DELETE
app/app_windows.go
-package app
-
-func defineColorTheme() {
- //Windows uses the defaults
-}

MODIFY
config/theme.go
config/theme.go
@@ -21,6 +21,11 @@ var (
theme = createDefaultTheme()
)
+// GetTheme returns a pointer to the currently loaded Theme.
+func GetTheme() *Theme {
+ return theme
+}
+
func createDefaultTheme() *Theme {
return &Theme{&tview.Theme{
PrimitiveBackgroundColor: tcell.ColorBlack,
@@ -38,6 +43,7 @@ func createDefaultTheme() *Theme {
}}
}
+// GetThemeFile returns the path to the theme file.
func GetThemeFile() (string, error) {
configDir, configError := GetConfigDirectory()
@@ -48,20 +54,22 @@ func GetThemeFile() (string, error) {
return filepath.Join(configDir, "theme.json"), nil
}
-func LoadTheme() (*Theme, error) {
+// 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 nil, themeError
+ return themeError
}
themeFile, openError := os.Open(themeFilePath)
if os.IsNotExist(openError) {
- return theme, nil
+ return nil
}
if openError != nil {
- return nil, openError
+ return openError
}
defer themeFile.Close()
@@ -70,8 +78,8 @@ func LoadTheme() (*Theme, error) {
//io.EOF would mean empty, therefore we use defaults.
if themeLoadError != nil && themeLoadError != io.EOF {
- return nil, themeLoadError
+ return themeLoadError
}
- return theme, nil
+ return nil
}

ADD
tools/theme/theme.go
+package main
+
+import (
+ "encoding/json"
+ "os"
+
+ "github.com/Bios-Marcel/cordless/config"
+ "github.com/Bios-Marcel/tview"
+ "github.com/gdamore/tcell"
+)
+
+func main() {
+ theme := &config.Theme{&tview.Theme{
+ PrimitiveBackgroundColor: tcell.NewRGBColor(70, 70, 70),
+ ContrastBackgroundColor: tcell.NewRGBColor(104, 142, 196),
+ MoreContrastBackgroundColor: tcell.NewRGBColor(79, 79, 79),
+ BorderColor: tcell.NewRGBColor(213, 220, 229),
+ BorderFocusColor: tcell.NewRGBColor(104, 142, 196),
+ TitleColor: tcell.ColorWhite,
+ GraphicsColor: tcell.ColorWhite,
+ PrimaryTextColor: tcell.ColorWhite,
+ SecondaryTextColor: tcell.ColorWhite,
+ TertiaryTextColor: tcell.ColorWhite,
+ InverseTextColor: tcell.NewRGBColor(104, 142, 196),
+ ContrastSecondaryTextColor: tcell.NewRGBColor(104, 142, 196),
+ }}
+
+ encoder := json.NewEncoder(os.Stdout)
+ encoder.SetIndent("", " ")
+ encoder.Encode(theme)
+}

Add super basic theming support