aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
Commit message (Collapse)AuthorAgeFilesLines
* main: add aliases for flags and optionsRobin Jarry2024-06-281-14/+18
| | | | | | | | | | Add --help and --version as aliases of -h and -v, respectively. Also add short flags for other options. Reported-by: Peter Sanchez <pjs@petersanchez.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* main: detect invalid arguments earlyRobin Jarry2024-06-281-0/+10
| | | | | | | | | | | | | | | | | | | | | Currently, when running aerc --help or aerc --version, we get an obscure error when aerc is already running. $ aerc --help response: command not understood When it is not running, it starts but prints the same error message in the status line with weird colors. Avoid sending garbage into the control socket. Try to detect invalid arguments early. $ aerc --foobaz error: unknown argument: --foobaz Reported-by: Peter Sanchez <pjs@petersanchez.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* ipc: add more fine-grained options to disable IPCJason Cox2024-04-131-1/+4
| | | | | | | | | | | | Add disable-ipc-mailto and disable-ipc-mbox to make mailto:... and mbox:... commands always run in a new instance, while still allowing aerc-internal commands (i.e., aerc :<command...>) to run over IPC. Changelog-added: Add config options `disable-ipc-mailto` and `disable-ipc-mbox` to make `mailto:...` and `mbox:...` commands always run in a new aerc instance. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ipc: disable IPC completely when disable-ipc=trueJason Cox2024-04-131-9/+11
| | | | | | | | | | | | | | | Truly disable IPC when disable-ipc is set to true in aerc.conf. Don't run commands over IPC and don't start an IPC server. Being able to disable IPC in the config is useful because it allows making aerc open mailto links in a new instance without modifying the aerc.desktop file. There are of course potential security benefits as well. Changelog-changed: The `disable-ipc` option in `aerc.conf` completely disables IPC. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ipc: add --no-ipc flag to completely disable IPCJason Cox2024-04-131-7/+13
| | | | | | | | | | | | | | | | | Running aerc mailto:... and aerc mbox:... can be confusing; if there's another aerc instance already open, the action will be performed in the other instance, which may not be visible. Add a --no-ipc flag that runs these actions, and aerc-internal commands (i.e., aerc :<command>), in the new aerc instance instead. Also, if --no-ipc is passed, don't listen on a socket for IPC calls from other aerc instances. Changelog-added: Add `--no-ipc` flag to run `aerc mailto:...`, `aerc mbox:...`, and `aerc :<command...>` within the current aerc instance and prevent listening for IPC calls from other aerc instances. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ipc: retry failed command directly, not over IPCJason Cox2024-04-131-13/+7
| | | | | | | | | If IPC fails the first time we try it, we know that no other aerc instance is running. When we retry, run the command directly instead of going through the current instance's own IPC server. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ipc: improve error handlingJason Cox2024-04-131-11/+20
| | | | | | | | | | | | | | | Detect error responses in addition to errors connecting, sending the request, and receiving the response. If an error occurs when retrying the IPC call, keep the new aerc instance running and simply show the error. We already know (due to the initial failed IPC call) that no other aerc instance is running. Keeping the new instance open also improves the visibility of the error in some cases, such as when clicking on a malformed mailto link causes a new aerc instance to open. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ipc: fix deadlock when aerc is not runningRobin Jarry2024-02-221-4/+7
| | | | | | | | | | | | | Defer the execution of failed IPC commands *after* the IPC socket has been unblocked. Fixes: fd4dd4240885 ("ipc: wait for app to be ready before accepting commands") Fixes: https://todo.sr.ht/~rjarry/aerc/229 Changelog-fixed: Deadlock when running `aerc mailto:foo@bar.com` without another instance of aerc already running. Reported-by: Skejg <grolleman@zoho.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Tim Culverhouse <tim@timculverhouse.com>
* config: improve styleset error reportingRobin Jarry2024-02-141-1/+1
| | | | | | | | | Include the styleset filepath and exact statement that caused the error. Remove the "failed to load config: " prefix in the error message. The line is often very long already. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* log: move package to libRobin Jarry2024-02-141-1/+1
| | | | | | | This has nothing to do at the root of the source tree. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Bence Ferdinandy <bence@ferdinandy.com>
* aerc: set title using vaxisTim Culverhouse2024-02-121-28/+0
| | | | | | | Set the window title using Vaxis at UI initialization. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* ui: remove screen and viewportsTim Culverhouse2024-02-121-3/+0
| | | | | | | | Remove references to tcell.Screen or views.Viewports. Convert Contexts and the core UI struct to use Vaxis objects only. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* main: improve version stringRobin Jarry2024-02-011-8/+7
| | | | | | | | | | | | | | | | | | | | | | | Initialize a build variable to the date on which the binary was generated. Include the date in the build info string which is output when running aerc -v and in the crash logs. Do not rely on parsing the build flags via some obscure base64 voodoo to determine if notmuch support is available or not. Instead, use the symbols from the linked library directly if available. Before: $ aerc -v 0.16.0-183-g4cc2e6be3a01 +notmuch (go1.21.6 amd64 linux) After: $ aerc -v aerc 0.16.0-183-g4cc2e6be3a01 +notmuch-5.6.0 (go1.21.6 amd64 linux 2024-01-31) Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Ciarán Ainsworth <cda@sporiff.dev>
* ipc: wait for app to be ready before accepting commandsRobin Jarry2024-01-311-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Pass a cancellable context to the IPC server and defer accepting connections until the first worker message has been received by the main thread. This is not a real fix for the :split command not working at startup. :split requires a mail store to be present on the currently selected account tab+folder. I could have waited for a types.DirectoryContents message but it seems silly and bug prone since such a message may never arrive and we don't want to pool IPC messages forever. Also, a types.DirectoryContents message may arrive for one account but :split is only effective *per account* and the default selected account tab is the first one. In any case, this band aid prevents aerc from crashing or breaking down the terminal when running IPC commands in the aerc-startup hook. Fixes: https://lists.sr.ht/~rjarry/aerc-devel/%3CCYPN7AVYQ69S.WV0T67VM6WX3%40wegtam.com%3E Fixes: https://todo.sr.ht/~rjarry/aerc/173 Reported-by: Jens Grassel <jens@wegtam.com> Reported-by: Justine Smithies <justine@smithies.me.uk> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Thomas Böhler <witcher@wiredspace.de> Reviewed-by: Thomas Böhler <witcher@wiredspace.de>
* main: add flags to override config filesBence Ferdinandy2024-01-211-5/+13
| | | | | | | | | | | | Add --aerc-conf, --binds-conf and --accounts-conf CLI flags, which respectively override the default aerc.conf, binds.conf and accounts.conf configuration files. If the specified files do not exist or cannot be read, exit with an error. Implements: https://todo.sr.ht/~rjarry/aerc/209 Changelog-added: CLI flags to override paths to config files. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: refactor registrationRobin Jarry2024-01-201-99/+12
| | | | | | | | | | | | | | | | | | Register all commands with the same function and store them in the same map. Use bit flags to determine in which contexts each command should be available. Remove duplicate commands now that the same command can be exposed in multiple contexts. Refactor API to allow executing commands from other commands without import cycles. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
* commands: fix abbreviations regressionVitaly Ovchinnikov2023-12-311-7/+7
| | | | | | | | | | Make commands abbreviations work again by fixing the mistake introduced in one of the recent commits. Fixes: 07c1cefcf62d ("patch: create sub-command structure") Signed-off-by: Vitaly Ovchinnikov <v@ovch.ru> Reviewed-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* patch: create sub-command structureKoni Marti2023-12-301-1/+9
| | | | | | | | Create the sub-command structure for the :patch command. Make the :patch command accessible from any context. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: use completion from go-optRobin Jarry2023-10-281-1/+1
| | | | | | | | | | | Implement command completion with complete struct field tags from the get-opt library introduced earlier. Changelog-changed: Improved command completion. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
* commands: remove command set completion apiRobin Jarry2023-10-281-11/+28
| | | | | | | | | | | Do not expose the completion of a command via its command set. Instead, require a single command object to be resolved in order to execute it. Extract the command names and the template terms completions in main.go. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
* main: parse command line args with go-optRobin Jarry2023-10-281-28/+59
| | | | | | | | | | | | | Use get-opt to make argument parsing more explicit and have automatic usage generation. Update the man page to include missing details. Add a -h flag to display verbose usage and descriptions of options. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
* commands: remove command set execute apiRobin Jarry2023-10-281-35/+25
| | | | | | | | | | Do not expose the execution of a command via its command set. Instead, require a single command object to be resolved in order to execute it. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
* commands: expand templates before command resolutionRobin Jarry2023-10-281-1/+5
| | | | | | | | Move the template expansion before the command name is looked up. It saves a few void renderings and will be required for the next commits. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* commands: pass raw command line down to template evaluationRobin Jarry2023-10-281-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | Some commands need to invoke others and/or run shell commands. For this, we need the raw command line as entered by the user. Pass it down the call chain just before it is split to invoke the command Execute method. Remove unit tests for the template expand() test which does have any added value now that it is performed on a single string without any quote juggling. Update all code to handle a single string instead of a list of arguments. Introduce a new dependency on git.sr.ht/~rjarry/go-opt to deal with shell splitting. This is in preparation for using opt.ArgsToStruct to parse arguments for all aerc commands. There should be no functional change after this patch. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
* aerc: initialise the random number generatorMoritz Poldrack2023-10-261-0/+5
| | | | | | | | Add an init function to the main package that seeds the RNG with based on the current time. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: add :suspendNojus Gudinavičius2023-10-241-0/+5
| | | | | | | | | Add :suspend to suspend the aerc process, returning to shell. Include documentation and default Ctrl-z keybinding for it. Changelog-added: New `:suspend` command bound to `<C-z>` by default. Signed-off-by: Nojus Gudinavičius <nojus.gudinavicius@gmail.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
* ui: export global functionsRobin Jarry2023-10-111-14/+7
| | | | | | | | | | | | | There is no need for an UI object. The Aerc.ui field is unused. And there is a single instance of it anyway. Move the object's public fields as global variables and change methods to public functions. This makes the code cleaner and removes boilerplate. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* app: export global functionsRobin Jarry2023-10-101-22/+17
| | | | | | | | | | | | | | | The single Aerc object is passed around in almost all command functions. This hinders readability. Store the single Aerc instance as a global variable. Export public functions from the app package to access methods of that object. Remove all explicit references to *app.Aerc and replace them with calls to these functions. For references to private/unexported fields and functions from within the app package, directly access the global aerc object. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* widgets: rename package to appRobin Jarry2023-10-101-9/+9
| | | | | | | | | This is the central point of all aerc. Having it named widgets is confusing. Rename it to app. It will make a cleaner transition when making the app.Aerc object available globally in the next commit. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* commands: strip leading colons from commandsBence Ferdinandy2023-09-191-1/+1
| | | | | | | | | | | When giving advice on commands to run the colon is often included to signify that the snippet is needs to be run as an aerc command. Unfortunately, copying this into the command prompt of aerc leads to an error. Copy the behaviour of vim and strip any number of leading colons from command names. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* commands: run a command by its first lettersVitaly Ovchinnikov2023-09-191-0/+42
| | | | | | | | | | | Check if the command entered after : is the abbreviation of an existing command and run that instead. This is only done if there is no complete name matching first-hand and if the abbreviation matches just one command. Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* ui: fix deadlocks in message channelRobin Jarry2023-05-201-17/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are several ways the ui message channel can fill up leading to deadlocks. 1) Invalidate() changes the value of uiState to DIRTY. The following call sequence: QueueRedraw() Invalidate() QueueRedraw() Leads to multiple nil messages being queued in the message channel whereas one could assume that the second QueueRedraw() would do nothing. This is caused by the tri-state nature of uiState. 2) We use the same channel to convey state change, keyboard events and redraw requests. Since a keyboard event almost always triggers a redraw, we end up trying to append a redraw message in the same goroutine that reads from the channel. This triggers a deadlock when there are more than 50 pending messages. Solve the issue by using multiple channels, one per type of message that needs to be sent to the main ui thread. Remove QueueRedraw() and merge its functionality in Invalidate(). Only use a DIRTY/CLEAN state to determine if something needs to be queued in the redraw channel. Use a channel for quitting instead of an atomic. Restructure some code functions to have a cleaner API. Use a for loop in the main thread and select from all channels. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com> Tested-by: Maarten van Gompel <proycon@anaproy.nl>
* commands: expand and complete template codeKoni Marti2023-05-161-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | 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-4/+9
| | | | | | | | | | | | | | | | | | | 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>
* hooks: add aerc-shutdownMoritz Poldrack2023-04-011-0/+9
| | | | | | | | | | Add a hook to run when aerc shuts down. The environment is supplemented with the duration aerc was alive for. References: https://todo.sr.ht/~rjarry/aerc/136 Signed-off-by: Moritz Poldrack <git@moritz.sh> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* hooks: add aerc-startup hookMoritz Poldrack2023-04-011-0/+9
| | | | | | | | | | | Add a hook to run when aerc starts up. The environment is supplemented with aerc version and the path to its binary. References: https://todo.sr.ht/~rjarry/aerc/136 References: https://todo.sr.ht/~rjarry/aerc/139 Signed-off-by: Moritz Poldrack <git@moritz.sh> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* main: rename aerc.go -> main.goRobin Jarry2023-03-151-0/+263
I like it better that way. And it will not piss me off every time I need to use auto completion. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>