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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
let NameVal = λ(T : Type) → { name : Text, value : T }
in λ ( imports
: { -- Take an aerc filter from the aerc distribution /share directory
aercFilter : Text → Text
, -- given a dsl of functions to create an Ini, render the ini file
toIni :
{ globalSection : List (NameVal Text)
, sections : List (NameVal (List (NameVal Text)))
} →
Text
}
) →
let List/map
: ∀(a : Type) → ∀(b : Type) → (a → b) → List a → List b
= λ(a : Type) →
λ(b : Type) →
λ(f : a → b) →
λ(xs : List a) →
List/build
b
( λ(list : Type) →
λ(cons : b → list → list) →
List/fold a xs list (λ(x : a) → cons (f x))
)
in { accounts =
imports.toIni
{ globalSection = [] : List (NameVal Text)
, sections =
[ { name = "mail"
, value =
[ { name = "archive", value = "Archive" }
, { name = "copy-to", value = "Sent" }
, { name = "default", value = "INBOX" }
, { name = "from"
, value = "Profpatsch <mail@profpatsch.de>"
}
, { name = "source", value = "maildir://~/.Mail/mail" }
, { name = "postpone", value = "Drafts" }
]
}
]
}
, aerc =
imports.toIni
{ globalSection = [] : List (NameVal Text)
, sections =
[ { name = "filters"
, value =
[ { name = "text/html"
, value = imports.aercFilter "html"
}
, let _ = "-- TODO: this awk should be taken from nix!"
in { name = "text/*"
, value = "awk -f ${imports.aercFilter "plaintext"}"
}
]
}
]
}
, binds =
let
-- keybinding and command to run
Key =
{ ctrl : Bool, key : Text, cmd : Text }
in let
-- render a key to config format
renderKey =
λ(k : Key) →
if k.ctrl
then { name = "<C-${k.key}>", value = k.cmd }
else { name = k.key, value = k.cmd }
let
-- render a list of keys to config format
renderKeys =
λ(keys : List Key) →
List/map Key (NameVal Text) renderKey keys
let
-- create a section whith a name and a list of keys
sect =
λ(section : Text) →
λ(keys : List Key) →
{ name = section, value = renderKeys keys }
let
-- set key without modifiers
key =
λ(key : Text) → { key }
let
-- set special key without modifiers
special =
λ(key : Text) → { key = "<${key}>" }
let
-- no modifier
none =
{ ctrl = False }
let
-- set control key
ctrl =
{ ctrl = True }
let
-- set a command to execute
cmd =
λ(cmd : Text) → { cmd = ":${cmd}<Enter>" }
let
-- set a command, but stay on the prompt
prompt =
λ(cmd : Text) → { cmd = ":${cmd}<Space>" }
let config =
{ globalSection =
renderKeys
[ ctrl ∧ key "p" ∧ cmd "prev-tab"
, ctrl ∧ key "n" ∧ cmd "next-tab"
, ctrl ∧ key "t" ∧ cmd "term"
]
, sections =
[ sect
"messages"
[ ctrl ∧ key "q" ∧ cmd "quit"
, none ∧ special "Up" ∧ cmd "prev"
, none ∧ special "Down" ∧ cmd "next"
, none ∧ special "PgUp" ∧ cmd "prev 100%"
, none ∧ special "PgDn" ∧ cmd "next 100%"
, none ∧ key "g" ∧ cmd "select 0"
, none ∧ key "G" ∧ cmd "select -1"
, ctrl ∧ key "Up" ∧ cmd "prev-folder"
, ctrl ∧ key "Down" ∧ cmd "next-folder"
, none ∧ key "v" ∧ cmd "mark -t"
, none ∧ key "V" ∧ cmd "mark -v"
, none ∧ special "Enter" ∧ cmd "view"
, none ∧ key "c" ∧ cmd "compose"
, none ∧ key "|" ∧ prompt "pipe"
, none ∧ key "t" ∧ prompt "term"
, none ∧ key "/" ∧ prompt "search"
, none ∧ key "n" ∧ cmd "next-result"
, none ∧ key "N" ∧ cmd "prev-result"
, none ∧ special "Esc" ∧ cmd "clear"
]
, sect "view" [ none ∧ key "q" ∧ cmd "close" ]
]
}
in imports.toIni config
}
|