-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (62 loc) · 1.85 KB
/
Copy pathmain.go
File metadata and controls
74 lines (62 loc) · 1.85 KB
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
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"signls/core/field"
"signls/filesystem"
"signls/midi"
"signls/ui"
tea "charm.land/bubbletea/v2"
)
// version is set at build time via -ldflags "-X main.version=...". It defaults
// to "dev" for local builds.
var version = "dev"
func main() {
configFile := flag.String("config", "", "config file to load or create (default: <user config dir>/signls/config.json)")
bankFile := flag.String("bank", "", "bank file to store grids (default: <user config dir>/signls/default.json)")
keyboard := flag.String("keyboard", "", fmt.Sprintf("keyboard layout (%s)", strings.Join(filesystem.KeyboardNames(), ", ")))
theme := flag.String("theme", "", fmt.Sprintf("color theme to set (%s)", strings.Join(filesystem.ThemeNames(), ", ")))
showVersion := flag.Bool("version", false, "print current version")
debug := flag.Bool("debug", false, "enable debug mode")
flag.Parse()
if *showVersion {
fmt.Println(version)
os.Exit(0)
}
// Default config and bank files live in the per-user config directory; an
// explicit -config/-bank path is honored as given.
configPath := *configFile
if configPath == "" {
configPath = filesystem.DefaultPath("config.json")
}
bankPath := *bankFile
if bankPath == "" {
bankPath = filesystem.DefaultPath("default.json")
}
config, err := filesystem.NewConfiguration(configPath, version, *keyboard, *theme)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
midi, err := midi.New()
if err != nil {
log.Fatal(err)
}
defer midi.Close()
if *debug {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
log.Fatal(err)
}
defer f.Close()
}
bank := filesystem.New(bankPath)
grid := field.NewFromBank(bank.Active, bank.ActiveGrid(), midi)
p := tea.NewProgram(ui.New(config, grid, bank))
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}