From 2a0961701c4cabecc53d134ed1782e5612e64580 Mon Sep 17 00:00:00 2001 From: Gregory Mullen Date: Thu, 27 Jun 2019 10:33:11 -0700 Subject: Implement basic tab completion support Tab completion currently only works on commands. Contextual completion will be added in the future. --- commands/account/account.go | 4 ++-- commands/account/cf.go | 14 ++++++++++++-- commands/account/compose.go | 14 ++++++++++++-- commands/account/mkdir.go | 14 ++++++++++++-- commands/account/next-folder.go | 19 ++++++++++++++----- commands/account/next-result.go | 19 ++++++++++++++----- commands/account/next.go | 21 ++++++++++++++------- commands/account/pipe.go | 14 ++++++++++++-- commands/account/search.go | 15 ++++++++++++--- commands/account/select.go | 15 ++++++++++++--- commands/account/view.go | 15 ++++++++++++--- 11 files changed, 128 insertions(+), 36 deletions(-) (limited to 'commands/account') diff --git a/commands/account/account.go b/commands/account/account.go index c590c8a..9c90087 100644 --- a/commands/account/account.go +++ b/commands/account/account.go @@ -8,9 +8,9 @@ var ( AccountCommands *commands.Commands ) -func register(name string, cmd commands.AercCommand) { +func register(cmd commands.Command) { if AccountCommands == nil { AccountCommands = commands.NewCommands() } - AccountCommands.Register(name, cmd) + AccountCommands.Register(cmd) } diff --git a/commands/account/cf.go b/commands/account/cf.go index 2816473..197e956 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -10,12 +10,22 @@ var ( history map[string]string ) +type ChangeFolder struct{} + func init() { history = make(map[string]string) - register("cf", ChangeFolder) + register(ChangeFolder{}) +} + +func (_ ChangeFolder) Aliases() []string { + return []string{"cf"} +} + +func (_ ChangeFolder) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func ChangeFolder(aerc *widgets.Aerc, args []string) error { +func (_ ChangeFolder) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 2 { return errors.New("Usage: cf ") } diff --git a/commands/account/compose.go b/commands/account/compose.go index aeb415e..cafba78 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -6,12 +6,22 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type Compose struct{} + func init() { - register("compose", Compose) + register(Compose{}) +} + +func (_ Compose) Aliases() []string { + return []string{"compose"} +} + +func (_ Compose) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } // TODO: Accept arguments for default headers, message body -func Compose(aerc *widgets.Aerc, args []string) error { +func (_ Compose) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 1 { return errors.New("Usage: compose") } diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go index d245821..be9b14a 100644 --- a/commands/account/mkdir.go +++ b/commands/account/mkdir.go @@ -10,11 +10,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/worker/types" ) +type MakeDir struct{} + func init() { - register("mkdir", Mkdir) + register(MakeDir{}) +} + +func (_ MakeDir) Aliases() []string { + return []string{"mkdir"} +} + +func (_ MakeDir) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func Mkdir(aerc *widgets.Aerc, args []string) error { +func (_ MakeDir) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 2 { return errors.New("Usage: :mkdir ") } diff --git a/commands/account/next-folder.go b/commands/account/next-folder.go index 6ad3d54..414e606 100644 --- a/commands/account/next-folder.go +++ b/commands/account/next-folder.go @@ -8,16 +8,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type NextPrevFolder struct{} + func init() { - register("next-folder", NextPrevFolder) - register("prev-folder", NextPrevFolder) + register(NextPrevFolder{}) } -func nextPrevFolderUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +func (_ NextPrevFolder) Aliases() []string { + return []string{"next-folder", "prev-folder"} +} + +func (_ NextPrevFolder) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func NextPrevFolder(aerc *widgets.Aerc, args []string) error { +func (_ NextPrevFolder) Execute(aerc *widgets.Aerc, args []string) error { if len(args) > 2 { return nextPrevFolderUsage(args[0]) } @@ -44,3 +49,7 @@ func NextPrevFolder(aerc *widgets.Aerc, args []string) error { } return nil } + +func nextPrevFolderUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +} diff --git a/commands/account/next-result.go b/commands/account/next-result.go index d89de56..24d53be 100644 --- a/commands/account/next-result.go +++ b/commands/account/next-result.go @@ -7,16 +7,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type NextPrevResult struct{} + func init() { - register("next-result", NextPrevResult) - register("prev-result", NextPrevResult) + register(NextPrevResult{}) } -func nextPrevResultUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [[%%]]", cmd)) +func (_ NextPrevResult) Aliases() []string { + return []string{"next-result", "prev-result"} +} + +func (_ NextPrevResult) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func NextPrevResult(aerc *widgets.Aerc, args []string) error { +func (_ NextPrevResult) Execute(aerc *widgets.Aerc, args []string) error { if len(args) > 1 { return nextPrevResultUsage(args[0]) } @@ -39,3 +44,7 @@ func NextPrevResult(aerc *widgets.Aerc, args []string) error { } return nil } + +func nextPrevResultUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [[%%]]", cmd)) +} diff --git a/commands/account/next.go b/commands/account/next.go index 3b9260c..f306b48 100644 --- a/commands/account/next.go +++ b/commands/account/next.go @@ -9,18 +9,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 nextPrevMessageUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [[%%]]", cmd)) +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 { if len(args) > 2 { return nextPrevMessageUsage(args[0]) } @@ -63,3 +66,7 @@ func NextPrevMessage(aerc *widgets.Aerc, args []string) error { } return nil } + +func nextPrevMessageUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [[%%]]", cmd)) +} diff --git a/commands/account/pipe.go b/commands/account/pipe.go index d3cc80a..a68ef64 100644 --- a/commands/account/pipe.go +++ b/commands/account/pipe.go @@ -8,11 +8,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 [args...]") } diff --git a/commands/account/search.go b/commands/account/search.go index 513ad43..a8640dc 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -9,12 +9,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type SearchFilter struct{} + func init() { - register("search", SearchFilter) - //register("filter", SearchFilter) // TODO + register(SearchFilter{}) +} + +func (_ SearchFilter) Aliases() []string { + return []string{"search"} +} + +func (_ SearchFilter) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func SearchFilter(aerc *widgets.Aerc, args []string) error { +func (_ SearchFilter) Execute(aerc *widgets.Aerc, args []string) error { var ( criteria *imap.SearchCriteria = imap.NewSearchCriteria() ) diff --git a/commands/account/select.go b/commands/account/select.go index 707f6c9..70e08ac 100644 --- a/commands/account/select.go +++ b/commands/account/select.go @@ -7,12 +7,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type SelectMessage struct{} + func init() { - register("select", SelectMessage) - register("select-message", SelectMessage) + register(SelectMessage{}) +} + +func (_ SelectMessage) Aliases() []string { + return []string{"select", "select-message"} +} + +func (_ SelectMessage) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func SelectMessage(aerc *widgets.Aerc, args []string) error { +func (_ SelectMessage) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 2 { return errors.New("Usage: :select-message ") } diff --git a/commands/account/view.go b/commands/account/view.go index f7f3ec6..cec65aa 100644 --- a/commands/account/view.go +++ b/commands/account/view.go @@ -6,12 +6,21 @@ import ( "git.sr.ht/~sircmpwn/aerc/widgets" ) +type ViewMessage struct{} + func init() { - register("view", ViewMessage) - register("view-message", ViewMessage) + register(ViewMessage{}) +} + +func (_ ViewMessage) Aliases() []string { + return []string{"view-message", "view"} +} + +func (_ ViewMessage) Complete(aerc *widgets.Aerc, args []string) []string { + return nil } -func ViewMessage(aerc *widgets.Aerc, args []string) error { +func (_ ViewMessage) Execute(aerc *widgets.Aerc, args []string) error { if len(args) != 1 { return errors.New("Usage: view-message") } -- cgit 1.4.1-2-gfad0 href='#n219'>219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401