Commit Graph

81 Commits

Author SHA1 Message Date
Tim Culverhouse ba24e92062 invalidatable: cleanup dead code
Remove invalidatable type and all associated calls. All items can
directly invalidate the UI.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-10-12 22:16:40 +02:00
Tim Culverhouse 83136234a4 dirlist: prevent race condition on accessing uiconfig
Prevent a race condition when accessing UI Config maps

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-09-29 21:21:00 +02:00
Koni Marti 0e50f29bf3 notmuch: move logic for dynamic folders to backend
Moves logic for creating dynamic folders from the dirlist widget to the
backend. Since dynamic folders are notmuch-specific, the notmuch backend
should be responsible for correctly setting up those folders. It does
that by sending two DirectoryInfos: the first to create the message
store, the second to fetch the directory content.

This approach also fixes a deadlock introduced by 716ade8968
("worker: lock access to callback maps").

Reported-by: Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-09-29 16:52:12 +02:00
Tim Culverhouse c8c4b8c7cb dirlist: avoid race from accessing ui config in Select debounce
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-09-26 17:31:15 +02:00
Tim Culverhouse aa01f0f6dc dirlist: don't invalidate on spinner.Invalidate
The dirlist is invalidated explicitly after the spinner is stopped.
For simplicitly, don't invalidate on spinner.Invalidate.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-09-20 21:05:48 +02:00
Tim Culverhouse e1b62db583 fix: Set proper UIConfig for msgstores
The merged UIConfig used to create new message stores is based on the
selected directory. If the message store is created by other means than
selecting (ListDirectories for maildir/notmuch/mbox, or check-mail) it
may have an incorrect configuration if the user has folder-specific
values for:

- Threaded view
- Client built threads
- Client threads delay
- Sort criteria
- NewMessage bell

