refactor(config): share the tree status style
This commit is contained in:
parent
32aed22618
commit
02ca5019c7
3 changed files with 28 additions and 40 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue