Browse Source

refactor(util): remove *{Background,Foreground} in favor of Background & Foreground

rigormorrtiss 4 years ago
parent
commit
4bf8085239
5 changed files with 11 additions and 17 deletions
  1. 4 2
      discordo.go
  2. 3 3
      ui/inputfields.go
  3. 1 4
      ui/textviews.go
  4. 1 4
      ui/treeviews.go
  5. 2 4
      util/config.go

+ 4 - 2
discordo.go

@@ -46,9 +46,11 @@ func main() {
 	tview.Borders.BottomRight = ' '
 
 	conf = util.NewConfig()
+	tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(conf.Theme.Background)
+
 	app = ui.NewApp(onAppInputCapture)
-	guildsTreeView = ui.NewGuildsTreeView(onGuildsTreeViewSelected, conf.Theme)
-	messagesTextView = ui.NewMessagesTextView(app, conf.Theme)
+	guildsTreeView = ui.NewGuildsTreeView(onGuildsTreeViewSelected)
+	messagesTextView = ui.NewMessagesTextView(app)
 	messageInputField = ui.NewMessageInputField(onMessageInputFieldInputCapture, conf.Theme)
 	mainFlex = ui.NewMainFlex(guildsTreeView, messagesTextView, messageInputField)
 

+ 3 - 3
ui/inputfields.go

@@ -6,13 +6,13 @@ import (
 	"github.com/rivo/tview"
 )
 
-func NewMessageInputField(onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey, theme *util.Theme) (i *tview.InputField) {
+func NewMessageInputField(onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey, t *util.Theme) (i *tview.InputField) {
 	i = tview.NewInputField()
 	i.
 		SetPlaceholder("Message...").
 		SetPlaceholderTextColor(tcell.ColorWhite).
-		SetFieldBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
-		SetBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
+		SetFieldBackgroundColor(tcell.GetColor(t.Background)).
+		SetBackgroundColor(tcell.GetColor(t.Background)).
 		SetInputCapture(onMessageInputFieldInputCapture).
 		SetBorder(true).
 		SetBorderPadding(0, 0, 1, 0)

+ 1 - 4
ui/textviews.go

@@ -1,12 +1,10 @@
 package ui
 
 import (
-	"github.com/gdamore/tcell/v2"
-	"github.com/rigormorrtiss/discordo/util"
 	"github.com/rivo/tview"
 )
 
-func NewMessagesTextView(app *tview.Application, theme *util.Theme) (textV *tview.TextView) {
+func NewMessagesTextView(app *tview.Application) (textV *tview.TextView) {
 	textV = tview.NewTextView()
 	textV.
 		SetDynamicColors(true).
@@ -15,7 +13,6 @@ func NewMessagesTextView(app *tview.Application, theme *util.Theme) (textV *tvie
 		SetChangedFunc(func() {
 			app.Draw()
 		}).
-		SetBackgroundColor(tcell.GetColor(theme.TextViewBackground)).
 		SetBorder(true).
 		SetBorderPadding(0, 0, 1, 0).
 		SetTitleAlign(tview.AlignLeft)

+ 1 - 4
ui/treeviews.go

@@ -1,12 +1,10 @@
 package ui
 
 import (
-	"github.com/gdamore/tcell/v2"
-	"github.com/rigormorrtiss/discordo/util"
 	"github.com/rivo/tview"
 )
 
-func NewGuildsTreeView(onGuildsTreeViewSelected func(*tview.TreeNode), theme *util.Theme) (treeV *tview.TreeView) {
+func NewGuildsTreeView(onGuildsTreeViewSelected func(*tview.TreeNode)) (treeV *tview.TreeView) {
 	treeV = tview.NewTreeView()
 	treeN := tview.NewTreeNode("")
 	treeV.
@@ -14,7 +12,6 @@ func NewGuildsTreeView(onGuildsTreeViewSelected func(*tview.TreeNode), theme *ut
 		SetRoot(treeN).
 		SetCurrentNode(treeN).
 		SetSelectedFunc(onGuildsTreeViewSelected).
-		SetBackgroundColor(tcell.GetColor(theme.TreeViewBackground)).
 		SetTitle("Guilds").
 		SetBorder(true).
 		SetBorderPadding(0, 0, 1, 0).

+ 2 - 4
util/config.go

@@ -6,10 +6,8 @@ import (
 )
 
 type Theme struct {
-	DropDownBackground   string `json:"dropdown.background"`
-	TreeViewBackground   string `json:"treeview.background"`
-	TextViewBackground   string `json:"textview.background"`
-	InputFieldBackground string `json:"inputField.background"`
+	Background string `json:"background"`
+	Foreground string `json:"foreground"`
 }
 
 type Config struct {