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
74 lines (61 loc) · 1.86 KB
/
main.go
File metadata and controls
74 lines (61 loc) · 1.86 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"log"
ui "github.com/metaspartan/gotui/v5"
"github.com/metaspartan/gotui/v5/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize gotui: %v", err)
}
defer ui.Close()
// 1. Header (Fixed height 3)
p1 := widgets.NewParagraph()
p1.Title = "Header"
p1.Text = "Fixed Height: 3 rows\nStandard Layout Demo"
p1.Border = true
// 2. Sidebar (Fixed Width 20)
p2 := widgets.NewParagraph()
p2.Title = "Sidebar"
p2.Text = "Fixed Width: 20\n\n- Item 1\n- Item 2\n- Item 3"
p2.Border = true
// 3. Main Content (Proportion 1 aka 100% of rest)
p3 := widgets.NewParagraph()
p3.Title = "Main Content"
p3.Text = "This block takes up all remaining space.\nResize the window to see it adapt!"
p3.Border = true
// 4. Footer (Fixed height 1)
p4 := widgets.NewParagraph()
p4.Text = "Footer: Fixed Height 1"
p4.Border = false
p4.TextStyle.Bg = ui.ColorBlue
// Compose logic:
// Root is Vertical: Header, Middle, Footer
// Middle is Horizontal: Sidebar, Content
middleFlex := widgets.NewFlex()
middleFlex.Direction = widgets.FlexRow // Horizontal layout
middleFlex.AddItem(p2, 20, 0, false) // Fixed 20 width
middleFlex.AddItem(p3, 0, 1, false) // 100% remaining
rootFlex := widgets.NewFlex()
rootFlex.Direction = widgets.FlexColumn // Vertical layout
rootFlex.AddItem(p1, 3, 0, false) // Fixed 3 height
rootFlex.AddItem(middleFlex, 0, 1, false) // 100% remaining height
rootFlex.AddItem(p4, 1, 0, false) // Fixed 1 height
// Set root size to screen
w, h := ui.TerminalDimensions()
rootFlex.SetRect(0, 0, w, h)
ui.Render(rootFlex)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
case "<Resize>":
payload := e.Payload.(ui.Resize)
rootFlex.SetRect(0, 0, payload.Width, payload.Height)
ui.Clear()
ui.Render(rootFlex)
}
}
}