summaryrefslogtreecommitdiff
path: root/client/main.go
blob: 5b88117c0ecc52c8074c12bc9a27069222e29993 (plain)
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
package main

import (
	"citrons.xyz/talk/tui"
	"time"
	"fmt"
	"os"
)

var globalApp *application

func main() {
	err := tui.Start()
	if err != nil {
		fmt.Fprintln(os.Stderr, "error initializing terminal: ", err)
		os.Exit(-1)
	}
	defer func() {
		tui.End()
		fmt.Println("bye!")
	}()

	globalApp = newApplication("alt.mondecitronne.com:27508")
	go globalApp.RunClient()
	defer globalApp.Stop()

	drawTick := time.Tick(time.Second / 60)
	redraw := true
	for {
		select {
		case m := <-globalApp.Messages():
			m.Handle(globalApp)
			redraw = true
		case e := <-tui.Events():
			globalApp.onInput(e)
			redraw = true
		case <-drawTick:
			if redraw {
				globalApp.show()
				redraw = false
			}
		}
		if globalApp.quit == true {
			return
		}
	}
}