aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/exline.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-12 15:03:30 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:22:58 +0100
commitc05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch)
tree13a3a84eb74fdea77996161f01bec5596f67f39f /widgets/exline.go
parent9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff)
downloadaerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc widget. Everywhere we need to access configuration options, we need somehow to get a reference either to the Aerc widget or to a pointer to the AercConfig instance. This makes the code cluttered. Remove the AercConfig structure and every place where it is referenced. Instead, declare global variables for every configuration section and access them directly from the `config` module. Since bindings and ui sections can be "contextual" (i.e. per account, per folder or per subject), leave most local references intact. Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would make this patch even more unreadable. This is something that may be addressed in the future. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'widgets/exline.go')
-rw-r--r--widgets/exline.go26
1 files changed, 12 insertions, 14 deletions
diff --git a/widgets/exline.go b/widgets/exline.go
index 5cf4338d..1f2d71e4 100644
--- a/widgets/exline.go
+++ b/widgets/exline.go
@@ -14,19 +14,18 @@ type ExLine struct {
tabcomplete func(cmd string) ([]string, string)
cmdHistory lib.History
input *ui.TextInput
- conf *config.AercConfig
}
-func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), finish func(),
+func NewExLine(cmd string, commit func(cmd string), finish func(),
tabcomplete func(cmd string) ([]string, string),
cmdHistory lib.History,
) *ExLine {
- input := ui.NewTextInput("", &conf.Ui).Prompt(":").Set(cmd)
- if conf.Ui.CompletionPopovers {
+ input := ui.NewTextInput("", config.Ui).Prompt(":").Set(cmd)
+ if config.Ui.CompletionPopovers {
input.TabComplete(
tabcomplete,
- conf.Ui.CompletionDelay,
- conf.Ui.CompletionMinChars,
+ config.Ui.CompletionDelay,
+ config.Ui.CompletionMinChars,
)
}
exline := &ExLine{
@@ -35,7 +34,6 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
tabcomplete: tabcomplete,
cmdHistory: cmdHistory,
input: input,
- conf: conf,
}
return exline
}
@@ -43,20 +41,20 @@ func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), fin
func (x *ExLine) TabComplete(tabComplete func(string) ([]string, string)) {
x.input.TabComplete(
tabComplete,
- x.conf.Ui.CompletionDelay,
- x.conf.Ui.CompletionMinChars,
+ config.Ui.CompletionDelay,
+ config.Ui.CompletionMinChars,
)
}
-func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string),
+func NewPrompt(prompt string, commit func(text string),
tabcomplete func(cmd string) ([]string, string),
) *ExLine {
- input := ui.NewTextInput("", &conf.Ui).Prompt(prompt)
- if conf.Ui.CompletionPopovers {
+ input := ui.NewTextInput("", config.Ui).Prompt(prompt)
+ if config.Ui.CompletionPopovers {
input.TabComplete(
tabcomplete,
- conf.Ui.CompletionDelay,
- conf.Ui.CompletionMinChars,
+ config.Ui.CompletionDelay,
+ config.Ui.CompletionMinChars,
)
}
exline := &ExLine{