Use the correct merged UIConfig when creating a new message store.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-22 09:30:37 +02:00
Moritz Poldrack 978d35d356 lint: homogenize operations and minor fixes (gocritic)
Apply GoDoc comment policy (comments for humans should have a space
after the //; machine-readable comments shouldn't)

Use strings.ReplaceAll instead of strings.Replace when appropriate

Remove if/else chains by replacing them with switches

Use short assignment/increment notation

Replace single case switches with if statements

Combine else and if when appropriate

Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:58:01 +02:00
Moritz Poldrack c882cf9960 lint: removed unused code (deadcode, structcheck, unused)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:58:00 +02:00
Moritz Poldrack 2534612c59 lint: remove unused structs and functions (unused)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:57:48 +02:00
Moritz Poldrack aaf0a0c656 lint: apply new formatting rules
Run `make fmt`.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:44:52 +02:00
Robin Jarry cd19995557 logging: use level-based logger functions
Do not pass logger objects around anymore. Shuffle some messages to make
them consistent with the new logging API. Avoid using %v when a more
specific verb exists for the argument types.

The loggers are completely disabled (i.e. Sprintf is not even called)
by default. They are only enabled when redirecting stdout to a file.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
2022-07-23 22:52:15 +02:00
Tim Culverhouse c2f4404fca threading: enable filtering of server-side threads
This patch enables the filtering of a threaded view which uses
server-built threads. Filtering is done server-side, in order to
preserve the use of server-built threads.

In adding this feature, the filtering of notmuch folders was brought up
to feature parity with the other workers. The filters function the same
(ie: they can be stacked). The notmuch filters, however, still use
notmuch syntax for the filtering.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00
Tim Culverhouse 4240f1fbfd perf: reduce calls to GetUiConfig
GetUiConfig was being called many times, and came up as a high CPU user
in a cpuprofile. Every call would merge a UIConfig, which is a costly
operation. Ideally, we would only need to have a config for every
account X every directory. We also have a context for subjects. This
patch stores all FOLDER and ACCOUNT level configs and reuses those
merged objects. The SUBJECT contexts are not stored in favor of merging
on-the-go, with a TODO comment to deprecate that feature and implement a
better per-message styling option. I suspect this feature is not used
very much.

Before applying this patch with my setup, GetUiConfig is called 1159
times just to open aerc. After applying, this is reduced to 37.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-03 21:32:24 +02:00
Tim Culverhouse d45c07eb6a uiconfig: use pointer references to uiConfig
This patch changes references to uiConfig in function signatures and
structs to be pointers.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-03 21:32:18 +02:00
Moritz Poldrack 964b362ceb dirlist: fix race condition in directory selection
This replaces a channel that is used like a context with a context.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-06-26 12:07:44 +02:00
Tim Culverhouse ed005f770c dirlist: fix ruestring counts from checkmail
Commit 8b6f971 broke ruestring counts when AccurateCounts=true, which
primarily occur from a checkmail. This restores the functionality.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-14 22:12:31 +02:00
Tim Culverhouse 115447e57f dirlist: fix panic when disconnecting with dirlist-tree=false
Commit 2027223a created a panic when attempting to clear the dirlist
when the config option dirlist-tree is set to false.

This patch fixes that panic by creating a dirlist.ClearList() function
to prevent needing to check a callback.

Tested with both dirlist-tree=false and true

Fixes: 2027223ab3 ("fix: clear dirlist on disconnect")
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-07 18:01:25 +02:00
Tim Culverhouse 2027223ab3 fix: clear dirlist on disconnect
A message of Done:Disconnect will trigger an update of the dirlist. An
update of the dirlist will issue a ListDirectories message, which causes
an imap: client not ready error by trying to use the imap connection -
which is disconnected. By not issuing the update, we prevent using a
disconnected client.

This patch checks for connection state prior to updating the dirlist. A
disconnected state will clear out the dirlist.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-07 16:19:31 +02:00
Tim Culverhouse 8b6f9719a8 dirlist: update RUE counts for imap/maildir on move|copy|delete|archive
When moving/copying/deleting/archiving a message in imap, the RUE counts
displayed in the dirlist would not update properly. Maildir has (had) an
implementation that recounts the entire directory and updates the
DirectoryInfo after one of these actions.

This patch implements a more efficient method of updating, and also
enables it to apply to IMAP without any additional requests. Upon
completion of the action, the counts are manually updated with the count
of messages in the action and recent and/or unseen states of those
messages. This is more efficient for maildir, because we aren't counting
everything in the store. For IMAP, we get the updates for free because
we are only performing the update after confirmation from the server
that the action has happened.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-07 16:19:23 +02:00
Tim Culverhouse 4985d1bab8 fix: rue string count accuracy
The countRUE function was inaccurately counting flags. If a message was
unread and recent, it was only counted as recent. The two flags are not
mutually exclusive. A previous count for a mailbox with 1 recent, 1
unread, and 5 existing would be :
1/0/5

An accurate count of this state would be:
1/1/5

This patch fixes the count.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-07 15:50:32 +02:00
Tim Culverhouse 2551dd1bfa feat: add background mail polling option for all workers
Check for new mail (recent, unseen, exists counts) with an external
command, or for imap with the STATUS command, at start or on
reconnection and every X time duration

IMAP:
The selected folder is skipped, per specification. Additional config
options are included for including/excluding folders explicitly.

Maildir/Notmuch:
An external command will be run in the background to check for new mail.
An optional timeout can be used with maildir/notmuch. Default is 10s

New account options:
check-mail
check-mail-cmd (maildir/notmuch only)
check-mail-timeout (maildir/notmuch only), default 10s
check-mail-include (IMAP only)
check-mail-exclude (IMAP only)

If unset, or set less than or equal to 0, check-mail will be ignored

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-31 14:32:51 +02:00
Koni Marti e1ae7b80cc dirlist: add format specifier to compact folder name
Add the format specifier %N to the dirlist-format to display compacted
folder names.

A folder such as INBOX/WORK/PROJECT will be compacted to I/W/PROJECT in
the directoy list.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-04-29 13:41:38 +02:00
Tim Culverhouse afe35839ed style: add style config options for dirlist_unread and dirlist_recent
Adds two style options: dirlist_unread and dirlist_recent. These options
apply in layers, in the same way as msglist_* styles do.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-27 09:46:06 +02:00
Aivars Vaivods d3a10b4983 Initialization fix for dynamic folders
There is an issue with backends, that provide dynamic folders, namely
when opening folder, that isn't defined in config file, you get empty
folder. To actually get messages listed, you need to open that folder
twice.

At first attempt only DirectoryInfo is fetched and new
MessageStore created. Second attempt populates previously created
MessageStore with list of messages.

For pre-configured folders, DirectoryInfos are fetched upon connection
to backend and, when folder is opened, MessageStore is updated with list
of messages.

Fixes: https://todo.sr.ht/~rjarry/aerc/30
Signed-off-by: Aivars Vaivods <aivars@vaivods.lv>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:48:21 +02:00
Moritz Poldrack ae83373fa6 logging: added a log on panic
Since panics still regularly "destroy" the terminal, it is hard to get a
stack trace for panics you do not anticipate. This commit adds a panic
handler that automatically creates a logfile inside the current working
directory.

It has to be added to every goroutine that is started and will repair
the terminal on a panic.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-03-23 20:56:09 +01:00
Koni Marti 515a8b56f6 scrollable: extract scrolling behavior for reuse
Extract the vertical scrolling ability into its own Scrollable struct
that can be embedded and reused across any ui element that relies on
scrolling.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-03-03 21:11:05 +01:00
inwit 91ead11c47 ui: make dirlist-delay context-aware
Allow this in aerc.conf:

  dirlist-delay=200ms
  ...
  [ui:account=CrappyO365Account]
  dirlist-delay=2000ms

Fixes: https://todo.sr.ht/~rjarry/aerc/26
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Signed-off-by: inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-02-24 17:45:56 +01:00
Koni Marti 454606a9cd dirtree: implement foldable tree for directory list
implement a foldable tree for the directory list. Expand all parent
directories when a hidden directory is selected with the change-folder
command.

folders-sort considers the top-level directories only. The folders and
foldersexclude filters work with the full directory path.

Enable tree view by adding 'dirlist-tree=true' to the config file.

Implements: https://todo.sr.ht/~sircmpwn/aerc2/228
Signed-off-by: Koni Marti <koni.marti@gmail.com>
2022-02-23 21:09:01 +01:00
Robin Jarry a5c046efe3 dirlist: use shorter delay before listing directory contents
1 second is a bit excessive. Use 200ms which should cover most quick
folder changes.

Add an option to make that delay configurable by the users.

References: https://todo.sr.ht/~rjarry/aerc/16
Fixes: cb3090956c ("dirlist: skip unnecessary change-folder action")
Suggested-by: Koni Marti <koni.marti@gmail.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-01-29 22:01:25 +01:00
Koni Marti cb3090956c dirlist: skip unnecessary change-folder action
when traversing the directory list, aerc will fetch the contents for
every directory even though the user might just move on to the next.
This causes an unnecessary delay (and load on the worker) and can be
avoided by skipping the old change-folder action when a newer one
arrives within a predefined time interval.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
2022-01-24 09:51:32 +01:00
Koni Marti eafb537081 dirlist: improve change-folder responsiveness
improves change-folder responsiveness. When changing folders, the
highlighted directory is currently updated in a callback function to the
open-directory action. This creates an unpleasent lag in the ui until
the entire operation is done. Instead, we should provide an immediate
visual feedback of the selection to the user and keep loading the
directory contents in the background.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
2022-01-24 09:51:29 +01:00
Kalyan Sriram 402612fd97 notmuch: allow sort by file order
When using the notmuch backend, it often makes more sense to sort
folders (actual virtual folders, or queries) by the order specified in
the query-map file, rather than alphabetically. This patch introduces a
configuration option (disabled by default) that allows this.

Additionally, due to the notmuch backend previously using maps (which
are order-undefined) to store the list of queries, default query
selection on aerc startup fluctuated. This patch fixes that by using
slices to store query order.
2021-11-13 15:25:04 +01:00
Robin Jarry 0d645bcebd go.mod: change base git url
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>
2021-11-05 10:21:45 +01:00
Eyal Sawady 7371d91b3c Apply dirlist style to unselected directories 2021-01-12 20:07:36 +01:00
y0ast 03650474e2 update tcell to v2 and enable TrueColor support
Also update to the tcell v2 PaletteColor api, which should keep the chosen
theme of the user intact.

Note, that if $TRUECOLOR is defined and a truecolor given, aerc will now stop
clipping the value to one of the theme colors.
Generally this is desired behaviour though.
2020-12-18 07:23:22 +01:00
Reto Brunner fe42beb3e4 dirlist: fix empty row if dir is added
There is a window where a new dir entry isn't yet in the dirlist.dir.
dirlist.ensureScroll however expected to always find a valid index.
Add a check so that we don't try to scroll to a -1 index.
2020-09-08 07:48:55 +02:00
Kalyan Sriram 905cb9dfd3 Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of
aerc's look (color scheme, font weight, etc). Default styleset is
installed to /path/to/aerc/stylesets/default.
2020-08-06 21:42:06 +02:00
Reto Brunner 3d784c5d8c Revert "Implement style configuration."
This reverts commit 1ff687ca2b.
2020-07-30 23:22:32 +02:00
Kalyan Sriram 1ff687ca2b Implement style configuration.
Introduce the ability to configure stylesets, allowing customization of
aerc's look (color scheme, font weight, etc). Default styleset is
installed to /path/to/aerc/stylesets/default.
2020-07-30 19:35:59 +02:00
ARaspiK e1c2b596dc Add a 'folders-exclude' option
Added a 'folders-exclude' option that allows removing selected folders
from the directory list sidebar. My motivating example was that removing
a single folder from the list using Golang regexes seemed pretty hard,
so this is a better way to do it. The excluded folders list is included
in the man page.
2020-07-02 09:13:14 +02:00
Jeffas c6f4d7badd Add dirlist scrollbar
This mimics the scrollbar implementation from the completion popover.
Only showing it when necessary and adapting the dirlist strings
appropriately.
2020-06-09 20:50:28 +02:00
Jeffas 3877b1aa71 Add dirlist scrolling
Should fix #402
2020-06-09 08:43:01 +02:00
Drew DeVault caad1b2c06 Revert "Add Style configuration"
This reverts commit 0f78f06610.
2020-05-28 10:32:42 -04:00
Reto Brunner 0f78f06610 Add Style configuration
The following functionalities are added to configure aerc ui styles.
- Read stylesets from file with very basic fnmatch wildcard matching
- Add default styleset
- Support different stylesets as part of UiConfig allowing contextual
  styles.
- Move widgets/ui elements to use the stylesets.
- Add configuration manual for the styleset
2020-05-27 07:57:10 +02:00
Reto Brunner 53d0c0a903 widgets/dirlist: Fix total message count
This fixes an issue with the updated count logic, where only fetched messages
where counted to the exists string of the rue count.

Note that the count is still broken (we only count read / unread messages we
fetched, but that is the same behaviour as prior to the commit
66b68f35b3)
2020-02-25 11:05:25 -05:00
Reto Brunner cb04629f3c fix missing import 2020-02-19 17:09:26 +01:00
Reto Brunner d44bdc9fb9 Revert "Only fetch the directory contents when we are switching directories"
This reverts commit bd4df53009.

I did not properly untangle the opening / dirlist update of each other.
This interferes with the imap worker, hence the revert
2020-02-19 08:37:20 +01:00
Reto Brunner 66b68f35b3 dirlist: actually honor the DirInfo
Currently the dirlist ignores the counts provided by the dirInfo.
However some of the workers can actually provide accurate counts much quicker
than if we count the flags.

Eventually we will also want to enable displaying counts for background folders,
where the brute force counting won't work as none of the headers are fetched yet.

This commit models it in an opt-in manner, if the flag isn't set then we still
count the messages manually.
2020-02-16 10:41:16 -05:00
Reto Brunner bd4df53009 Only fetch the directory contents when we are switching directories
Previously, sending a DirectoryInfo assumed that a directory change
happened. However we don't want that if we only want to update the
unread message count.
2020-02-16 10:41:15 -05:00
Andreas Rammhold aed847f9eb Ensure we aren't selecting negative directories
When the list of directories is empty trying to navigate in the
directory list did previously lead to a crash. With this change we
instead return early before trying to change the directory.

Example backtrace:

> panic: runtime error: index out of range [-1]
>
> goroutine 1 [running]:
> git.sr.ht/~sircmpwn/aerc/widgets.(*DirectoryList).NextPrev(0xc000160680, 0xffffffffffffffff)
> 	source/aerc/widgets/dirlist.go:285 +0xd4
> git.sr.ht/~sircmpwn/aerc/commands/account.NextPrevFolder.Execute(0xc000191040, 0xc00025c210, 0x1, 0x1, 0x0, 0xc00016f420)
> 	source/aerc/commands/account/next-folder.go:44 +0xe0
> git.sr.ht/~sircmpwn/aerc/commands.(*Commands).ExecuteCommand(0xc0000101a8, 0xc000191040, 0xc00025c210, 0x1, 0x1, 0xc000020070, 0xb46d01)
> 	source/aerc/commands/commands.go:66 +0xa7
> main.execCommand(0xc000191040, 0xc0001ca190, 0xc00025c210, 0x1, 0x1, 0xc00025c210, 0xc0003fb080)
> 	source/aerc/aerc.go:60 +0xc7
> main.main.func3(0xc00025c210, 0x1, 0x1, 0x1, 0x1)
> 	source/aerc/aerc.go:162 +0x57
> git.sr.ht/~sircmpwn/aerc/widgets.(*Aerc).BeginExCommand.func1(0xc000201db0, 0xb)
> 	source/aerc/widgets/aerc.go:382 +0x83
> git.sr.ht/~sircmpwn/aerc/widgets.(*ExLine).Event(0xc0003be100, 0xb475a0, 0xc00023cba0, 0xc00023cba0)
> 	source/aerc/widgets/exline.go:79 +0x131
> git.sr.ht/~sircmpwn/aerc/widgets.(*Aerc).Event(0xc000191040, 0xb475a0, 0xc00023cba0, 0x99ee01)
> 	source/aerc/widgets/aerc.go:202 +0x4c1
> git.sr.ht/~sircmpwn/aerc/widgets.(*Aerc).simulate(0xc000191040, 0xc000036f00, 0xd, 0x10)
> 	source/aerc/widgets/aerc.go:195 +0x8d
> git.sr.ht/~sircmpwn/aerc/widgets.(*Aerc).Event(0xc000191040, 0xb475a0, 0xc00023c9c0, 0x9c5a60)
> 	source/aerc/widgets/aerc.go:218 +0x3e8
> git.sr.ht/~sircmpwn/aerc/lib/ui.(*UI).Tick(0xc0001ca190, 0xa99d00)
> 	source/aerc/lib/ui/ui.go:92 +0x190
> main.main()
> 	source/aerc/aerc.go:192 +0x5f2
2020-02-07 10:40:37 -05:00