From dcc7205699d882f2f8495dd66cb953fbaa5bb336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Wed, 11 Oct 2023 21:15:20 +0200 Subject: [PATCH 1/2] bindings: Allow raw escape sequence to be bound with `bind` --- internal/action/command.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 16d2fff8..7d31c928 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -634,6 +634,11 @@ func (h *BufPane) ShowCmd(args []string) { InfoBar.Message(option) } +func parseKeyArg(arg string) string { + // If this is a raw escape sequence, convert it to its raw byte form + return strings.ReplaceAll(arg, "\\x1b", "\x1b") +} + // ShowKeyCmd displays the action that a key is bound to func (h *BufPane) ShowKeyCmd(args []string) { if len(args) < 1 { @@ -641,7 +646,7 @@ func (h *BufPane) ShowKeyCmd(args []string) { return } - event, err := findEvent(args[0]) + event, err := findEvent(parseKeyArg(args[0])) if err != nil { InfoBar.Error(err) return @@ -660,7 +665,7 @@ func (h *BufPane) BindCmd(args []string) { return } - _, err := TryBindKey(args[0], args[1], true) + _, err := TryBindKey(parseKeyArg(args[0]), args[1], true) if err != nil { InfoBar.Error(err) } @@ -673,7 +678,7 @@ func (h *BufPane) UnbindCmd(args []string) { return } - err := UnbindKey(args[0]) + err := UnbindKey(parseKeyArg(args[0])) if err != nil { InfoBar.Error(err) } From 6fa12743d61cd5228c93456c9cbe0bbb0ab030e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 15 Oct 2023 13:52:39 +0200 Subject: [PATCH 2/2] bindings: Add capability to unregister user defined raw escape sequence --- internal/action/bindings.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/action/bindings.go b/internal/action/bindings.go index 846e3d11..73ef8407 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -88,6 +88,10 @@ func BindKey(k, v string, bind func(e Event, a string)) { return } + if strings.HasPrefix(k, "\x1b") { + screen.Screen.RegisterRawSeq(k) + } + bind(event, v) // switch e := event.(type) { @@ -153,7 +157,6 @@ modSearch: k = k[5:] modifiers |= tcell.ModShift case strings.HasPrefix(k, "\x1b"): - screen.Screen.RegisterRawSeq(k) return RawEvent{ esc: k, }, true @@ -322,6 +325,10 @@ func UnbindKey(k string) error { } } + if strings.HasPrefix(k, "\x1b") { + screen.Screen.UnregisterRawSeq(k) + } + defaults := DefaultBindings("buffer") if a, ok := defaults[k]; ok { BindKey(k, a, Binder["buffer"])