-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (73 loc) · 1.47 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
78
79
80
81
82
83
84
package main
import (
"errors"
"fmt"
"github.com/gdamore/tcell/v2"
"log"
"os"
"os/signal"
"sync"
"syscall"
)
const homePath = "/.lil"
func main() {
screen, err := initScreen()
if err != nil {
panic("Can't create view: " + err.Error())
}
var once sync.Once
gracefulClose := func() {
once.Do(func() {
screen.Fini()
})
}
go func() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, os.Kill, syscall.SIGTERM)
<-sigChan
gracefulClose()
os.Exit(0)
}()
defer func() {
if err != nil {
if errors.Is(err, Quit) {
return
}
log.Println("Exit with error: " + err.Error())
os.Exit(1)
}
}()
defer gracefulClose()
view := NewView(screen)
input := NewKeyboardInput(screen)
for {
var userHome string
userHome, err = os.UserHomeDir()
if err != nil {
return
}
clientListController := NewClientListController(input, view, userHome+homePath)
var client Client
client, err = clientListController.Run()
if err != nil {
return
}
controller := NewController(input, view, client)
err = controller.Run()
if err != nil {
return
}
}
}
func initScreen() (tcell.Screen, error) {
tcell.SetEncodingFallback(tcell.EncodingFallbackASCII)
screen, err := tcell.NewScreen()
if err != nil {
return nil, fmt.Errorf("can't create presenter screen: %w", err)
}
if err = screen.Init(); err != nil {
return nil, fmt.Errorf("can't create presenter screen: %w", err)
}
screen.Clear()
return screen, nil
}