forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (45 loc) · 1.05 KB
/
main.go
File metadata and controls
54 lines (45 loc) · 1.05 KB
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
package main
import (
"log"
"strconv"
"github.com/metaspartan/gotui/v5"
"github.com/metaspartan/gotui/v5/widgets"
)
// MainWidget acts as a container or main logic handler.
type MainWidget struct {
*widgets.Paragraph
clickCount int
}
func NewMainWidget() *MainWidget {
p := &MainWidget{
Paragraph: widgets.NewParagraph(),
}
p.Title = "Application Example"
p.Text = "Press <Space> to change text.\nClick to increment counter.\nPress <C-c> to quit."
return p
}
func (p *MainWidget) HandleEvent(e gotui.Event) bool {
if e.Type == gotui.KeyboardEvent {
switch e.ID {
case "<Space>", " ":
p.Text = "Space Pressed! (Event Handled)"
return true
}
} else if e.Type == gotui.MouseEvent {
if e.ID == "<MouseLeft>" {
p.clickCount++
p.Text = "Clicked " + strconv.Itoa(p.clickCount) + " times!"
return true
}
}
return false
}
func main() {
app := gotui.NewApp()
w := NewMainWidget()
// Size will be set by Run() after initialization
app.SetRoot(w, true)
if err := app.Run(); err != nil {
log.Fatalf("App run failed: %v", err)
}
}