mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-07-11 10:00:21 +02:00

Update the Command interface to include a Description() method. Implement the method for all commands using short descriptions inspired from the aerc(1) man page. Return the description values along with command names so that they can be displayed in completion choices. Implements: https://todo.sr.ht/~rjarry/aerc/271 Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bojan Gabric <bojan@bojangabric.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
57 lines
1 KiB
Go
57 lines
1 KiB
Go
package commands
|
|
|
|
import (
|
|
"git.sr.ht/~rjarry/aerc/app"
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
"git.sr.ht/~rockorager/vaxis"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type SendKeys struct {
|
|
Keys string `opt:"..."`
|
|
}
|
|
|
|
func init() {
|
|
Register(SendKeys{})
|
|
}
|
|
|
|
func (SendKeys) Description() string {
|
|
return "Send keystrokes to the currently visible terminal."
|
|
}
|
|
|
|
func (SendKeys) Context() CommandContext {
|
|
return GLOBAL
|
|
}
|
|
|
|
func (SendKeys) Aliases() []string {
|
|
return []string{"send-keys"}
|
|
}
|
|
|
|
func (s 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")
|
|
}
|
|
|
|
keys2send, err := config.ParseKeyStrokes(s.Keys)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "Unable to parse keystroke: %q", s.Keys)
|
|
}
|
|
|
|
for _, key := range keys2send {
|
|
ev := vaxis.Key{
|
|
Keycode: key.Key,
|
|
Modifiers: key.Modifiers,
|
|
}
|
|
term.Event(ev)
|
|
}
|
|
|
|
term.Invalidate()
|
|
|
|
return nil
|
|
}
|