فهرست منبع

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

ayntgl 4 سال پیش
والد
کامیت
80179a8246
2فایلهای تغییر یافته به همراه41 افزوده شده و 5 حذف شده
  1. 28 4
      config.go
  2. 13 1
      main.go

+ 28 - 4
config.go

@@ -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]",
 

+ 13 - 1
main.go

@@ -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()