refactor(ui): update to tview's ActionNone keybinds

This commit is contained in:
ayn2op 2026-10-02 15:33:03 -04:00
parent dae8467a58
commit 1604231f6d
8 changed files with 44 additions and 42 deletions

4
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/andybalholm/brotli v1.2.6
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e
github.com/ayn2op/tview v0.0.0-20261002033553-436738a0b031
github.com/ayn2op/tview v0.0.0-20261002193117-35ae7f9a9c7c
github.com/bogdanfinn/fhttp v0.6.9
github.com/bogdanfinn/tls-client v1.16.0
github.com/gdamore/tcell/v3 v3.5.0
@ -45,7 +45,7 @@ require (
github.com/cloudflare/circl v1.6.5 // indirect
github.com/danieljoos/wincred v1.2.3 // indirect
github.com/dchest/jsmin v1.0.0 // indirect
github.com/dlclark/regexp2/v2 v2.8.1 // indirect
github.com/dlclark/regexp2/v2 v2.8.2 // indirect
github.com/ebitengine/purego v0.11.1 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/godbus/dbus/v5 v5.2.2 // indirect

8
go.sum
View file

@ -14,8 +14,8 @@ github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c h1:Qkl3W5RXzUQUR
github.com/ayn2op/arikawa/v3 v3.0.0-20260929021956-7d0802bf4d7c/go.mod h1:SHqcr+EmZKeNtVKZybHJn4HNz+ufA1XbeKNSTigBCEE=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e h1:QAei/IVEyZV7GcpkpcFUh37+QRqwrt57z7OT3ciHrhI=
github.com/ayn2op/ningen/v3 v3.0.1-0.20260929010920-29794d5fa70e/go.mod h1:RsvYiMzi4Si1F7vmml5NCL2DaKIZXkNUQC7QlGTMtCw=
github.com/ayn2op/tview v0.0.0-20261002033553-436738a0b031 h1:LDAVehU5RKMj7OMzyPoWSvLyzG+LlsPbBfksXTgtUnA=
github.com/ayn2op/tview v0.0.0-20261002033553-436738a0b031/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
github.com/ayn2op/tview v0.0.0-20261002193117-35ae7f9a9c7c h1:mRu34vay2riznvGkY8BkZJri3Tkrm3wNgPAHH2C4JD0=
github.com/ayn2op/tview v0.0.0-20261002193117-35ae7f9a9c7c/go.mod h1:oRPTSZgaEJPhv3dmmNvo6grBq/BemrLG3wFQLMTZJkY=
github.com/bdandy/go-errors v1.2.2 h1:WdFv/oukjTJCLa79UfkGmwX7ZxONAihKu4V0mLIs11Q=
github.com/bdandy/go-errors v1.2.2/go.mod h1:NkYHl4Fey9oRRdbB1CoC6e84tuqQHiqrOcZpqFEkBxM=
github.com/bdandy/go-socks4 v1.2.3 h1:Q6Y2heY1GRjCtHbmlKfnwrKVU/k81LS8mRGLRlmDlic=
@ -42,8 +42,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dchest/jsmin v1.0.0 h1:Y2hWXmGZiRxtl+VcTksyucgTlYxnhPzTozCwx9gy9zI=
github.com/dchest/jsmin v1.0.0/go.mod h1:AVBIund7Mr7lKXT70hKT2YgL3XEXUaUk5iw9DZ8b0Uc=
github.com/dlclark/regexp2/v2 v2.8.1 h1:I1jbaCbXeOxdVN8z3fb55Mvtgb94/6+Dh0zjmXjKV/0=
github.com/dlclark/regexp2/v2 v2.8.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/dlclark/regexp2/v2 v2.8.2 h1:uTTe+cxADL4be+dv4DZwsBIEPCQ6RHPlnVuKrtLqSx0=
github.com/dlclark/regexp2/v2 v2.8.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
github.com/ebitengine/purego v0.11.1 h1:2zpWRSQNVKN4eKsKO9eM1ILDgWfYMY9GwqRmK6XeQ/0=
github.com/ebitengine/purego v0.11.1/go.mod h1:DCHPP08djqhNSoTfImcnHYQRZmd0qhakvrozqaEYhGQ=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=

View file

@ -617,12 +617,14 @@ func (c *Model) canAttachFiles() bool {
}
// editAction binds the configured newline key and textarea's other default keys.
func (c Model) editAction(key tview.KeyMsg) (textarea.Action, bool) {
func (c Model) editAction(key tview.KeyMsg) textarea.Action {
if keybind.Matches(key, c.cfg.Keybinds.Composer.Newline.Keybind) {
return textarea.ActionNewline, true
return textarea.ActionNewline
}
action, ok := textarea.DefaultKeybind(key)
return action, ok && action != textarea.ActionNewline
if action := textarea.DefaultKeybind(key); action != textarea.ActionNewline {
return action
}
return textarea.ActionNone
}
func (c Model) ShortHelp() []keybind.Keybind {

View file

@ -115,19 +115,19 @@ func (ml *Model) listView(focused bool) list.Widget {
}
// scrollKeybind binds kbs to scrolling the list.
func scrollKeybind(kbs config.ScrollKeybinds) func(tview.KeyMsg) (list.Action, bool) {
return func(key tview.KeyMsg) (list.Action, bool) {
func scrollKeybind(kbs config.ScrollKeybinds) func(tview.KeyMsg) list.Action {
return func(key tview.KeyMsg) list.Action {
switch {
case keybind.Matches(key, kbs.ScrollUp.Keybind):
return list.ActionScrollUp, true
return list.ActionScrollUp
case keybind.Matches(key, kbs.ScrollDown.Keybind):
return list.ActionScrollDown, true
return list.ActionScrollDown
case keybind.Matches(key, kbs.ScrollTop.Keybind):
return list.ActionScrollTop, true
return list.ActionScrollTop
case keybind.Matches(key, kbs.ScrollBottom.Keybind):
return list.ActionScrollBottom, true
return list.ActionScrollBottom
}
return 0, false
return list.ActionNone
}
}

View file

@ -8,18 +8,18 @@ import (
)
// SelectionKeybind binds kbs to moving a list's selection.
func SelectionKeybind(kbs config.SelectionKeybinds) func(tview.KeyMsg) (list.Action, bool) {
return func(key tview.KeyMsg) (list.Action, bool) {
func SelectionKeybind(kbs config.SelectionKeybinds) func(tview.KeyMsg) list.Action {
return func(key tview.KeyMsg) list.Action {
switch {
case keybind.Matches(key, kbs.SelectUp.Keybind):
return list.ActionSelectUp, true
return list.ActionSelectUp
case keybind.Matches(key, kbs.SelectDown.Keybind):
return list.ActionSelectDown, true
return list.ActionSelectDown
case keybind.Matches(key, kbs.SelectTop.Keybind):
return list.ActionSelectTop, true
return list.ActionSelectTop
case keybind.Matches(key, kbs.SelectBottom.Keybind):
return list.ActionSelectBottom, true
return list.ActionSelectBottom
}
return 0, false
return list.ActionNone
}
}

View file

@ -12,14 +12,14 @@ var (
nextTab = keybind.NewSingleKeybind("ctrl+l", "next tab")
)
func tabAction(key tview.KeyMsg) (tabs.Action, bool) {
func tabAction(key tview.KeyMsg) tabs.Action {
switch {
case keybind.Matches(key, previousTab):
return tabs.ActionPrevious, true
return tabs.ActionPrevious
case keybind.Matches(key, nextTab):
return tabs.ActionNext, true
return tabs.ActionNext
}
return 0, false
return tabs.ActionNone
}
var _ help.KeyMap = Model{}

View file

@ -57,14 +57,14 @@ func (m *Model) SetItems(items picker.Items) {
// Reset clears the query.
func (m *Model) Reset() { m.searchState.Reset() }
func bindKeys(kbs config.PickerKeybinds) func(tview.KeyMsg) (picker.Action, bool) {
return func(key tview.KeyMsg) (picker.Action, bool) {
func bindKeys(kbs config.PickerKeybinds) func(tview.KeyMsg) picker.Action {
return func(key tview.KeyMsg) picker.Action {
switch {
case keybind.Matches(key, kbs.Select.Keybind):
return picker.ActionSelect, true
return picker.ActionSelect
case keybind.Matches(key, kbs.Cancel.Keybind):
return picker.ActionCancel, true
return picker.ActionCancel
}
return 0, false
return picker.ActionNone
}
}

View file

@ -34,22 +34,22 @@ func New(root *tree.Node, selectionState tree.SelectionState, cfg *config.Config
return ui.Box(t, &cfg.Theme, focused)
}
func bindKeys(kbs config.TreeKeybinds) func(tview.KeyMsg) (tree.Action, bool) {
return func(key tview.KeyMsg) (tree.Action, bool) {
func bindKeys(kbs config.TreeKeybinds) func(tview.KeyMsg) tree.Action {
return func(key tview.KeyMsg) tree.Action {
switch {
case keybind.Matches(key, kbs.SelectUp.Keybind):
return tree.ActionUp, true
return tree.ActionUp
case keybind.Matches(key, kbs.SelectDown.Keybind):
return tree.ActionDown, true
return tree.ActionDown
case keybind.Matches(key, kbs.SelectTop.Keybind):
return tree.ActionTop, true
return tree.ActionTop
case keybind.Matches(key, kbs.SelectBottom.Keybind):
return tree.ActionBottom, true
return tree.ActionBottom
case keybind.Matches(key, kbs.MoveToParentNode.Keybind):
return tree.ActionMoveToParent, true
return tree.ActionMoveToParent
case keybind.Matches(key, kbs.SelectCurrent.Keybind):
return tree.ActionSelect, true
return tree.ActionSelect
}
return 0, false
return tree.ActionNone
}
}