From 02ca5019c7a6fa7348da268cf8d97692b09e4014 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Wed, 30 Sep 2026 17:32:55 -0400 Subject: [PATCH] refactor(config): share the tree status style --- internal/config/theme.go | 35 +++++++++++++++++++-------- internal/ui/chat/guildstree/model.go | 17 ++----------- internal/ui/chat/memberstree/model.go | 16 +----------- 3 files changed, 28 insertions(+), 40 deletions(-) diff --git a/internal/config/theme.go b/internal/config/theme.go index 69e8970..0f96f43 100644 --- a/internal/config/theme.go +++ b/internal/config/theme.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" + "github.com/ayn2op/arikawa/v3/discord" "github.com/ayn2op/tview" "github.com/ayn2op/tview/list" "github.com/ayn2op/tview/scrollbar" @@ -208,16 +209,6 @@ type ( ActiveSet BorderSetWrapper `toml:"active_set"` } - CommonTreeTheme struct { - Graphics bool `toml:"graphics"` - GraphicsColor string `toml:"graphics_color"` - - OnlineStyle StyleWrapper `toml:"online_style"` - IdleStyle StyleWrapper `toml:"idle_style"` - DNDStyle StyleWrapper `toml:"dnd_style"` - OfflineStyle StyleWrapper `toml:"offline_style"` - } - GuildsTreeTheme struct { CommonTreeTheme AutoExpandFolders bool `toml:"auto_expand_folders"` @@ -281,3 +272,27 @@ type ( Help HelpTheme `toml:"help"` } ) + +type CommonTreeTheme struct { + Graphics bool `toml:"graphics"` + GraphicsColor string `toml:"graphics_color"` + + OnlineStyle StyleWrapper `toml:"online_style"` + IdleStyle StyleWrapper `toml:"idle_style"` + DNDStyle StyleWrapper `toml:"dnd_style"` + OfflineStyle StyleWrapper `toml:"offline_style"` +} + +// StatusStyle returns the style for a user with status. +func (ctt CommonTreeTheme) StatusStyle(status discord.Status) tcell.Style { + switch status { + case discord.OnlineStatus: + return ctt.OnlineStyle.Style + case discord.IdleStatus: + return ctt.IdleStyle.Style + case discord.DoNotDisturbStatus: + return ctt.DNDStyle.Style + default: + return ctt.OfflineStyle.Style + } +} diff --git a/internal/ui/chat/guildstree/model.go b/internal/ui/chat/guildstree/model.go index a3791cc..7062adf 100644 --- a/internal/ui/chat/guildstree/model.go +++ b/internal/ui/chat/guildstree/model.go @@ -182,23 +182,10 @@ func (m *Model) channelNodeStyle(channel discord.Channel) tcell.Style { recipient := channel.DMRecipients[0] presence, err := m.state.Cabinet.Presence(discord.NullGuildID, recipient.ID) if err != nil { - return tview.MergeStyle(m.dmStatusStyle(discord.OfflineStatus), unread) + return tview.MergeStyle(m.cfg.Theme.GuildsTree.StatusStyle(discord.OfflineStatus), unread) } - return tview.MergeStyle(m.dmStatusStyle(presence.Status), unread) -} - -func (m *Model) dmStatusStyle(status discord.Status) tcell.Style { - switch status { - case discord.DoNotDisturbStatus: - return m.cfg.Theme.GuildsTree.DNDStyle.Style - case discord.IdleStatus: - return m.cfg.Theme.GuildsTree.IdleStyle.Style - case discord.OnlineStatus: - return m.cfg.Theme.GuildsTree.OnlineStyle.Style - default: - return m.cfg.Theme.GuildsTree.OfflineStyle.Style - } + return tview.MergeStyle(m.cfg.Theme.GuildsTree.StatusStyle(presence.Status), unread) } func (m *Model) createGuildNode(parent *tree.Node, guild discord.Guild) { diff --git a/internal/ui/chat/memberstree/model.go b/internal/ui/chat/memberstree/model.go index e9c3a4e..9d23ecd 100644 --- a/internal/ui/chat/memberstree/model.go +++ b/internal/ui/chat/memberstree/model.go @@ -260,7 +260,7 @@ const statusMarker = "●" // setStatus styles the status dot and name of a member line for status. func (m *Model) setStatus(line richtext.Line, status discord.Status) { - line[0].Style = m.statusStyle(status) + line[0].Style = m.cfg.Theme.MembersTree.StatusStyle(status) line[2].Style = line[2].Style.Dim(status == discord.OfflineStatus) } @@ -290,20 +290,6 @@ func (m *Model) status(guildID discord.GuildID, userID discord.UserID) discord.S return presence.Status } -func (m *Model) statusStyle(status discord.Status) tcell.Style { - theme := &m.cfg.Theme.MembersTree - switch status { - case discord.OnlineStatus: - return theme.OnlineStyle.Style - case discord.IdleStatus: - return theme.IdleStyle.Style - case discord.DoNotDisturbStatus: - return theme.DNDStyle.Style - default: - return theme.OfflineStyle.Style - } -} - // statusRank orders members as Discord does: online, idle, do not disturb, then offline. func statusRank(status discord.Status) int { switch status {