Parcourir la source

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

Signed-off-by: xqrs <3bd3bdr@gmail.com>
Co-authored-by: ayn2op <ayn2op@gmail.com>
xqrs il y a 2 mois
Parent
commit
bab0ee8856
3 fichiers modifiés avec 42 ajouts et 7 suppressions
  1. 9 0
      internal/config/config.toml
  2. 13 3
      internal/config/theme.go
  3. 20 4
      internal/ui/chat/guilds_tree.go

+ 9 - 0
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"

+ 13 - 3
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 {

+ 20 - 4
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 {
+	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)
 	}
-	gt.setNodeLineStyle(channelNode, gt.getChannelNodeStyle(channel.ID))
 	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
 		}