feat(config): add configurable icons for guilds tree (#722)

This commit is contained in:
Ayyan 2026-01-21 10:31:46 -05:00 • committed by GitHub
parent 56b89ba503
commit 314bad64cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 55 additions and 14 deletions

View file

@ -36,6 +36,21 @@ type (
Receive bool `toml:"receive"`
}
Icons struct {
GuildCategory string `toml:"guild_category"`
GuildText string `toml:"guild_text"`
GuildVoice string `toml:"guild_voice"`
GuildStageVoice string `toml:"guild_stage_voice"`
GuildAnnouncementThread string `toml:"guild_announcement_thread"`
GuildPublicThread string `toml:"guild_public_thread"`
GuildPrivateThread string `toml:"guild_private_thread"`
GuildAnnouncement string `toml:"guild_announcement"`
GuildForum string `toml:"guild_forum"`
GuildStore string `toml:"guild_store"`
}
Config struct {
AutoFocus bool `toml:"auto_focus"`
Mouse bool `toml:"mouse"`
@ -55,6 +70,8 @@ type (
Notifications Notifications `toml:"notifications"`
TypingIndicator TypingIndicator `toml:"typing_indicator"`
Icons Icons `toml:"icons"`
Keys Keys `toml:"keys"`
Theme Theme `toml:"theme"`
}

View file

@ -41,6 +41,18 @@ send = true
# Whether to receive typing status or not.
receive = true
[icons]
guild_category = ""
guild_text = "#"
guild_voice = "♪ "
guild_stage_voice = "♪ "
guild_announcement_thread = "a-"
guild_public_thread = "› "
guild_private_thread = "› "
guild_announcement = "a-"
guild_forum = "≡ "
guild_store = "s-"
# Global shortcuts
# Esc: Reset message selection or close the channel selection popup.
[keys]

View file

@ -99,7 +99,7 @@ func (gt *guildsTree) createChannelNode(node *tview.TreeNode, channel discord.Ch
return
}
channelNode := tview.NewTreeNode(ui.ChannelToString(channel)).
channelNode := tview.NewTreeNode(ui.ChannelToString(channel, gt.cfg.Icons)).
SetReference(channel.ID).
SetTextStyle(gt.getChannelNodeStyle(channel.ID))
node.AddChild(channelNode)

View file

@ -74,7 +74,7 @@ func (ml *messagesList) reset() {
}
func (ml *messagesList) setTitle(channel discord.Channel) {
title := ui.ChannelToString(channel)
title := ui.ChannelToString(channel, ml.cfg.Icons)
if topic := channel.Topic; topic != "" {
title += " - " + topic
}

View file

@ -58,7 +58,8 @@ func Centered(p tview.Primitive, width, height int) tview.Primitive {
AddItem(p, 1, 1, 1, 1, 0, 0, true)
}
func ChannelToString(channel discord.Channel) string {
func ChannelToString(channel discord.Channel, icons config.Icons) string {
var icon string
switch channel.Type {
case discord.DirectMessage, discord.GroupDM:
if channel.Name != "" {
@ -71,19 +72,30 @@ func ChannelToString(channel discord.Channel) string {
}
return strings.Join(recipients, ", ")
case discord.GuildCategory:
icon = icons.GuildCategory
case discord.GuildText:
return "#" + channel.Name
case discord.GuildVoice, discord.GuildStageVoice:
return "v-" + channel.Name
icon = icons.GuildText
case discord.GuildVoice:
icon = icons.GuildVoice
case discord.GuildStageVoice:
icon = icons.GuildStageVoice
case discord.GuildAnnouncementThread:
icon = icons.GuildAnnouncementThread
case discord.GuildPublicThread:
icon = icons.GuildPublicThread
case discord.GuildPrivateThread:
icon = icons.GuildPrivateThread
case discord.GuildAnnouncement:
return "a-" + channel.Name
case discord.GuildStore:
return "s-" + channel.Name
icon = icons.GuildAnnouncement
case discord.GuildForum:
return "f-" + channel.Name
case discord.GuildPublicThread, discord.GuildPrivateThread, discord.GuildAnnouncementThread:
return "t-" + channel.Name
default:
return channel.Name
icon = icons.GuildForum
case discord.GuildStore:
icon = icons.GuildStore
}
return icon + channel.Name
}