-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.go
77 lines (62 loc) · 1.23 KB
/
main.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
package main
import (
"fmt"
"os"
"github.com/jroimartin/gocui"
)
var (
version = "devel"
commit = ""
)
func main() {
var err error
defer func() {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}()
oState := State{
ActionIndex: -1,
HideHelp: len(os.Args) > 1,
}
// load config from claws.json
if oState.Settings, err = LoadSettings(); err != nil {
return
}
// cmdline configuration + help
// merge cmdline flags into settings
if err = oState.Settings.ParseFlags(); err != nil {
return
}
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
return
}
defer g.Close()
oState.ExecuteFunc = g.Update
fnLayout := NewLayoutFunc(&oState)
g.SetManagerFunc(fnLayout)
g.Cursor = true
g.InputEsc = true
if err = g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return
}
fnClearBuf := func(*gocui.Gui, *gocui.View) error {
v := oState.Writer.(*gocui.View)
v.Clear()
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
return nil
}
if err = g.SetKeybinding("", gocui.KeyCtrlL, gocui.ModNone, fnClearBuf); err != nil {
return
}
err = g.MainLoop()
if err == gocui.ErrQuit {
err = nil
}
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}