aboutsummaryrefslogtreecommitdiffstats
path: root/lib/statusline/renderer.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 /lib/statusline/renderer.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 'lib/statusline/renderer.go')
-rw-r--r--lib/statusline/renderer.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/statusline/renderer.go b/lib/statusline/renderer.go
index f128e6a2..993cfcc5 100644
--- a/lib/statusline/renderer.go
+++ b/lib/statusline/renderer.go
@@ -7,6 +7,7 @@ import (
"strings"
"unicode"
+ "git.sr.ht/~rjarry/aerc/config"
"github.com/mattn/go-runewidth"
)
@@ -19,24 +20,25 @@ type renderParams struct {
type renderFunc func(r renderParams) string
-func newRenderer(renderFormat, textMode string) renderFunc {
+func newRenderer() renderFunc {
var texter Texter
- switch strings.ToLower(textMode) {
+ switch strings.ToLower(config.Statusline.DisplayMode) {
case "icon":
texter = &icon{}
default:
texter = &text{}
}
- return renderer(texter, renderFormat)
+ return renderer(texter)
}
-func renderer(texter Texter, renderFormat string) renderFunc {
+func renderer(texter Texter) renderFunc {
var leftFmt, rightFmt string
- if idx := strings.Index(renderFormat, "%>"); idx < 0 {
- leftFmt = renderFormat
+ if idx := strings.Index(config.Statusline.RenderFormat, "%>"); idx < 0 {
+ leftFmt = config.Statusline.RenderFormat
} else {
- leftFmt, rightFmt = renderFormat[:idx], strings.Replace(renderFormat[idx:], "%>", "", 1)
+ leftFmt = config.Statusline.RenderFormat[:idx]
+ rightFmt = strings.Replace(config.Statusline.RenderFormat[idx:], "%>", "", 1)
}
return func(r renderParams) string {