Debian Codegraph @

config/compose.go

raw
1 package config
2
3 import (
4 "regexp"
5 "sync/atomic"
6
7 "git.sr.ht/~rjarry/aerc/lib/log"
8 "github.com/go-ini/ini"
9 )
10
11 type ComposeConfig struct {
12 Editor string `ini:"editor"`
13 HeaderLayout [][]string `ini:"header-layout" parse:"ParseLayout" default:"To|From,Subject"`
14 AddressBookCmd string `ini:"address-book-cmd"`
15 ReplyToSelf bool `ini:"reply-to-self" default:"true"`
16 NoAttachmentWarning *regexp.Regexp `ini:"no-attachment-warning" parse:"ParseNoAttachmentWarning"`
17 EmptySubjectWarning bool `ini:"empty-subject-warning"`
18 FilePickerCmd string `ini:"file-picker-cmd"`
19 FormatFlowed bool `ini:"format-flowed"`
20 EditHeaders bool `ini:"edit-headers"`
21 FocusBody bool `ini:"focus-body"`
22 LFEditor bool `ini:"lf-editor"`
23 }
24
25 var composeConfig atomic.Pointer[ComposeConfig]
26
27 func Compose() *ComposeConfig {
28 return composeConfig.Load()
29 }
30
31 func parseCompose(file *ini.File) (*ComposeConfig, error) {
32 conf := new(ComposeConfig)
33 if err := MapToStruct(file.Section("compose"), conf, true); err != nil {
34 return nil, err
35 }
36 log.Debugf("aerc.conf: [compose] %#v", conf)
37 return conf, nil
38 }
39
40 func (c *ComposeConfig) ParseLayout(sec *ini.Section, key *ini.Key) ([][]string, error) {
41 layout := parseLayout(key.String())
42 return layout, nil
43 }
44
45 func (c *ComposeConfig) ParseNoAttachmentWarning(sec *ini.Section, key *ini.Key) (*regexp.Regexp, error) {
46 if key.String() == "" {
47 return nil, nil
48 }
49 return regexp.Compile(`(?im)` + key.String())
50 }