From bab0ee885642eaf03dba7fc61ae2a5616a99ec9c Mon Sep 17 00:00:00 2001 From: xqrs <3bd3bdr@gmail.com> Date: Sun, 1 Mar 2026 12:31:28 +0300 Subject: [PATCH] feat(ui/chat): add configurable indentation for guilds tree (#617) Signed-off-by: xqrs <3bd3bdr@gmail.com> Co-authored-by: ayn2op --- internal/config/config.toml | 9 +++++++++ internal/config/theme.go | 16 +++++++++++++--- internal/ui/chat/guilds_tree.go | 26 +++++++++++++++++++++----- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/internal/config/config.toml b/internal/config/config.toml index e9ac182..e2bfaa9 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -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" diff --git a/internal/config/theme.go b/internal/config/theme.go index 193c22d..1320b79 100644 --- a/internal/config/theme.go +++ b/internal/config/theme.go @@ -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 { diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index 78a083c..82fff9a 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -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 }