From 30ee90a8ef68e3fb30cdeea8ae4adccf7fcd7b9b Mon Sep 17 00:00:00 2001 From: ayn2op Date: Sat, 13 Jun 2026 18:29:52 -0400 Subject: [PATCH] refactor(ui): match tview getter api --- go.mod | 2 +- go.sum | 4 +-- internal/ui/chat/composer.go | 2 +- internal/ui/chat/guilds_tree.go | 42 +++++++++++++++---------------- internal/ui/chat/keybinds.go | 4 +-- internal/ui/chat/mentions_list.go | 2 +- internal/ui/chat/model.go | 6 ++--- internal/ui/chat/state.go | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/go.mod b/go.mod index 057fefc..e6e60cd 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/alecthomas/chroma/v2 v2.26.1 github.com/andybalholm/brotli v1.2.1 github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97 - github.com/ayn2op/tview v0.0.0-20260612231537-97f061269b21 + github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb github.com/diamondburned/arikawa/v3 v3.6.1-0.20260518050745-b430932b3ee1 github.com/diamondburned/ningen/v3 v3.0.1-0.20260306213430-5a08d3a709b4 diff --git a/go.sum b/go.sum index 229291e..9dad609 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eT github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97 h1:WujETUV+v0DEJyZgjeLzQvihWyL80c0Tg4qf0dDo+Io= github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97/go.mod h1:3kFnpNCa3dF6WryzOMCDao7PfZ7DTCh+pievlfuwV80= -github.com/ayn2op/tview v0.0.0-20260612231537-97f061269b21 h1:vpWN5iVxK0bNdi4Kc5B+MNJnV96rJDd7xewy2mups8s= -github.com/ayn2op/tview v0.0.0-20260612231537-97f061269b21/go.mod h1:CaEiemJYKtmWqR0khyMI3HzVIia6B61jOPcLeZ7y4xk= +github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef h1:25kloMP4wqA8h5MQBRrPQ9/8O8OzNn0y2fr9gIudFS0= +github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef/go.mod h1:CaEiemJYKtmWqR0khyMI3HzVIia6B61jOPcLeZ7y4xk= github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= diff --git a/internal/ui/chat/composer.go b/internal/ui/chat/composer.go index 3430ad4..3311879 100644 --- a/internal/ui/chat/composer.go +++ b/internal/ui/chat/composer.go @@ -124,7 +124,7 @@ func (c *composer) resizeForContent() { // Clamp scroll: when content overflows, pin the bottom row to the end of the text so backspacing the last newline doesn't leave a blank trailing row; once everything fits, reset to (0,0). total := c.LineCount(0) - row, col := c.GetOffset() + row, col := c.Offset() maxOff := max(total-visible, 0) // last valid rowOffset that still shows real content on the bottom row if row > maxOff { c.SetOffset(maxOff, col) diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index 64539b2..dae5d86 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -85,7 +85,7 @@ func (gt *guildsTree) createFolderNode(folder gateway.GuildFolder, guildsByID ma folderStyle := tcell.StyleDefault.Foreground(tcell.NewHexColor(int32(folder.Color))) gt.setNodeLineStyle(folderNode, folderStyle) } - gt.GetRoot().AddChild(folderNode) + gt.Root().AddChild(folderNode) for _, guildID := range folder.GuildIDs { if guildEvent, ok := guildsByID[guildID]; ok { @@ -180,7 +180,7 @@ func (gt *guildsTree) createChannelNode(parent *tree.Node, channel discord.Chann } func (gt *guildsTree) setNodeLineStyle(node *tree.Node, style tcell.Style) { - line := node.GetLine() + line := node.Line() for i := range line { line[i].Style = style } @@ -237,12 +237,12 @@ func isThread(t discord.ChannelType) bool { } func (gt *guildsTree) onSelected(node *tree.Node) tview.Cmd { - if len(node.GetChildren()) != 0 { - node.SetExpanded(!node.IsExpanded()) + if len(node.Children()) != 0 { + node.SetExpanded(!node.Expanded()) return nil } - switch ref := node.GetReference().(type) { + switch ref := node.Reference().(type) { case discord.GuildID: go gt.chat.state.MemberState.Subscribe(ref) @@ -318,7 +318,7 @@ func (gt *guildsTree) loadChannel(channel discord.Channel) tview.Cmd { func (gt *guildsTree) collapseParentNode(node *tree.Node) { gt. - GetRoot(). + Root(). Walk(func(n, parent *tree.Node) bool { if n == node && parent.GetLevel() != 0 { parent.Collapse() @@ -337,12 +337,12 @@ func (gt *guildsTree) Update(msg tview.Msg) tview.Cmd { case tview.KeyMsg: switch { case keybind.Matches(msg, gt.cfg.Keybinds.GuildsTree.CollapseAll.Keybind): - for _, node := range gt.GetRoot().GetChildren() { + for _, node := range gt.Root().Children() { node.CollapseAll() } return nil case keybind.Matches(msg, gt.cfg.Keybinds.GuildsTree.CollapseParentNode.Keybind): - gt.collapseParentNode(gt.GetCurrentNode()) + gt.collapseParentNode(gt.CurrentNode()) return nil case keybind.Matches(msg, gt.cfg.Keybinds.GuildsTree.YankID.Keybind): return gt.yankID() @@ -352,14 +352,14 @@ func (gt *guildsTree) Update(msg tview.Msg) tview.Cmd { } func (gt *guildsTree) yankID() tview.Cmd { - node := gt.GetCurrentNode() + node := gt.CurrentNode() if node == nil { return nil } // Reference of a tree node in the guilds tree is its ID. // discord.Snowflake (discord.GuildID and discord.ChannelID) have the String method. - if id, ok := node.GetReference().(fmt.Stringer); ok { + if id, ok := node.Reference().(fmt.Stringer); ok { return func() tview.Msg { if err := clipboard.Write(clipboard.FmtText, []byte(id.String())); err != nil { slog.Error("failed to copy node id", "err", err) @@ -381,8 +381,8 @@ func (gt *guildsTree) findNodeByReference(reference any) *tree.Node { default: // Fallback keeps this helper safe for non-indexed custom references. var found *tree.Node - gt.GetRoot().Walk(func(node, _ *tree.Node) bool { - if node.GetReference() == reference { + gt.Root().Walk(func(node, _ *tree.Node) bool { + if node.Reference() == reference { found = node return false } @@ -406,7 +406,7 @@ func (gt *guildsTree) findNodeByChannelID(channelID discord.ChannelID) *tree.Nod reference = dmNode{} } if parent := gt.findNodeByReference(reference); parent != nil { - if len(parent.GetChildren()) == 0 { + if len(parent.Children()) == 0 { gt.onSelected(parent) } } @@ -430,15 +430,15 @@ func (gt *guildsTree) selectCurrentKeybind() keybind.Keybind { selectCurrent := gt.cfg.Keybinds.GuildsTree.SelectCurrent.Keybind selectHelp := selectCurrent.Help() selectDesc := selectHelp.Desc - if node := gt.GetCurrentNode(); node != nil { - if len(node.GetChildren()) > 0 { - if node.IsExpanded() { + if node := gt.CurrentNode(); node != nil { + if len(node.Children()) > 0 { + if node.Expanded() { selectDesc = "collapse" } else { selectDesc = "expand" } } else { - switch node.GetReference().(type) { + switch node.Reference().(type) { case discord.GuildID, dmNode: selectDesc = "expand" } @@ -451,7 +451,7 @@ func (gt *guildsTree) selectCurrentKeybind() keybind.Keybind { func (gt *guildsTree) ShortHelp() []keybind.Keybind { cfg := gt.cfg.Keybinds.GuildsTree shortHelp := []keybind.Keybind{cfg.SelectUp.Keybind, cfg.SelectDown.Keybind, gt.selectCurrentKeybind()} - if gt.canCollapseParent(gt.GetCurrentNode()) { + if gt.canCollapseParent(gt.CurrentNode()) { shortHelp = append(shortHelp, cfg.CollapseParentNode.Keybind) } return shortHelp @@ -473,7 +473,7 @@ func (gt *guildsTree) collapseKeybinds() []keybind.Keybind { cfg := gt.cfg.Keybinds.GuildsTree var keybinds []keybind.Keybind - if gt.canCollapseParent(gt.GetCurrentNode()) { + if gt.canCollapseParent(gt.CurrentNode()) { keybinds = append(keybinds, cfg.CollapseParentNode.Keybind) } if gt.canCollapseAll() { @@ -497,8 +497,8 @@ func (gt *guildsTree) canCollapseParent(node *tree.Node) bool { func (gt *guildsTree) canCollapseAll() bool { var can bool - for _, node := range gt.GetRoot().GetChildren() { - if node.IsExpanded() { + for _, node := range gt.Root().Children() { + if node.Expanded() { can = true break } diff --git a/internal/ui/chat/keybinds.go b/internal/ui/chat/keybinds.go index 3550d7b..7d0de9b 100644 --- a/internal/ui/chat/keybinds.go +++ b/internal/ui/chat/keybinds.go @@ -45,7 +45,7 @@ func (m *Model) activeKeyMap() help.KeyMap { func (m *Model) baseShortHelp() []keybind.Keybind { cfg := m.cfg.Keybinds short := []keybind.Keybind{cfg.FocusGuildsTree.Keybind, cfg.FocusMessagesList.Keybind} - if !m.composer.GetDisabled() { + if !m.composer.Disabled() { short = append(short, cfg.FocusComposer.Keybind) } short = append(short, cfg.ToggleGuildsTree.Keybind, cfg.ToggleChannelsPicker.Keybind) @@ -55,7 +55,7 @@ func (m *Model) baseShortHelp() []keybind.Keybind { func (m *Model) baseFullHelp() [][]keybind.Keybind { cfg := m.cfg.Keybinds focus := []keybind.Keybind{cfg.FocusGuildsTree.Keybind, cfg.FocusMessagesList.Keybind} - if !m.composer.GetDisabled() { + if !m.composer.Disabled() { focus = append(focus, cfg.FocusComposer.Keybind) } return [][]keybind.Keybind{ diff --git a/internal/ui/chat/mentions_list.go b/internal/ui/chat/mentions_list.go index ca8cae7..3a30607 100644 --- a/internal/ui/chat/mentions_list.go +++ b/internal/ui/chat/mentions_list.go @@ -35,7 +35,7 @@ func newMentionsList(cfg *config.Config) *mentionsList { m.Box = ui.ConfigureBox(m.Box, &cfg.Theme) m.SetSnapToItems(true).SetTitle("Mentions") - b := m.GetBorderSet() + b := m.BorderSet() b.BottomLeft, b.BottomRight = b.BottomT, b.BottomT m.SetBorderSet(b) diff --git a/internal/ui/chat/model.go b/internal/ui/chat/model.go index 3625b46..d193da3 100644 --- a/internal/ui/chat/model.go +++ b/internal/ui/chat/model.go @@ -198,7 +198,7 @@ func (m *Model) focusGuildsTree() tview.Cmd { } func (m *Model) focusComposer() tview.Cmd { - if !m.composer.GetDisabled() { + if !m.composer.Disabled() { return tview.SetFocus(m.composer) } return nil @@ -285,11 +285,11 @@ func (m *Model) Update(msg tview.Msg) tview.Cmd { } return m.listen() case channelLoadedMsg: - node := m.guildsTree.GetCurrentNode() + node := m.guildsTree.CurrentNode() if node == nil { return nil } - channelID, ok := node.GetReference().(discord.ChannelID) + channelID, ok := node.Reference().(discord.ChannelID) if !ok || channelID != msg.Channel.ID { return nil } diff --git a/internal/ui/chat/state.go b/internal/ui/chat/state.go index 2b01782..cd7a364 100644 --- a/internal/ui/chat/state.go +++ b/internal/ui/chat/state.go @@ -40,7 +40,7 @@ func (m *Model) onReady(event *gateway.ReadyEvent) tview.Cmd { m.guildsTree.dmRootNode = dmNode root := m.guildsTree. - GetRoot(). + Root(). ClearChildren(). AddChild(dmNode)