about summary refs log tree commit diff stats
path: root/config/config.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-01-24 18:18:49 +0100
committerDrew DeVault <sir@cmpwn.com>2020-01-24 12:25:59 -0500
commite78b7b85e4792f413175e13ef2fe437839b017a2 (patch)
tree0e050469f2f3d7768d4cc8f39af27a580d03e7b1 /config/config.go
parentdf5d9a3ec7564f0d95e3f92afc0e59588de3c4ce (diff)
downloadaerc-e78b7b85e4792f413175e13ef2fe437839b017a2.tar.gz
config: Strongly type context type
The go compiler can't help much with untyped int constants.
Even though the only valid constants are 0-3 it will happily accept 4 as input.

Let's let the go compiler worry about correctness here. This also allows people
not very familiar with the code to use it properly via auto completion.
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/config/config.go b/config/config.go
index 0b46014..0393e46 100644
--- a/config/config.go
+++ b/config/config.go
@@ -46,14 +46,16 @@ type UIConfig struct {
 	CompletionPopovers  bool          `ini:"completion-popovers"`
 }
 
+type ContextType int
+
 const (
-	UI_CONTEXT_FOLDER = iota
+	UI_CONTEXT_FOLDER ContextType = iota
 	UI_CONTEXT_ACCOUNT
 	UI_CONTEXT_SUBJECT
 )
 
 type UIConfigContext struct {
-	ContextType int
+	ContextType ContextType
 	Regex       *regexp.Regexp
 	UiConfig    UIConfig
 }
@@ -602,7 +604,8 @@ func parseLayout(layout string) [][]string {
 	return l
 }
 
-func (config *AercConfig) mergeContextualUi(baseUi *UIConfig, contextType int, s string) {
+func (config *AercConfig) mergeContextualUi(baseUi *UIConfig,
+	contextType ContextType, s string) {
 	for _, contextualUi := range config.ContextualUis {
 		if contextualUi.ContextType != contextType {
 			continue
@@ -617,7 +620,7 @@ func (config *AercConfig) mergeContextualUi(baseUi *UIConfig, contextType int, s
 	}
 }
 
-func (config *AercConfig) GetUiConfig(params map[int]string) UIConfig {
+func (config *AercConfig) GetUiConfig(params map[ContextType]string) UIConfig {
 	baseUi := config.Ui
 
 	for k, v := range params {
f1684 ^
f3158b3 ^

331b915 ^
89f1684 ^



bbdf9df ^

6473848 ^

56b84d3 ^

89f1684 ^

b0eaf51 ^
974b22c ^
89f1684 ^


072bc26 ^
0c2ede5 ^
b2fa5a1 ^

072bc26 ^
89f1684 ^

56b84d3 ^
89f1684 ^

974b22c ^

89f1684 ^

1170893 ^
89f1684 ^

56b84d3 ^
89f1684 ^



513e8aa ^

89f1684 ^

8d20e92 ^
974b22c ^

072bc26 ^
974b22c ^
974b22c ^
8d20e92 ^
8d20e92 ^
3f452ca ^
855362d ^
b0eaf51 ^

072bc26 ^
f3158b3 ^
974b22c ^
89f1684 ^



b0eaf51 ^
072bc26 ^
f3158b3 ^
84f49e9 ^
89f1684 ^


648ca98 ^
072bc26 ^



b0eaf51 ^
89f1684 ^
89f1684 ^
974b22c ^
89f1684 ^
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106