aboutsummaryrefslogtreecommitdiffstats
path: root/commands/send-keys.go
diff options
context:
space:
mode:
authorVitaly Ovchinnikov <v@postbox.nz>2023-09-29 18:48:47 +0000
committerRobin Jarry <robin@jarry.cc>2023-10-22 14:56:27 +0200
commit14fc59f189775dbe95daf582c08c9c1b3cd949b2 (patch)
tree285a1b8bb0d4a27a0d04ebd09287d0cabd9654ce /commands/send-keys.go
parent6bbb477d441b17756f89e0034c26c4c3cdc941af (diff)
downloadaerc-14fc59f189775dbe95daf582c08c9c1b3cd949b2.tar.gz
terminal: add `:send-keys` command
Add a new command for sending keystrokes to the active terminal, if there is one visible. Covers split preview, message viewer, composer and the terminal mode. This can be used to navigate the embedded applications to scroll or safely quit them when needed. Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/send-keys.go')
-rw-r--r--commands/send-keys.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/commands/send-keys.go b/commands/send-keys.go
new file mode 100644
index 00000000..f9cae392
--- /dev/null
+++ b/commands/send-keys.go
@@ -0,0 +1,51 @@
+package commands
+
+import (
+ "strings"
+
+ "git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/config"
+ "github.com/gdamore/tcell/v2"
+ "github.com/pkg/errors"
+)
+
+type SendKeys struct{}
+
+func init() {
+ register(SendKeys{})
+}
+
+func (SendKeys) Aliases() []string {
+ return []string{"send-keys"}
+}
+
+func (SendKeys) Complete(args []string) []string {
+ return nil
+}
+
+func (SendKeys) Execute(args []string) error {
+ tab, ok := app.SelectedTabContent().(app.HasTerminal)
+ if !ok {
+ return errors.New("There is no terminal here")
+ }
+
+ term := tab.Terminal()
+ if term == nil {
+ return errors.New("The terminal is not active")
+ }
+
+ text2send := strings.Join(args[1:], "")
+ keys2send, err := config.ParseKeyStrokes(text2send)
+ if err != nil {
+ return errors.Wrapf(err, "Unable to parse keystroke: '%s'", text2send)
+ }
+
+ for _, key := range keys2send {
+ ev := tcell.NewEventKey(key.Key, key.Rune, key.Modifiers)
+ term.Event(ev)
+ }
+
+ term.Invalidate()
+
+ return nil
+}