Ver código fonte

Clear screen if the background color is set as ColorDefault (#207)

ayntgl 3 anos atrás
pai
commit
277e314146
3 arquivos alterados com 35 adições e 16 exclusões
  1. 1 1
      config/config.lua
  2. 0 15
      main.go
  3. 34 0
      ui/core.go

+ 1 - 1
config/config.lua

@@ -104,4 +104,4 @@ keys = {
 }
 
 -- Theme
-theme = {background = "#1F2430", border = "white", title = "white"}
+theme = {background = "default", border = "white", title = "white"}

+ 0 - 15
main.go

@@ -8,9 +8,7 @@ import (
 
 	"github.com/ayntgl/discordo/config"
 	"github.com/ayntgl/discordo/ui"
-	"github.com/gdamore/tcell/v2"
 	"github.com/rivo/tview"
-	lua "github.com/yuin/gopher-lua"
 	"github.com/zalando/go-keyring"
 )
 
@@ -103,19 +101,6 @@ func main() {
 	tview.Borders.Horizontal = 0
 	tview.Borders.Vertical = 0
 
-	themeTable, ok := c.Config.State.GetGlobal("theme").(*lua.LTable)
-	if !ok {
-		themeTable = c.Config.State.NewTable()
-	}
-
-	background := themeTable.RawGetString("background")
-	border := themeTable.RawGetString("border")
-	title := themeTable.RawGetString("title")
-
-	tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(lua.LVAsString(background))
-	tview.Styles.BorderColor = tcell.GetColor(lua.LVAsString(border))
-	tview.Styles.TitleColor = tcell.GetColor(lua.LVAsString(title))
-
 	err = c.Application.Run()
 	if err != nil {
 		log.Fatal(err)

+ 34 - 0
ui/core.go

@@ -65,6 +65,40 @@ func (c *Core) Run(token string) error {
 		return err
 	}
 
+	themeTable, ok := c.Config.State.GetGlobal("theme").(*lua.LTable)
+	if !ok {
+		themeTable = c.Config.State.NewTable()
+	}
+
+	backgroundColor := tcell.GetColor(lua.LVAsString(themeTable.RawGetString("background")))
+	borderColor := tcell.GetColor(lua.LVAsString(themeTable.RawGetString("border")))
+	titleColor := tcell.GetColor(lua.LVAsString(themeTable.RawGetString("title")))
+
+	c.GuildsTree.SetBackgroundColor(backgroundColor)
+	c.GuildsTree.SetBorderColor(borderColor)
+	c.GuildsTree.SetTitleColor(titleColor)
+
+	c.ChannelsTree.SetBackgroundColor(backgroundColor)
+	c.ChannelsTree.SetBorderColor(borderColor)
+	c.ChannelsTree.SetTitleColor(titleColor)
+
+	c.MessagesPanel.SetBackgroundColor(backgroundColor)
+	c.MessagesPanel.SetBorderColor(borderColor)
+	c.MessagesPanel.SetTitleColor(titleColor)
+
+	c.MessageInput.SetBackgroundColor(backgroundColor)
+	c.MessageInput.SetBorderColor(borderColor)
+	c.MessageInput.SetTitleColor(titleColor)
+	c.MessageInput.SetPlaceholderStyle(tcell.StyleDefault.Background(backgroundColor))
+
+	c.Application.SetBeforeDrawFunc(func(s tcell.Screen) bool {
+		if backgroundColor == 0 {
+			s.Clear()
+		}
+
+		return false
+	})
+
 	c.Application.EnableMouse(lua.LVAsBool(c.Config.State.GetGlobal("mouse")))
 
 	identifyProperties, ok := c.Config.State.GetGlobal("identifyProperties").(*lua.LTable)