浏览代码

feat(ui/chat): add tree markers (#752)

Ayyan 2 月之前
父节点
当前提交
7b585d7548
共有 7 个文件被更改,包括 30 次插入6 次删除
  1. 1 1
      go.mod
  2. 2 2
      go.sum
  3. 11 0
      internal/config/config.go
  4. 5 0
      internal/config/config.toml
  5. 9 1
      internal/ui/chat/guilds_tree.go
  6. 1 1
      internal/ui/chat/keybinds.go
  7. 1 1
      internal/ui/chat/state.go

+ 1 - 1
go.mod

@@ -8,7 +8,7 @@ require (
 	github.com/BurntSushi/toml v1.6.0
 	github.com/alecthomas/chroma/v2 v2.23.1
 	github.com/andybalholm/brotli v1.2.0
-	github.com/ayn2op/tview v0.0.0-20260223065535-6a0c066d0bdd
+	github.com/ayn2op/tview v0.0.0-20260223211434-6859308d597f
 	github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb
 	github.com/diamondburned/arikawa/v3 v3.6.1-0.20260221051847-b81b70d1a5cb
 	github.com/diamondburned/ningen/v3 v3.0.1-0.20250920191746-98fbd92e134d

+ 2 - 2
go.sum

@@ -14,8 +14,8 @@ github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs
 github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
 github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
 github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
-github.com/ayn2op/tview v0.0.0-20260223065535-6a0c066d0bdd h1:DdR19f4xNbd3XM9vxmC9LtF5XY1nv0rDMMzn0FSTwd0=
-github.com/ayn2op/tview v0.0.0-20260223065535-6a0c066d0bdd/go.mod h1:lZ8RdOegQWBQafTOasGE7Ps1/Ymy4jmXoPt5vz2QsS0=
+github.com/ayn2op/tview v0.0.0-20260223211434-6859308d597f h1:ZxDODg1E/RPoTWlXhnhZOKITe1ebBM0Cpy+GiGaa+xk=
+github.com/ayn2op/tview v0.0.0-20260223211434-6859308d597f/go.mod h1:lZ8RdOegQWBQafTOasGE7Ps1/Ymy4jmXoPt5vz2QsS0=
 github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ=
 github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

+ 11 - 0
internal/config/config.go

@@ -74,6 +74,16 @@ type (
 		Separator        string `toml:"separator"`
 	}
 
+	SidebarMarkersConfig struct {
+		Expanded  string `toml:"expanded"`
+		Collapsed string `toml:"collapsed"`
+		Leaf      string `toml:"leaf"`
+	}
+
+	SidebarConfig struct {
+		Markers SidebarMarkersConfig `toml:"markers"`
+	}
+
 	Config struct {
 		AutoFocus bool   `toml:"auto_focus"`
 		Mouse     bool   `toml:"mouse"`
@@ -94,6 +104,7 @@ type (
 		DateSeparator   DateSeparator   `toml:"date_separator"`
 		Notifications   Notifications   `toml:"notifications"`
 		TypingIndicator TypingIndicator `toml:"typing_indicator"`
+		Sidebar         SidebarConfig   `toml:"sidebar"`
 
 		Icons Icons `toml:"icons"`
 

+ 5 - 0
internal/config/config.toml

@@ -63,6 +63,11 @@ send = true
 # Whether to receive typing status or not.
 receive = true
 
+[sidebar.markers]
+expanded = "▾ "
+collapsed = "▸ "
+leaf = ""
+
 [icons]
 guild_category = ""
 guild_text = "#"

+ 9 - 1
internal/ui/chat/guilds_tree.go

@@ -47,6 +47,11 @@ func newGuildsTree(cfg *config.Config, chatView *View) *guildsTree {
 	gt.
 		SetRoot(tview.NewTreeNode("")).
 		SetTopLevel(1).
+		SetMarkers(tview.TreeMarkers{
+			Expanded:  cfg.Sidebar.Markers.Expanded,
+			Collapsed: cfg.Sidebar.Markers.Collapsed,
+			Leaf:      cfg.Sidebar.Markers.Leaf,
+		}).
 		SetGraphics(cfg.Theme.GuildsTree.Graphics).
 		SetGraphicsColor(tcell.GetColor(cfg.Theme.GuildsTree.GraphicsColor)).
 		SetSelectedFunc(gt.onSelected).
@@ -189,7 +194,7 @@ 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)
+	guildNode := tview.NewTreeNode(guild.Name).SetReference(guild.ID).SetExpandable(true)
 	gt.setNodeLineStyle(guildNode, gt.getGuildNodeStyle(guild.ID))
 	n.AddChild(guildNode)
 	gt.guildNodeByID[guild.ID] = guildNode
@@ -201,6 +206,9 @@ func (gt *guildsTree) createChannelNode(node *tview.TreeNode, channel discord.Ch
 	}
 
 	channelNode := tview.NewTreeNode(ui.ChannelToString(channel, gt.cfg.Icons)).SetReference(channel.ID)
+	if channel.Type == discord.GuildForum {
+		channelNode.SetExpandable(true)
+	}
 	gt.setNodeLineStyle(channelNode, gt.getChannelNodeStyle(channel.ID))
 	node.AddChild(channelNode)
 	gt.channelNodeByID[channel.ID] = channelNode

+ 1 - 1
internal/ui/chat/keybinds.go

@@ -66,6 +66,6 @@ func (v *View) baseFullHelp() [][]keybind.Keybind {
 		focus,
 		{cfg.FocusPrevious.Keybind, cfg.FocusNext.Keybind},
 		{cfg.ToggleGuildsTree.Keybind, cfg.ToggleChannelsPicker.Keybind},
-		{cfg.ToggleHelp.Keybind, cfg.Logout.Keybind, cfg.Quit.Keybind},
+		{cfg.ToggleHelp.Keybind, cfg.Suspend.Keybind, cfg.Logout.Keybind, cfg.Quit.Keybind},
 	}
 }

+ 1 - 1
internal/ui/chat/state.go

@@ -85,7 +85,7 @@ func (v *View) onReady(event *gateway.ReadyEvent) {
 	// retain stale pointers to detached tree nodes.
 	v.guildsTree.resetNodeIndex()
 
-	dmNode := tview.NewTreeNode("Direct Messages").SetReference(dmNode{})
+	dmNode := tview.NewTreeNode("Direct Messages").SetReference(dmNode{}).SetExpandable(true)
 	v.guildsTree.dmRootNode = dmNode
 
 	root := v.guildsTree.