forked from liamg/darktile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (66 loc) · 1.7 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
package main
import (
"fmt"
"github.com/liamg/aminal/gui"
"github.com/liamg/aminal/platform"
"github.com/liamg/aminal/terminal"
"github.com/riywo/loginshell"
"os"
"runtime"
)
type callback func(terminal *terminal.Terminal, g *gui.GUI)
func init() {
runtime.LockOSThread()
}
func main() {
initialize(nil)
}
func initialize(unitTestfunc callback) {
conf := getConfig()
logger, err := getLogger(conf)
if err != nil {
fmt.Printf("Failed to create logger: %s\n", err)
os.Exit(1)
}
defer logger.Sync()
logger.Infof("Allocating pty...")
pty, err := platform.NewPty(80, 25)
if err != nil {
logger.Fatalf("Failed to allocate pty: %s", err)
}
shellStr := conf.Shell
if shellStr == "" {
loginShell, err := loginshell.Shell()
if err != nil {
logger.Fatalf("Failed to ascertain your shell: %s", err)
}
shellStr = loginShell
}
os.Setenv("TERM", "xterm-256color") // controversial! easier than installing terminfo everywhere, but obviously going to be slightly different to xterm functionality, so we'll see...
os.Setenv("COLORTERM", "truecolor")
guestProcess, err := pty.CreateGuestProcess(shellStr)
if err != nil {
pty.Close()
logger.Fatalf("Failed to start your shell: %s", err)
}
defer guestProcess.Close()
logger.Infof("Creating terminal...")
terminal := terminal.New(pty, logger, conf)
g, err := gui.New(conf, terminal, logger)
if err != nil {
logger.Fatalf("Cannot start: %s", err)
}
if unitTestfunc != nil {
go unitTestfunc(terminal, g)
} else {
go func() {
if err := guestProcess.Wait(); err != nil {
logger.Fatalf("Failed to wait for guest process: %s", err)
}
g.Close()
}()
}
if err := g.Render(); err != nil {
logger.Fatalf("Render error: %s", err)
}
}