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
|
package main
import (
"fmt"
tui "github.com/grindlemire/go-tui"
)
type statusApp struct {
value *tui.State[int]
}
func StatusApp() *statusApp {
return &statusApp{
value: tui.NewState(0),
}
}
func (s *statusApp) KeyMap() tui.KeyMap {
return tui.KeyMap{
tui.On(tui.KeyEscape, func(ke tui.KeyEvent) { ke.App().Stop() }),
tui.On(tui.Rune('+'), func(ke tui.KeyEvent) {
s.value.Update(func(v int) int { return v + 1 })
}),
tui.On(tui.Rune('-'), func(ke tui.KeyEvent) {
s.value.Update(func(v int) int { return v - 1 })
}),
}
}
func valueStyle(v int) tui.Style {
if v > 0 {
return tui.NewStyle().Bold().Foreground(tui.Green)
}
if v < 0 {
return tui.NewStyle().Bold().Foreground(tui.Red)
}
return tui.NewStyle().Dim()
}
templ (s *statusApp) Render() {
<div class="flex-col items-center justify-center h-full gap-1">
<span textStyle={valueStyle(s.value.Get())}>{fmt.Sprintf("Value: %d", s.value.Get())}</span>
<span class="font-dim">Press + / - to change, Esc to quit</span>
</div>
}
|