diff options
author | Gregory Mullen <greg@cmdline.org> | 2019-06-27 10:33:11 -0700 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-29 14:24:19 -0400 |
commit | 2a0961701c4cabecc53d134ed1782e5612e64580 (patch) | |
tree | 57952ac82fb7104113ca7fc0e25dc3d225f77ea7 /commands/msgview | |
parent | 177651bddab145c8a56cdfeb0d57b5fd95a6d0e2 (diff) | |
download | aerc-2a0961701c4cabecc53d134ed1782e5612e64580.tar.gz |
Implement basic tab completion support
Tab completion currently only works on commands. Contextual completion
will be added in the future.
Diffstat (limited to 'commands/msgview')
-rw-r--r-- | commands/msgview/close.go | 14 | ||||
-rw-r--r-- | commands/msgview/msgview.go | 4 | ||||
-rw-r--r-- | commands/msgview/next-part.go | 19 | ||||
-rw-r--r-- | commands/msgview/next.go | 17 | ||||
-rw-r--r-- | commands/msgview/open.go | 14 | ||||
-rw-r--r-- | commands/msgview/pipe.go | 14 | ||||
-rw-r--r-- | commands/msgview/save.go | 16 | ||||
-rw-r--r-- | commands/msgview/toggle-headers.go | 18 |
8 files changed, 92 insertions, 24 deletions
diff --git a/commands/msgview/close.go b/commands/msgview/close.go index 4ce15c4f..6a7eb0a3 100644 --- a/commands/msgview/close.go +++ b/commands/msgview/close.go @@ -6,11 +6,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type Close struct{} + func init() { - register("close", CommandClose) + register(Close{}) +} + +func (_ Close) Aliases() []string { + return []string{"close"} +} + +func (_ Close) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func CommandClose(aerc *widgets.Aerc, args []string) error { +func (_ Close) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 1 { return errors.New("Usage: close") } diff --git a/commands/msgview/msgview.go b/commands/msgview/msgview.go index f0e42ad1..d60549ee 100644 --- a/commands/msgview/msgview.go +++ b/commands/msgview/msgview.go @@ -8,9 +8,9 @@ var ( MessageViewCommands *commands.Commands ) -func register(name string, cmd commands.AercCommand) { +func register(cmd commands.Command) { if MessageViewCommands == nil { MessageViewCommands = commands.NewCommands() } - MessageViewCommands.Register(name, cmd) + MessageViewCommands.Register(cmd) } diff --git a/commands/msgview/next-part.go b/commands/msgview/next-part.go index fcf8f19f..8f25e02d 100644 --- a/commands/msgview/next-part.go +++ b/commands/msgview/next-part.go @@ -8,16 +8,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type NextPrevPart struct{} + func init() { - register("next-part", NextPrevPart) - register("prev-part", NextPrevPart) + register(NextPrevPart{}) } -func nextPrevPartUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +func (_ NextPrevPart) Aliases() []string { + return []string{"next-part", "prev-part"} +} + +func (_ NextPrevPart) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func NextPrevPart(aerc *widgets.Aerc, args []string) error { +func (_ NextPrevPart) Execute(aerc *widgets.Aerc, args []string) error { if len(args) > 2 { return nextPrevPartUsage(args[0]) } @@ -41,3 +46,7 @@ func NextPrevPart(aerc *widgets.Aerc, args []string) error { } return nil } + +func nextPrevPartUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +} diff --git a/commands/msgview/next.go b/commands/msgview/next.go index 0c868397..82fb12f9 100644 --- a/commands/msgview/next.go +++ b/commands/msgview/next.go @@ -6,14 +6,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type NextPrevMsg struct{} + func init() { - register("next", NextPrevMessage) - register("next-message", NextPrevMessage) - register("prev", NextPrevMessage) - register("prev-message", NextPrevMessage) + register(NextPrevMsg{}) +} + +func (_ NextPrevMsg) Aliases() []string { + return []string{"next", "next-message", "prev", "prev-message"} +} + +func (_ NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func NextPrevMessage(aerc *widgets.Aerc, args []string) error { +func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { mv, _ := aerc.SelectedTab().(*widgets.MessageViewer) acct := mv.SelectedAccount() store := mv.Store() diff --git a/commands/msgview/open.go b/commands/msgview/open.go index 1a33cecd..d1b32380 100644 --- a/commands/msgview/open.go +++ b/commands/msgview/open.go @@ -14,11 +14,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type Open struct{} + func init() { - register("open", Open) + register(Open{}) +} + +func (_ Open) Aliases() []string { + return []string{"open"} +} + +func (_ Open) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func Open(aerc *widgets.Aerc, args []string) error { +func (_ Open) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 1 { return errors.New("Usage: open") } diff --git a/commands/msgview/pipe.go b/commands/msgview/pipe.go index a84cdf55..56c125bf 100644 --- a/commands/msgview/pipe.go +++ b/commands/msgview/pipe.go @@ -12,11 +12,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type Pipe struct{} + func init() { - register("pipe", Pipe) + register(Pipe{}) +} + +func (_ Pipe) Aliases() []string { + return []string{"pipe"} +} + +func (_ Pipe) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func Pipe(aerc *widgets.Aerc, args []string) error { +func (_ Pipe) Execute(aerc *widgets.Aerc, args []string) error { if len(args) < 2 { return errors.New("Usage: :pipe <cmd> [args...]") } diff --git a/commands/msgview/save.go b/commands/msgview/save.go index 59d94b2f..93fa83f8 100644 --- a/commands/msgview/save.go +++ b/commands/msgview/save.go @@ -16,19 +16,31 @@ import ( "github.com/mitchellh/go-homedir" ) +type Save struct{} + func init() { - register("save", Save) + register(Save{}) +} + +func (_ Save) Aliases() []string { + return []string{"save"} +} + +func (_ Save) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func Save(aerc *widgets.Aerc, args []string) error { +func (_ Save) Execute(aerc *widgets.Aerc, args []string) error { opts, optind, err := getopt.Getopts(args, "p") if err != nil { return err } + var ( mkdirs bool path string ) + for _, opt := range opts { switch opt.Option { case 'p': diff --git a/commands/msgview/toggle-headers.go b/commands/msgview/toggle-headers.go index fc29042d..d9d7eba6 100644 --- a/commands/msgview/toggle-headers.go +++ b/commands/msgview/toggle-headers.go @@ -7,15 +7,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type ToggleHeaders struct{} + func init() { - register("toggle-headers", ToggleHeaders) + register(ToggleHeaders{}) } -func toggleHeadersUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s", cmd)) +func (_ ToggleHeaders) Aliases() []string { + return []string{"toggle-headers"} +} + +func (_ ToggleHeaders) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func ToggleHeaders(aerc *widgets.Aerc, args []string) error { +func (_ ToggleHeaders) Execute(aerc *widgets.Aerc, args []string) error { if len(args) > 1 { return toggleHeadersUsage(args[0]) } @@ -23,3 +29,7 @@ func ToggleHeaders(aerc *widgets.Aerc, args []string) error { mv.ToggleHeaders() return nil } + +func toggleHeadersUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s", cmd)) +} |