-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (57 loc) · 1.12 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
package main
import (
"bytes"
"context"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/glasware/glas-core"
"github.com/spf13/afero"
)
type (
surface struct {
m model
buf *bytes.Buffer
in chan string
glas glas.Glas
prog *tea.Program
errCh chan error
}
)
func main() {
if err := start(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
func start() error {
s := surface{
buf: new(bytes.Buffer),
in: make(chan string),
errCh: make(chan error, 1),
}
s.m = initialModel(&s)
var err error
s.glas, err = glas.New(s.in, pipe{&s}, "./cfg", glas.OptAfs(afero.NewOsFs())) // FIXME: this path should come from env or flags.
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
if err := s.glas.Start(ctx); err != nil {
s.errCh <- fmt.Errorf("m.glas.Start -- %w", err)
}
}()
s.prog = tea.NewProgram(s.m)
go func() {
if err := s.prog.Start(); err != nil {
s.errCh <- fmt.Errorf("p.Start -- %w", err)
}
close(s.errCh)
}()
if err := <-s.errCh; err != nil {
return err
}
return nil
}