diff --git a/go.mod b/go.mod index 84f9600..0246b19 100644 --- a/go.mod +++ b/go.mod @@ -2,16 +2,15 @@ module github.com/ayn2op/discordo go 1.26.0 -// replace ( -// github.com/ayn2op/tview => ../tview -// github.com/diamondburned/arikawa/v3 => ../arikawa -// ) +// replace github.com/ayn2op/tview => ../tview + +// replace github.com/diamondburned/arikawa/v3 => ../arikawa 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-20260302045935-716714ee7442 + github.com/ayn2op/tview v0.0.0-20260302171301-0583f0a59cb9 github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb github.com/diamondburned/arikawa/v3 v3.6.1-0.20260226015332-783a3e8e8e86 github.com/diamondburned/ningen/v3 v3.0.1-0.20260226220604-93f1e60c3cdb diff --git a/go.sum b/go.sum index 3ef9872..c47ca72 100644 --- a/go.sum +++ b/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-20260302045935-716714ee7442 h1:5CN5nE/5s7zbIp51hiH1CY6hpDgvzfvh4CF38FXJCGk= -github.com/ayn2op/tview v0.0.0-20260302045935-716714ee7442/go.mod h1:lZ8RdOegQWBQafTOasGE7Ps1/Ymy4jmXoPt5vz2QsS0= +github.com/ayn2op/tview v0.0.0-20260302171301-0583f0a59cb9 h1:S9rDf+pMs6xNfrXPMhT57m0vyo1hK/mTT4K+jQYrgYU= +github.com/ayn2op/tview v0.0.0-20260302171301-0583f0a59cb9/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= diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index a05e78b..dc39ae8 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -396,14 +396,13 @@ func (gt *guildsTree) collapseParentNode(node *tview.TreeNode) { func (gt *guildsTree) HandleEvent(event tcell.Event) tview.Command { switch event := event.(type) { case *tview.KeyEvent: - consume := tview.ConsumeEventCommand{} - consumeRedraw := tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} + redraw := tview.RedrawCommand{} handler := gt.TreeView.HandleEvent switch { case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.CollapseParentNode.Keybind): gt.collapseParentNode(gt.GetCurrentNode()) - return consumeRedraw + return redraw case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.MoveToParentNode.Keybind): return handler(tcell.NewEventKey(tcell.KeyRune, "K", tcell.ModNone)) case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.Up.Keybind): @@ -412,18 +411,18 @@ func (gt *guildsTree) HandleEvent(event tcell.Event) tview.Command { return handler(tcell.NewEventKey(tcell.KeyDown, "", tcell.ModNone)) case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.Top.Keybind): gt.Move(gt.GetRowCount() * -1) - return consumeRedraw + return redraw case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.Bottom.Keybind): gt.Move(gt.GetRowCount()) - return consumeRedraw + return redraw case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.SelectCurrent.Keybind): return handler(tcell.NewEventKey(tcell.KeyEnter, "", tcell.ModNone)) case keybind.Matches(event, gt.cfg.Keybinds.GuildsTree.YankID.Keybind): gt.yankID() - return consume + return nil } // Do not fall through to TreeView defaults for unmatched keys. - return consume + return nil } return gt.TreeView.HandleEvent(event) } diff --git a/internal/ui/chat/message_input.go b/internal/ui/chat/message_input.go index c250add..c4973bd 100644 --- a/internal/ui/chat/message_input.go +++ b/internal/ui/chat/message_input.go @@ -95,8 +95,7 @@ func (mi *messageInput) stopTypingTimer() { func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { switch event := event.(type) { case *tview.KeyEvent: - consume := tview.ConsumeEventCommand{} - consumeRedraw := tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} + redraw := tview.RedrawCommand{} handler := mi.TextArea.HandleEvent switch { case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.Paste.Keybind): @@ -108,7 +107,7 @@ func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { } else { mi.send() } - return consumeRedraw + return redraw case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.OpenEditor.Keybind): var cmds tview.BatchCommand mi.stopTabCompletion(func(next tview.Command) { @@ -117,7 +116,7 @@ func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { } }) mi.editor() - cmds = append(cmds, consumeRedraw) + cmds = append(cmds, redraw) return cmds case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.OpenFilePicker.Keybind): var cmds tview.BatchCommand @@ -127,7 +126,7 @@ func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { } }) mi.openFilePicker() - cmds = append(cmds, consumeRedraw) + cmds = append(cmds, redraw) return cmds case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.Cancel.Keybind): var cmds tview.BatchCommand @@ -140,11 +139,11 @@ func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { } else { mi.reset() } - cmds = append(cmds, consumeRedraw) + cmds = append(cmds, redraw) return cmds case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.TabComplete.Keybind): go mi.chatView.app.QueueUpdateDraw(func() { mi.tabComplete() }) - return consume + return redraw case keybind.Matches(event, mi.cfg.Keybinds.MessageInput.Undo.Keybind): return handler(tcell.NewEventKey(tcell.KeyCtrlZ, "", tcell.ModNone)) } @@ -166,16 +165,16 @@ func (mi *messageInput) HandleEvent(event tcell.Event) tview.Command { switch { case keybind.Matches(event, mi.cfg.Keybinds.MentionsList.Up.Keybind): mi.mentionsList.HandleEvent(tcell.NewEventKey(tcell.KeyUp, "", tcell.ModNone)) - return consumeRedraw + return redraw case keybind.Matches(event, mi.cfg.Keybinds.MentionsList.Down.Keybind): mi.mentionsList.HandleEvent(tcell.NewEventKey(tcell.KeyDown, "", tcell.ModNone)) - return consumeRedraw + return redraw case keybind.Matches(event, mi.cfg.Keybinds.MentionsList.Top.Keybind): mi.mentionsList.HandleEvent(tcell.NewEventKey(tcell.KeyHome, "", tcell.ModNone)) - return consumeRedraw + return redraw case keybind.Matches(event, mi.cfg.Keybinds.MentionsList.Bottom.Keybind): mi.mentionsList.HandleEvent(tcell.NewEventKey(tcell.KeyEnd, "", tcell.ModNone)) - return consumeRedraw + return redraw } } diff --git a/internal/ui/chat/messages_list.go b/internal/ui/chat/messages_list.go index 3ff4eb4..683a160 100644 --- a/internal/ui/chat/messages_list.go +++ b/internal/ui/chat/messages_list.go @@ -528,71 +528,68 @@ func (ml *messagesList) selectedMessage() (*discord.Message, error) { func (ml *messagesList) HandleEvent(event tcell.Event) tview.Command { switch event := event.(type) { case *tview.KeyEvent: - consume := tview.ConsumeEventCommand{} - consumeRedraw := tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} - + redraw := tview.RedrawCommand{} switch { case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.ScrollUp.Keybind): ml.ScrollUp() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.ScrollDown.Keybind): ml.ScrollDown() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.ScrollTop.Keybind): ml.ScrollToStart() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.ScrollBottom.Keybind): ml.ScrollToEnd() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.Cancel.Keybind): ml.clearSelection() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.SelectUp.Keybind): ml.selectUp() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.SelectDown.Keybind): ml.selectDown() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.SelectTop.Keybind): ml.selectTop() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.SelectBottom.Keybind): ml.selectBottom() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.SelectReply.Keybind): ml.selectReply() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.YankID.Keybind): ml.yankID() - return consume + return nil case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.YankContent.Keybind): ml.yankContent() - return consume + return nil case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.YankURL.Keybind): ml.yankURL() - return consume + return nil case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.Open.Keybind): ml.open() - return consume + return nil case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.Reply.Keybind): ml.reply(false) - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.ReplyMention.Keybind): ml.reply(true) - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.Edit.Keybind): ml.edit() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.Delete.Keybind): ml.delete() - return consumeRedraw + return redraw case keybind.Matches(event, ml.cfg.Keybinds.MessagesList.DeleteConfirm.Keybind): ml.confirmDelete() - return consumeRedraw + return redraw } - // Do not fall through to List defaults for unmatched keys. - return consume + return nil } return ml.List.HandleEvent(event) } diff --git a/internal/ui/chat/view.go b/internal/ui/chat/view.go index c96b58f..cdc4549 100644 --- a/internal/ui/chat/view.go +++ b/internal/ui/chat/view.go @@ -225,30 +225,29 @@ func (v *View) focusNext() { func (v *View) HandleEvent(event tcell.Event) tview.Command { switch event := event.(type) { case *tview.KeyEvent: - consume := tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} - + redraw := tview.RedrawCommand{} switch { case keybind.Matches(event, v.cfg.Keybinds.ToggleHelp.Keybind): v.help.SetShowAll(!v.help.ShowAll()) v.updateHelpHeight() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.FocusGuildsTree.Keybind): v.messageInput.removeMentionsList() v.focusGuildsTree() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.FocusMessagesList.Keybind): v.messageInput.removeMentionsList() v.app.SetFocus(v.messagesList) - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.FocusMessageInput.Keybind): v.focusMessageInput() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.FocusPrevious.Keybind): v.focusPrevious() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.FocusNext.Keybind): v.focusNext() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.Logout.Keybind): if v.onLogout != nil { v.onLogout() @@ -256,17 +255,14 @@ func (v *View) HandleEvent(event tcell.Event) tview.Command { if err := keyring.DeleteToken(); err != nil { slog.Error("failed to delete token from keyring", "err", err) } - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.ToggleGuildsTree.Keybind): v.toggleGuildsTree() - return consume + return redraw case keybind.Matches(event, v.cfg.Keybinds.ToggleChannelsPicker.Keybind): v.togglePicker() - return consume + return redraw } - - cmd := v.Layers.HandleEvent(event) - return v.consumeLayerCommands(cmd) } cmd := v.Layers.HandleEvent(event) return v.consumeLayerCommands(cmd) @@ -323,10 +319,7 @@ func (v *View) consumeLayerCommands(command tview.Command) tview.Command { func (v *View) updateHelpHeight() { height := 1 if v.help.ShowAll() { - height = len(v.help.FullHelpLines(v.FullHelp(), 0)) - if height < 1 { - height = 1 - } + height = max(len(v.help.FullHelpLines(v.FullHelp(), 0)), 1) } v.rootFlex.ResizeItem(v.help, height, 0) } diff --git a/internal/ui/login/qr.go b/internal/ui/login/qr.go index fa2e82b..151b156 100644 --- a/internal/ui/login/qr.go +++ b/internal/ui/login/qr.go @@ -71,7 +71,7 @@ func (q *qrLogin) HandleEvent(event tcell.Event) tview.Command { if q.done != nil { q.done("", nil) } - return tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} + return tview.RedrawCommand{} } return q.TextView.HandleEvent(event) } diff --git a/internal/ui/root/view.go b/internal/ui/root/view.go index 5ea2425..9350209 100644 --- a/internal/ui/root/view.go +++ b/internal/ui/root/view.go @@ -129,7 +129,7 @@ func (v *View) HandleEvent(event tcell.Event) tview.Command { switch { case keybind.Matches(event, v.cfg.Keybinds.Suspend.Keybind): v.suspend() - return tview.ConsumeEventCommand{} + return nil case keybind.Matches(event, v.cfg.Keybinds.Quit.Keybind): v.closeChatViewState() return tview.QuitCommand{} diff --git a/pkg/picker/picker.go b/pkg/picker/picker.go index 8a56832..3ee1e7b 100644 --- a/pkg/picker/picker.go +++ b/pkg/picker/picker.go @@ -151,30 +151,29 @@ func (p *Picker) onInputChanged(text string) { func (p *Picker) HandleEvent(event tcell.Event) tview.Command { switch event := event.(type) { case *tview.KeyEvent: - consume := tview.BatchCommand{tview.RedrawCommand{}, tview.ConsumeEventCommand{}} - + redraw := tview.RedrawCommand{} if p.keyMap != nil { switch { case keybind.Matches(event, p.keyMap.Up): p.list.HandleEvent(tcell.NewEventKey(tcell.KeyUp, "", tcell.ModNone)) - return consume + return redraw case keybind.Matches(event, p.keyMap.Down): p.list.HandleEvent(tcell.NewEventKey(tcell.KeyDown, "", tcell.ModNone)) - return consume + return redraw case keybind.Matches(event, p.keyMap.Top): p.list.HandleEvent(tcell.NewEventKey(tcell.KeyHome, "", tcell.ModNone)) - return consume + return redraw case keybind.Matches(event, p.keyMap.Bottom): p.list.HandleEvent(tcell.NewEventKey(tcell.KeyEnd, "", tcell.ModNone)) - return consume + return redraw case keybind.Matches(event, p.keyMap.Select): p.onListSelected(p.list.Cursor()) - return consume + return redraw case keybind.Matches(event, p.keyMap.Cancel): if p.onCancel != nil { p.onCancel() } - return consume + return redraw } }