From 5dca2a1a2515856bc42eeb9d28f66567cf57e91f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Aug 2022 21:56:29 +0530 Subject: [PATCH] Fix stringifying mods --- tools/tui/key-encoding.go | 18 +++++++++--------- tools/tui/loop.go | 11 +++++++++-- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/tui/key-encoding.go b/tools/tui/key-encoding.go index 38f1bf188..2ea85d834 100644 --- a/tools/tui/key-encoding.go +++ b/tools/tui/key-encoding.go @@ -58,30 +58,30 @@ func (self KeyEventType) String() string { } } -func (self *KeyModifiers) String() string { +func (self KeyModifiers) String() string { ans := make([]string, 0) - if *self&SHIFT != 0 { + if self&SHIFT != 0 { ans = append(ans, "shift") } - if *self&ALT != 0 { + if self&ALT != 0 { ans = append(ans, "alt") } - if *self&CTRL != 0 { + if self&CTRL != 0 { ans = append(ans, "ctrl") } - if *self&SUPER != 0 { + if self&SUPER != 0 { ans = append(ans, "super") } - if *self&HYPER != 0 { + if self&HYPER != 0 { ans = append(ans, "hyper") } - if *self&META != 0 { + if self&META != 0 { ans = append(ans, "meta") } - if *self&CAPS_LOCK != 0 { + if self&CAPS_LOCK != 0 { ans = append(ans, "caps_lock") } - if *self&NUM_LOCK != 0 { + if self&NUM_LOCK != 0 { ans = append(ans, "num_lock") } return strings.Join(ans, "+") diff --git a/tools/tui/loop.go b/tools/tui/loop.go index 92a027af7..0fb7defdf 100644 --- a/tools/tui/loop.go +++ b/tools/tui/loop.go @@ -46,9 +46,16 @@ type Loop struct { write_buf []byte // Callbacks + + // Called when the terminal has been fully setup. Any string returned is sent to + // the terminal on shutdown OnInitialize func(loop *Loop) string - OnKeyEvent func(loop *Loop, event *KeyEvent) error - OnText func(loop *Loop, text string, from_key_event bool, in_bracketed_paste bool) error + + // Called when a key event happens + OnKeyEvent func(loop *Loop, event *KeyEvent) error + + // Called when text is received either from a key event or directly from the terminal + OnText func(loop *Loop, text string, from_key_event bool, in_bracketed_paste bool) error } func (self *Loop) handle_csi(raw []byte) error {