aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-06-19 22:09:19 -0500
committerRobin Jarry <robin@jarry.cc>2022-06-22 11:36:47 +0200
commitde24d2d5909adee29ea7adea9b22fbf1d02b7502 (patch)
treeae966f7f0a947f07a5040b702e39aac54d5638b7
parentbe2abb3d91fe19f8a90f550f7dce872ac5115ead (diff)
downloadaerc-de24d2d5909adee29ea7adea9b22fbf1d02b7502.tar.gz
config: fix setting of zero-value time.Duration config values
When using section.MapTo(struct) (go-ini), if the struct has a default value for a time.Duration type, a zero-value in the config will not overwrite the default. If the type is *time.Duration, it will be overwritten properly. One consideration was to change all time.Duration types to *time.Duration. This method was chosen for ease of implementation. For example, if you set dirlist-delay = 0s, the delay will be 200ms. This can be observed by logging the value just after mapping the ui section in config.go. A config value of 0.1ms will have a delay of 0.1ms. Currently, aerc has 4 time.Duration config values: 1. DirlistDelay - default 200 ms 2. CompletionDelay - default 250 ms 3. CheckMail - default unset (0) 4. CheckMailTimeout - default 10 s 1, 2, and 4 have a non-zero default value and are subject to this bug. Only 1 and 2 are fixed in this patch. Number 4 would not make sense to have a 0 second timeout, therefore we can prevent the user from doing this by keeping it as it is. Another option could be to set these to 0 in config.go. The default config (aerc.conf) has these keys in it with their default values. Presumably, we don't need to set them again in config.go. If a user deletes the config values out of aerc.conf, the UI will function but with 0s delays. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev>
-rw-r--r--config/config.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/config/config.go b/config/config.go
index 64106329..941a7261 100644
--- a/config/config.go
+++ b/config/config.go
@@ -467,6 +467,25 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
if err := validateBorderChars(ui, &config.Ui); err != nil {
return err
}
+ // Values with type=time.Duration must be explicitly set. If these
+ // values are given a default in the struct passed to ui.MapTo, which
+ // they are, a zero-value in the config won't overwrite the default.
+ for key, val := range ui.KeysHash() {
+ switch key {
+ case "dirlist-delay":
+ dur, err := time.ParseDuration(val)
+ if err != nil {
+ return err
+ }
+ config.Ui.DirListDelay = dur
+ case "completion-delay":
+ dur, err := time.ParseDuration(val)
+ if err != nil {
+ return err
+ }
+ config.Ui.CompletionDelay = dur
+ }
+ }
}
for _, sectionName := range file.SectionStrings() {