From 212b28aef40e024e7b2a3bb4c4bbbfeb27129982 Mon Sep 17 00:00:00 2001 From: Ayyan Date: Sat, 29 Mar 2025 00:43:32 -0400 Subject: [PATCH] feat(config): add theme.border.active_color (#522) --- cmd/guilds_tree.go | 38 ++++++++++++++---------- cmd/message_input.go | 41 +++++++++++++++----------- cmd/messages_text.go | 63 +++++++++++++++++++++++----------------- internal/config/theme.go | 22 ++++++++++---- 4 files changed, 98 insertions(+), 66 deletions(-) diff --git a/cmd/guilds_tree.go b/cmd/guilds_tree.go index 899de4c..5b01ee4 100644 --- a/cmd/guilds_tree.go +++ b/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) + t := cfg.Theme + gt. + SetRoot(tview.NewTreeNode("")). + SetTopLevel(1). + SetGraphics(t.GuildsTree.Graphics). + SetSelectedFunc(gt.onSelected) - gt.SetTopLevel(1) - gt.SetGraphics(cfg.Theme.GuildsTree.Graphics) - gt.SetBackgroundColor(tcell.GetColor(cfg.Theme.BackgroundColor)) - gt.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.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]) - - gt.SetInputCapture(gt.onInputCapture) return gt } diff --git a/cmd/message_input.go b/cmd/message_input.go index d86c810..9233745 100644 --- a/cmd/message_input.go +++ b/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 - }) + 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 + }) - 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]) + 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 } diff --git a/cmd/messages_text.go b/cmd/messages_text.go index 359d5d7..da7e8ae 100644 --- a/cmd/messages_text.go +++ b/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() - }) + t := cfg.Theme + mt. + SetDynamicColors(true). + SetRegions(true). + SetWordWrap(true). + ScrollToEnd(). + SetTextColor(tcell.GetColor(t.MessagesText.ContentColor)). + SetHighlightedFunc(mt.onHighlighted). + 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) - - 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: diff --git a/internal/config/theme.go b/internal/config/theme.go index f665fe7..ab140b0 100644 --- a/internal/config/theme.go +++ b/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",