-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
114 lines (95 loc) · 2.54 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"fmt"
"strconv"
"github.com/nowakf/undefined_behaviour/events/world"
"github.com/nowakf/pixel"
"github.com/nowakf/pixel/pixelgl"
"github.com/nowakf/tview"
)
var app *tview.Application
func run() {
//--------------------------------------------------------------//
// CONFIGURATION //
//--------------------------------------------------------------//
windowConfig := pixelgl.WindowConfig{
Resizable: true,
Bounds: pixel.R(0, 0, 824, 1024),
//Monitor: pixelgl.PrimaryMonitor(),
}
var err error
println(world.HOME.Place().Name())
app, err = tview.NewApplication(
&tview.Config{
FontSize: 12,
FontPath: "./assets/fonts/DejaVuSansMono.ttf",
AdjustX: -2,
AdjustY: -2,
DPI: 72,
WindowConfig: windowConfig,
})
//--------------------------------------------------------------//
// //
//--------------------------------------------------------------//
if err != nil {
panic(err)
}
//generate the player here
//these are the major modes of the program
majorModes := []MajorMode{
Book(),
News(),
Email(),
Graph(),
}
//the bottom has some global info
info := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true).
SetWrap(false)
currentMode := 0
info.Highlight(strconv.Itoa(currentMode))
pages := tview.NewPages()
previousMode := func() {
currentMode = (currentMode - 1 + len(majorModes)) % len(majorModes)
//wraps around
info.Highlight(strconv.Itoa(currentMode))
pages.SwitchToPage(strconv.Itoa(currentMode))
}
nextMode := func() {
currentMode = (currentMode + 1) % len(majorModes)
info.Highlight(strconv.Itoa(currentMode))
pages.SwitchToPage(strconv.Itoa(currentMode))
}
for index, mode := range majorModes {
title, primitive := mode.UI(nextMode)
pages.AddPage(strconv.Itoa(index),
primitive, true, index == currentMode)
fmt.Fprintf(info, `["%d"][lightgrey] %s [""] [""]`, index, title)
//print the title on the info?
}
//create the main layout
layout := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(pages, 0, 1, true).
AddItem(info, 1, 1, false)
app.SetInputCapture(func(event *pixelgl.KeyEv) *pixelgl.KeyEv {
if event.Key == pixelgl.KeyTab && event.M == pixelgl.ModShift {
previousMode()
} else if event.Key == pixelgl.KeyTab {
nextMode()
}
return event
})
if err := app.SetRoot(layout, true).Run(); err != nil {
panic(err)
}
}
func main() {
pixelgl.Run(run)
}
type MajorMode interface {
UI(nextMode func()) (title string, content tview.Primitive)
Count() int
Update()
}