forked from BurntSushi/wingo
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen.go
107 lines (98 loc) · 3.13 KB
/
gen.go
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
// +build ignore
// This program generates datafiles.go
package main
import (
"io/ioutil"
"log"
"os"
"text/template"
"time"
)
func DataFile(n string) []byte {
d, err := ioutil.ReadFile(n)
die(err)
return d
}
func main() {
f, err := os.Create("misc/datafiles.go")
die(err)
defer f.Close()
packageTemplate.Execute(f, struct {
Timestamp time.Time
DejavusansTTF []byte
WingoWav []byte
WingoPng []byte
ClosePng []byte
MinimizePng []byte
MaximizePng []byte
Hooks []byte
Key []byte
Mouse []byte
Options []byte
Theme []byte
}{
Timestamp: time.Now(),
DejavusansTTF: DataFile("data/DejaVuSans.ttf"),
WingoWav: DataFile("data/wingo.wav"),
WingoPng: DataFile("data/wingo.png"),
ClosePng: DataFile("data/close.png"),
MinimizePng: DataFile("data/minimize.png"),
MaximizePng: DataFile("data/maximize.png"),
Hooks: DataFile("config/hooks.wini"),
Key: DataFile("config/key.wini"),
Mouse: DataFile("config/mouse.wini"),
Options: DataFile("config/options.wini"),
Theme: DataFile("config/theme.wini"),
})
}
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
// These are data files built in to wingo.
// {{ .Timestamp }}
//
package misc
var (
DejavusansTTF = []byte( {{with $x := .DejavusansTTF}}{{printf "%q" $x}}{{end}})
WingoWav = []byte( {{with $x := .WingoWav}}{{printf "%q" $x}}{{end}})
WingoPng = []byte( {{with $x := .WingoPng}}{{printf "%q" $x}}{{end}})
ClosePng = []byte( {{with $x := .ClosePng}}{{printf "%q" $x}}{{end}})
MinimizePng = []byte( {{with $x := .MinimizePng}}{{printf "%q" $x}}{{end}})
MaximizePng = []byte( {{with $x := .MaximizePng}}{{printf "%q" $x}}{{end}})
// there are no globals that reference these, yet.
hooks = []byte( {{with $x := .Hooks}}{{printf "%q" $x}}{{end}})
key = []byte( {{with $x := .Key}}{{printf "%q" $x}}{{end}})
mouse = []byte( {{with $x := .Mouse}}{{printf "%q" $x}}{{end}})
options = []byte( {{with $x := .Options}}{{printf "%q" $x}}{{end}})
theme = []byte( {{with $x := .Theme}}{{printf "%q" $x}}{{end}})
// doubling the names up requires minimal code
// kludgery.
FileMap = map[string][]byte {
"DejaVuSans.ttf": DejavusansTTF,
"wingo.wav": WingoWav,
"data/wingo.png": WingoPng,
"data/close.png": ClosePng,
"data/minimize.png": MinimizePng,
"data/maximize.png": MaximizePng,
"hooks.wini":hooks,
"key.wini":key,
"mouse.wini":mouse,
"options.wini":options,
"theme.wini":theme,
// This is not great, but wingo got just a little too Klever
// for its own good, and until we can unwind some of the nonsense
// we do this ugly hack.
// We ought to be able to name just the base and have it find it.
// That's the whole point of search paths. wingo combined a fully
// qualified path with a search path, which is ... odd.
"/etc/xdg/wingo/hooks.wini":hooks,
"/etc/xdg/wingo/key.wini":key,
"/etc/xdg/wingo/mouse.wini":mouse,
"/etc/xdg/wingo/options.wini":options,
"/etc/xdg/wingo/theme.wini":theme,
}
)
`))