feat(ui/chat): add configurable indentation for guilds tree (#617)

Signed-off-by: xqrs <3bd3bdr@gmail.com>
Co-authored-by: ayn2op <ayn2op@gmail.com>
This commit is contained in:
xqrs 2026-03-01 12:31:28 +03:00 • committed by GitHub
parent ff6f8f9ad0
commit bab0ee8856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 8 deletions

View file

@ -197,6 +197,15 @@ auto_expand_folders = true
graphics = true
graphics_color = "default"
# Guilds tree indentation for different item types
[theme.guilds_tree.indents]
dm = 2
group_dm = 1
guild = 2 # server inside a folder
category = 1
channel = 2
forum = 2
[theme.scroll_bar]
visibility = "auto"
# "minimal", "box_drawing", or "unicode"

View file

@ -203,9 +203,19 @@ type (
}
GuildsTreeTheme struct {
AutoExpandFolders bool `toml:"auto_expand_folders"`
Graphics bool `toml:"graphics"`
GraphicsColor string `toml:"graphics_color"`
AutoExpandFolders bool `toml:"auto_expand_folders"`
Graphics bool `toml:"graphics"`
GraphicsColor string `toml:"graphics_color"`
Indents GuildsTreeIndents `toml:"indents"`
}
GuildsTreeIndents struct {
Guild int `toml:"guild"`
Category int `toml:"category"`
Channel int `toml:"channel"`
Forum int `toml:"forum"`
GroupDM int `toml:"group_dm"`
DM int `toml:"dm"`
}
MessagesListTheme struct {

View file

@ -193,7 +193,11 @@ func (gt *guildsTree) getChannelNodeStyle(channelID discord.ChannelID) tcell.Sty
}
func (gt *guildsTree) createGuildNode(n *tview.TreeNode, guild discord.Guild) {
guildNode := tview.NewTreeNode(guild.Name).SetReference(guild.ID).SetExpandable(true).SetExpanded(false)
guildNode := tview.NewTreeNode(guild.Name).
SetReference(guild.ID).
SetExpandable(true).
SetExpanded(false).
SetIndent(gt.cfg.Theme.GuildsTree.Indents.Guild)
gt.setNodeLineStyle(guildNode, gt.getGuildNodeStyle(guild.ID))
n.AddChild(guildNode)
gt.guildNodeByID[guild.ID] = guildNode
@ -205,12 +209,24 @@ func (gt *guildsTree) createChannelNode(node *tview.TreeNode, channel discord.Ch
}
channelNode := tview.NewTreeNode(ui.ChannelToString(channel, gt.cfg.Icons, gt.chatView.state)).SetReference(channel.ID)
if channel.Type == discord.GuildForum {
channelNode.SetExpandable(true).SetExpanded(false)
}
gt.setNodeLineStyle(channelNode, gt.getChannelNodeStyle(channel.ID))
switch channel.Type {
case discord.DirectMessage:
channelNode.SetIndent(gt.cfg.Theme.GuildsTree.Indents.DM)
case discord.GroupDM:
channelNode.SetIndent(gt.cfg.Theme.GuildsTree.Indents.GroupDM)
case discord.GuildCategory:
channelNode.SetIndent(gt.cfg.Theme.GuildsTree.Indents.Category)
channelNode.SetExpandable(true).SetExpanded(true)
case discord.GuildForum:
channelNode.SetIndent(gt.cfg.Theme.GuildsTree.Indents.Forum)
channelNode.SetExpandable(true).SetExpanded(false)
default:
channelNode.SetIndent(gt.cfg.Theme.GuildsTree.Indents.Channel)
}
node.AddChild(channelNode)
gt.channelNodeByID[channel.ID] = channelNode
gt.setNodeLineStyle(channelNode, gt.getChannelNodeStyle(channel.ID))
}
func (gt *guildsTree) setNodeLineStyle(node *tview.TreeNode, style tcell.Style) {
@ -283,7 +299,7 @@ func (gt *guildsTree) onSelected(node *tview.TreeNode) {
case discord.ChannelID:
channel, err := gt.chatView.state.Cabinet.Channel(ref)
if err != nil {
slog.Error("failed to get channel from state", "channel_id", ref)
slog.Error("failed to get channel from state", "err", err, "channel_id", ref)
return
}