feat: support w3c names and hex value colors in config (#60)

This commit is contained in:
ayntgl 2021-09-27 23:24:21 +04:00 • committed by GitHub
parent 88674c5f4d
commit 80179a8246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View file

@ -3,8 +3,6 @@ package main
import (
"encoding/json"
"os"
"github.com/rivo/tview"
)
var conf *config
@ -23,13 +21,27 @@ type keybindings struct {
MessageInputFieldFocus string
}
type theme struct {
PrimitiveBackgroundColor string // Main background color for primitives.
ContrastBackgroundColor string // Background color for contrasting elements.
MoreContrastBackgroundColor string // Background color for even more contrasting elements.
BorderColor string // Box borders.
TitleColor string // Box titles.
GraphicsColor string // Graphics.
PrimaryTextColor string // Primary text.
SecondaryTextColor string // Secondary text (e.g. labels).
TertiaryTextColor string // Tertiary text (e.g. subtitles, notes).
InverseTextColor string // Text on primary-colored backgrounds.
ContrastSecondaryTextColor string // Secondary text on ContrastBackgroundColor-colored backgrounds.
}
type config struct {
Token string
Mouse bool
Notifications bool
UserAgent string
GetMessagesLimit int
Theme tview.Theme
Theme theme
Keybindings keybindings
}
@ -60,7 +72,19 @@ func loadConfig() *config {
"AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/92.0.4515.131 Safari/537.36",
GetMessagesLimit: 50,
Theme: tview.Styles,
Theme: theme{
PrimitiveBackgroundColor: "black",
ContrastBackgroundColor: "blue",
MoreContrastBackgroundColor: "green",
BorderColor: "white",
TitleColor: "white",
GraphicsColor: "white",
PrimaryTextColor: "white",
SecondaryTextColor: "yellow",
TertiaryTextColor: "green",
InverseTextColor: "blue",
ContrastSecondaryTextColor: "darkcyan",
},
Keybindings: keybindings{
GuildsTreeViewFocus: "Alt+Rune[1]",

14
main.go
View file

@ -1,6 +1,7 @@
package main
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/zalando/go-keyring"
)
@ -9,7 +10,18 @@ const service = "discordo"
func main() {
conf = loadConfig()
tview.Styles = conf.Theme
tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(conf.Theme.PrimitiveBackgroundColor)
tview.Styles.ContrastBackgroundColor = tcell.GetColor(conf.Theme.ContrastBackgroundColor)
tview.Styles.MoreContrastBackgroundColor = tcell.GetColor(conf.Theme.MoreContrastBackgroundColor)
tview.Styles.BorderColor = tcell.GetColor(conf.Theme.BorderColor)
tview.Styles.TitleColor = tcell.GetColor(conf.Theme.TitleColor)
tview.Styles.GraphicsColor = tcell.GetColor(conf.Theme.GraphicsColor)
tview.Styles.PrimaryTextColor = tcell.GetColor(conf.Theme.PrimaryTextColor)
tview.Styles.SecondaryTextColor = tcell.GetColor(conf.Theme.SecondaryTextColor)
tview.Styles.TertiaryTextColor = tcell.GetColor(conf.Theme.TertiaryTextColor)
tview.Styles.InverseTextColor = tcell.GetColor(conf.Theme.InverseTextColor)
tview.Styles.ContrastSecondaryTextColor = tcell.GetColor(conf.Theme.ContrastSecondaryTextColor)
app = newApplication()
channelsTree = newChannelsTree()