Kaynağa Gözat

feat(config): add theme.border.active_color (#522)

Ayyan 1 yıl önce
ebeveyn
işleme
212b28aef4
4 değiştirilmiş dosya ile 100 ekleme ve 68 silme
  1. 23 17
      cmd/guilds_tree.go
  2. 25 18
      cmd/message_input.go
  3. 36 27
      cmd/messages_text.go
  4. 16 6
      internal/config/theme.go

+ 23 - 17
cmd/guilds_tree.go

@@ -28,24 +28,30 @@ func newGuildsTree(app *tview.Application, cfg *config.Config) *GuildsTree {
 		app:      app,
 	}
 
-	root := tview.NewTreeNode("")
-	gt.SetRoot(root)
-
-	gt.SetTopLevel(1)
-	gt.SetGraphics(cfg.Theme.GuildsTree.Graphics)
-	gt.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
-	gt.SetSelectedFunc(gt.onSelected)
-
-	gt.SetTitle("Guilds")
-	gt.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
-	gt.SetTitleAlign(tview.AlignLeft)
-
-	p := cfg.Theme.BorderPadding
-	gt.SetBorder(cfg.Theme.Border)
-	gt.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
-	gt.SetBorderPadding(p[0], p[1], p[2], p[3])
+	t := cfg.Theme
+	gt.
+		SetRoot(tview.NewTreeNode("")).
+		SetTopLevel(1).
+		SetGraphics(t.GuildsTree.Graphics).
+		SetSelectedFunc(gt.onSelected)
+
+	b := t.Border
+	p := b.Padding
+	gt.
+		SetInputCapture(gt.onInputCapture).
+		SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor)).
+		SetTitle("Guilds").
+		SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor)).
+		SetTitleAlign(tview.AlignLeft).
+		SetBorder(b.Enabled).
+		SetBorderPadding(p[0], p[1], p[2], p[3]).
+		SetFocusFunc(func() {
+			gt.SetBorderColor(tcell.GetColor(b.ActiveColor))
+		}).
+		SetBlurFunc(func() {
+			gt.SetBorderColor(tcell.GetColor(b.Color))
+		})
 
-	gt.SetInputCapture(gt.onInputCapture)
 	return gt
 }
 

+ 25 - 18
cmd/message_input.go

@@ -32,24 +32,31 @@ func newMessageInput(app *tview.Application, cfg *config.Config) *MessageInput {
 		app:      app,
 	}
 
-	mi.SetTextStyle(tcell.StyleDefault.Background(tcell.GetColor(cfg.Theme.BackgroundColor)))
-	mi.SetClipboard(func(s string) {
-		_ = clipboard.WriteAll(s)
-	}, func() string {
-		text, _ := clipboard.ReadAll()
-		return text
-	})
-
-	mi.SetInputCapture(mi.onInputCapture)
-	mi.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor))
-
-	mi.SetTitleColor(tcell.GetColor(cfg.Theme.TitleColor))
-	mi.SetTitleAlign(tview.AlignLeft)
-
-	p := cfg.Theme.BorderPadding
-	mi.SetBorder(cfg.Theme.Border)
-	mi.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
-	mi.SetBorderPadding(p[0], p[1], p[2], p[3])
+	t := cfg.Theme
+	mi.
+		SetTextStyle(tcell.StyleDefault.Background(tcell.GetColor(t.BackgroundColor))).
+		SetClipboard(func(s string) {
+			_ = clipboard.WriteAll(s)
+		}, func() string {
+			text, _ := clipboard.ReadAll()
+			return text
+		})
+
+	b := t.Border
+	p := b.Padding
+	mi.
+		SetInputCapture(mi.onInputCapture).
+		SetBackgroundColor(tcell.GetColor(t.BackgroundColor)).
+		SetTitleColor(tcell.GetColor(t.TitleColor)).
+		SetTitleAlign(tview.AlignLeft).
+		SetBorder(b.Enabled).
+		SetBorderPadding(p[0], p[1], p[2], p[3]).
+		SetFocusFunc(func() {
+			mi.SetBorderColor(tcell.GetColor(b.ActiveColor))
+		}).
+		SetBlurFunc(func() {
+			mi.SetBorderColor(tcell.GetColor(b.Color))
+		})
 
 	return mi
 }

+ 36 - 27
cmd/messages_text.go

@@ -38,34 +38,40 @@ func newMessagesText(app *tview.Application, cfg *config.Config) *MessagesText {
 		app:      app,
 	}
 
