-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.go
68 lines (54 loc) · 1.35 KB
/
gui.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
package gui
import (
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"./explorer"
"./help"
"./history"
"./settingsform"
)
var app *tview.Application
var pages *tview.Pages
var activePage string
// Init starts the gui
func Init() {
app = tview.NewApplication()
pages = tview.NewPages()
redraw := func() {
app.Draw()
}
pages.AddPage("explorer", explorer.UI(redraw), true, true)
pages.AddPage("history", history.UI(redraw), true, false)
pages.AddPage("help", help.UI(), true, false)
pages.AddPage("settingsform", settingsform.UI(redraw), true, false)
activePage = "explorer"
explorer.StartExplorer()
history.StartHistory()
app.SetInputCapture(eventHandler)
if err := app.SetRoot(pages, true).SetFocus(pages).Run(); err != nil {
panic(err)
}
}
func switchToPage(page string) {
activePage = page
pages.SwitchToPage(page)
}
func eventHandler(eventKey *tcell.EventKey) *tcell.EventKey {
if eventKey.Rune() == 'q' {
app.Stop()
return nil
}
if activePage == "help" {
return help.HandleEvents(eventKey, switchToPage)
}
if activePage == "history" {
return history.HandleEvents(eventKey, switchToPage, explorer.ReRenderExplorer)
}
if activePage == "explorer" {
return explorer.HandleEvents(eventKey, switchToPage)
}
if activePage == "settingsform" {
return settingsform.HandleEvents(eventKey, switchToPage)
}
return eventKey
}