aboutsummaryrefslogtreecommitdiffstats
path: root/config/viewer.go
blob: 3f7c6934db8003572f378ae7ecd0335f84c3a663 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package config

import (
	"strings"

	"git.sr.ht/~rjarry/aerc/log"
	"github.com/go-ini/ini"
)

type ViewerConfig struct {
	Pager          string
	Alternatives   []string
	ShowHeaders    bool       `ini:"show-headers"`
	AlwaysShowMime bool       `ini:"always-show-mime"`
	ParseHttpLinks bool       `ini:"parse-http-links"`
	HeaderLayout   [][]string `ini:"-"`
	KeyPassthrough bool       `ini:"-"`
	CloseOnReply   bool       `ini:"close-on-reply"`
}

func defaultViewerConfig() ViewerConfig {
	return ViewerConfig{
		Pager:        "less -R",
		Alternatives: []string{"text/plain", "text/html"},
		ShowHeaders:  false,
		HeaderLayout: [][]string{
			{"From", "To"},
			{"Cc", "Bcc"},
			{"Date"},
			{"Subject"},
		},
		ParseHttpLinks: true,
		CloseOnReply:   false,
	}
}

func (config *AercConfig) parseViewer(file *ini.File) error {
	viewer, err := file.GetSection("viewer")
	if err != nil {
		goto out
	}
	if err := viewer.MapTo(&config.Viewer); err != nil {
		return err
	}
	for key, val := range viewer.KeysHash() {
		switch key {
		case "alternatives":
			config.Viewer.Alternatives = strings.Split(val, ",")
		case "header-layout":
			config.Viewer.HeaderLayout = parseLayout(val)
		}
	}
out:
	log.Debugf("aerc.conf: [viewer] %#v", config.Viewer)
	return nil
}