aboutsummaryrefslogtreecommitdiffstats
path: root/commands/commands.go
Commit message (Collapse)AuthorAgeFilesLines
* commands: fix panic in template executionKoni Marti2023-06-201-0/+3
| | | | | | | | | | | | Fix a panic in the template execution when the template evalutes to nil. Check for length of returned arguments after the template code is expanded. To reproduce, run :{{exec "cat > /dev/null" .MessageId}} Fixes: 42cd4157 ("commands: execute commands with templates") Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* templates: use template interface consistentlyKoni Marti2023-05-161-3/+2
| | | | | | | | | | | | | | | Use the template interface consistently. Before, we have exported the state.TemplateData struct and used it in most places instead of the models.TemplateData interface. This lead to some inconsistencies, i.e. Role() has been defined on the exported struct but not on the interface. Unexport the state.TemplateData struct, add a DataSetter interface to set the data needed for the template data and call the Data() method which returns a models.TemplateData interface when the template data is needed. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* commands: execute commands with templatesKoni Marti2023-05-161-18/+52
| | | | | | | | | | | | Execute template code before running a command. With this, we can use templates in our keybinds like: [messages] E = :'{{if match (.Flags|join "") "O"}}envelope{{else}}view{{end}}'<Enter> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: expand and complete template codeKoni Marti2023-05-161-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | | Expand and complete template code. The exline does understand template code and can evaluate it. With this patch, the completion systems supports writing the templates by showing the available template data fields and template functions. Pressing <Tab> after }} will show the evaluated template in the completion menu. Complex template code, such as if-else statements work as well. Examples: :filter -f {{<Tab> will show the possible template data fields and functions :filter -f {{index (.To|email) 0}}<Tab> will show the value of the template expression in the completion list Pressing <Tab> twice after a completed template expression will substitute the expression with its value. :{{if match .Folder "INBOX"}}check-mail{{else}}cf INBOX{{end}} Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: add OptionsProvider and OptionCompleterKoni Marti2023-05-161-29/+104
| | | | | | | | | | | | | | | | | | | Improve command completion by supporting option flags and option arguments completion. Option completion is activated when the command implements the OptionsProvider interface. Implementing the OptionCompleter allows the completion of individual option arguments. The completion interfaces harmonizes the completion behavior in aerc, makes the completion code clearer and simplifies the completion functionality. With this patch, the Complete method on commands will only have to deal with the actual completion, i.e. paths, folders, etc and not worry about options. To remove all options and its mandatory arguments from args, use commands.Operands(). Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* directory: add role to template fieldsTim Culverhouse2023-04-221-2/+2
| | | | | | | | | Add .Role as a template field for use in distinguishing between mailboxes with a given IANA role, or custom role defined by aerc ("query" for notmuch queries, for example). Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry<robin@jarry.cc>
* triggers: use templates instead of % mini languageRobin Jarry2023-02-201-5/+16
| | | | | | | | | | | | | | | | | | | | | Since previous commit, all commands now support expanding text/template markup. Reuse that for the new-email trigger command. Update commands.ExecuteCommand to take optional *AccountConfig and *MessageInfo arguments. If these are nil, fallback to using the currently selected account and message (if any). Pass the proper *AccountConfig and *MessageInfo objects when firing the trigger command so that these are used instead of the currently selected ones. If new-email contains % placeholders, try to convert them to template markup reusing the same conversion added in commit 535300cfdbfc ("config: add columns based index format"). Warn the user that they need to update their configuration file. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
* commands: expand template placeholdersAivars Vaivods2023-02-201-1/+45
| | | | | | | | | Interpret go template constructs in all aerc command arguments based on the currently selected account, folder and message (if any). Signed-off-by: Aivars Vaivods <aivars@vaivods.lv> Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Tim Culverhouse <tim@timculverhouse.com>
* logging: add trace to every command callBence Ferdinandy2023-01-261-0/+2
| | | | | | | | | A previous commit introduced a trace loglevel, but aerc doesn't make much use of it. Logging is not very informative either. Add a log.Tracef to every command and log the provided arguments as well. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: implement prompt completionSergey Smirnykh2022-07-021-0/+7
| | | | | | | | | | | | | | | | | | | | | This patch implements :prompt completion. The completion mechanism only provides completions when there is at least one argument specified (prompt text). The mechanism is based on other commands' completions and works as follows: 1. Attempts to look up a command by the name specified in args[1]. 2.a On success it uses command.Complete. 2.b Otherwise, if total arguments count is lesser or equals than 2 (i.e. no command arguments specified), it attempts to complete the command's name. Additional effort is made to preserve prompt text, which often contains spaces and formatting. Signed-off-by: Sergey Smirnykh <sergey.smirnykh@siborgium.xyz> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: fix possible panic in CompletionFromListkt programs2022-03-161-1/+1
| | | | | | | Panic might occur if aerc.SelectedAccount() is nil Signed-off-by: kt programs <ktprograms@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* bindings: fix panic for terminal keybindKoni Marti2022-03-141-1/+1
| | | | | | | | | | Fix panic in the GetCompletions function when using the keybind for the terminal command. Fixes: https://todo.sr.ht/~rjarry/aerc/29 Reported-by: inwit <inwit@sindominio.net> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: implement fuzzy completion for commands and optionskt programs2022-03-071-45/+12
| | | | | | | | Change the option to enable fuzzy completion to be fuzzy-complete, since it's no longer only used for folders Signed-off-by: Kt Programs <ktprograms@gmail.com> Acked-by: Koni Marti <koni.marti@gmail.com>
* aerc: always check SelectedAccount return valueRobin Jarry2022-02-251-5/+13
| | | | | | | | | | | | | | | | aerc.SelectedAccount() is used in lots of places. Most of them without checking the return value. In some cases, the currently selected tab is not related to any account (widget.Terminal for example). This can lead to unexpected crashes when accessing account specific configuration. When possible, return an error when no account is currently selected. If no error can be returned, fallback to non-account specific configuration. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com>
* completions: add folder flexible search as an optioninwit2022-01-311-1/+14
| | | | | | | | | | | Provide an option to change the completion style when selecting a folder from completing with folders starting with the input string to completing with folders in which the input string is a substring present at any point in the folder name. References: https://lists.sr.ht/~sircmpwn/aerc/%3C20201129181020.186984-1-inwit%40sindominio.net%3E References: https://lists.sr.ht/~sircmpwn/aerc/%3C20210223202536.199355-1-clayton%40craftyguy.net%3E Signed-off-by: inwit <inwit@sindominio.net>
* go.mod: change base git urlRobin Jarry2021-11-051-1/+1
| | | | | | | I'm not sure what are the implications but it seems required. Link: https://github.com/golang/go/issues/20883 Signed-off-by: Robin Jarry <robin@jarry.cc>
* msg/archive: complete the possible optionsReto Brunner2020-04-111-0/+15
|
* modify-labels: add completionReto Brunner2019-12-211-0/+35
|
* Fix directory completion case sensitivityBen Burwell2019-08-031-11/+19
| | | | | | Before, lower_only was not being correctly set and was only considering whether the string ended with a lowercase sequence. Refactored this with some more explicit functions as the logic is a little confusing.
* Add tab completion to textinputsJeffas2019-07-261-3/+14
| | | | | | | | | | | | | This adds tab completion to textinput components. They can be configured with a completion function. This function is called when the user presses <tab>. The first completion is initially shown to the user inserted into the text. Repeated presses of <tab> or <backtab> cycle through the completions list. The completions list is invalidated when any other non-tab-like key is pressed. Also changed is some logic for current completion generation so that all available commands are returned when <tab> is pressed with no current text and similarly for arguments of commands.
* Add new-email triggerJeffas2019-07-261-5/+1
| | | | | | | | | | | | | | | | | This patch sets up the trigger config section of aerc.conf. Each trigger has its own function which is called from the place where it is triggered. Currently only the new-email trigger is implemented. The triggers make use of format strings. For instance, in the new-email trigger this allows the user to select the trigger command and also the information extracted from the command and placed into their command. To actually execute the trigger commands the keypresses are simulated. Further triggers can be implemented in the future. Formatting of the command is moved to a new package.
* Remove unused caps stringDrew DeVault2019-07-041-2/+0
|
* Add IMAP folder tab completionGregory Mullen2019-07-041-0/+23
| | | | | Credit for this fix goes to Reto; I guess if we're not gonna be mutt we should probabaly do things correctly.
* Implement basic tab completion supportGregory Mullen2019-06-291-9/+69
| | | | | Tab completion currently only works on commands. Contextual completion will be added in the future.
* s/aerc2/aerc/gDrew DeVault2019-05-171-1/+1
|
* Add context-specific commandsDrew DeVault2019-03-211-11/+25
|
* Implement :cd commandDrew DeVault2019-03-141-4/+3
|
* Flesh out command parsing & handlingDrew DeVault2019-03-101-4/+13
|
* Start building out command subsystemDrew DeVault2019-03-101-0/+28