-	mt.SetDynamicColors(true)
-	mt.SetRegions(true)
-	mt.SetWordWrap(true)
-	mt.SetInputCapture(mt.onInputCapture)
-	mt.ScrollToEnd()
-	mt.SetChangedFunc(func() {
-		app.Draw()
-	})
-
-	mt.SetTextColor(tcell.GetColor(mt.cfg.Theme.MessagesText.ContentColor))
-	mt.SetBackgroundColor(tcell.GetColor(mt.cfg.Theme.BackgroundColor))
-
-	mt.SetTitle("Messages")
-	mt.SetTitleColor(tcell.GetColor(mt.cfg.Theme.TitleColor))
-	mt.SetTitleAlign(tview.AlignLeft)
+	t := cfg.Theme
+	mt.
+		SetDynamicColors(true).
+		SetRegions(true).
+		SetWordWrap(true).
+		ScrollToEnd().
+		SetTextColor(tcell.GetColor(t.MessagesText.ContentColor)).
+		SetHighlightedFunc(mt.onHighlighted).
+		SetChangedFunc(func() {
+			app.Draw()
+		})
 
-	p := mt.cfg.Theme.BorderPadding
-	mt.SetBorder(mt.cfg.Theme.Border)
-	mt.SetBorderColor(tcell.GetColor(mt.cfg.Theme.BorderColor))
-	mt.SetBorderPadding(p[0], p[1], p[2], p[3])
+	b := t.Border
+	p := b.Padding
+	mt.
+		SetInputCapture(mt.onInputCapture).
+		SetBackgroundColor(tcell.GetColor(t.BackgroundColor)).
+		SetTitle("Messages").
+		SetTitleColor(tcell.GetColor(t.TitleColor)).
+		SetTitleAlign(tview.AlignLeft).
+		SetBorder(b.Enabled).
+		SetBorderPadding(p[0], p[1], p[2], p[3]).
+		SetFocusFunc(func() {
+			mt.SetBorderColor(tcell.GetColor(b.ActiveColor))
+		}).
+		SetBlurFunc(func() {
+			mt.SetBorderColor(tcell.GetColor(b.Color))
+		})
 
 	markdown.DefaultRenderer.AddOptions(
-		renderer.WithOption("emojiColor", mt.cfg.Theme.MessagesText.EmojiColor),
-		renderer.WithOption("linkColor", mt.cfg.Theme.MessagesText.LinkColor),
+		renderer.WithOption("emojiColor", t.MessagesText.EmojiColor),
+		renderer.WithOption("linkColor", t.MessagesText.LinkColor),
 	)
 
-	mt.SetHighlightedFunc(mt.onHighlighted)
-
 	return mt
 }
 
@@ -397,11 +403,14 @@ func (mt *MessagesText) showUrlSelector(urls []string, attachments []discord.Att
 		ShowSecondaryText(false).
 		SetDoneFunc(done)
 
-	p := mt.cfg.Theme.BorderPadding
+	b := mt.cfg.Theme.Border
+	p := b.Padding
+	list.
+		SetBorder(b.Enabled).
+		SetBorderColor(tcell.GetColor(b.Color)).
+		SetBorderPadding(p[0], p[1], p[2], p[3])
+
 	list.
-		SetBorder(mt.cfg.Theme.Border).
-		SetBorderColor(tcell.GetColor(mt.cfg.Theme.BorderColor)).
-		SetBorderPadding(p[0], p[1], p[2], p[3]).
 		SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
 			switch event.Name() {
 			case mt.cfg.Keys.MessagesText.SelectPrevious:

+ 16 - 6
internal/config/theme.go

@@ -3,10 +3,16 @@ package config
 import "github.com/rivo/tview"
 
 type (
+	BorderTheme struct {
+		Enabled bool   `toml:"enabled"`
+		Padding [4]int `toml:"padding"`
+
+		Color       string `toml:"color"`
+		ActiveColor string `toml:"active_color"`
+	}
+
 	Theme struct {
-		Border        bool   `toml:"border"`
-		BorderColor   string `toml:"border_color"`
-		BorderPadding [4]int `toml:"border_padding"`
+		Border BorderTheme `toml:"border"`
 
 		TitleColor      string `toml:"title_color"`
 		BackgroundColor string `toml:"background_color"`
@@ -36,9 +42,13 @@ type (
 
 func defaultTheme() Theme {
 	return Theme{
-		Border:        true,
-		BorderColor:   "default",
-		BorderPadding: [...]int{0, 0, 1, 1},
+		Border: BorderTheme{
+			Enabled: true,
+			Padding: [...]int{0, 0, 1, 1},
+
+			Color:       "default",
+			ActiveColor: "gold",
+		},
 
 		BackgroundColor: "default",
 		TitleColor:      "default",