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
109 lines (93 loc) · 2.54 KB
/
main.go
File metadata and controls
109 lines (93 loc) · 2.54 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
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
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. Basic Block
b1 := widgets.NewParagraph()
b1.Text = "Basic Block\n(Default Style)"
b1.SetRect(0, 0, 25, 5)
// 2. Title Styling
b2 := widgets.NewParagraph()
b2.Text = "Styled Block\n(Red Border, Yellow Title)"
b2.SetRect(26, 0, 51, 5)
b2.Title = "Custom Style"
b2.TitleStyle = ui.NewStyle(ui.ColorYellow)
b2.BorderStyle = ui.NewStyle(ui.ColorRed)
// 3. Title Alignments
b3 := widgets.NewParagraph()
b3.Text = "Left Aligned Title"
b3.SetRect(0, 6, 25, 11)
b3.Title = "Left"
b3.TitleAlignment = ui.AlignLeft
b4 := widgets.NewParagraph()
b4.Text = "Center Aligned Title"
b4.SetRect(26, 6, 51, 11)
b4.Title = "Center"
b4.TitleAlignment = ui.AlignCenter
b5 := widgets.NewParagraph()
b5.Text = "Right Aligned Title"
b5.SetRect(52, 6, 77, 11)
b5.Title = "Right"
b5.TitleAlignment = ui.AlignRight
// 4. Bottom Titles
b6 := widgets.NewParagraph()
b6.Text = "Bottom Title (Center)"
b6.SetRect(0, 12, 25, 17)
b6.TitleBottom = "Bottom Info"
b6.TitleBottomAlignment = ui.AlignCenter
b7 := widgets.NewParagraph()
b7.Text = "Top & Bottom Titles"
b7.SetRect(26, 12, 51, 17)
b7.Title = "Top"
b7.TitleAlignment = ui.AlignLeft
b7.TitleBottom = "Bottom"
b7.TitleBottomAlignment = ui.AlignRight
// 5. Padding
b8 := widgets.NewParagraph()
b8.Text = "Rounded Block\n(2px Padding)"
b8.SetRect(52, 12, 77, 17)
b8.BorderRounded = true
b8.PaddingLeft = 2
b8.PaddingTop = 1
b8.PaddingRight = 2
b8.PaddingBottom = 1
// 6. Asymmetric Padding
b9 := widgets.NewParagraph()
b9.Text = "Left: 10, Top: 2"
b9.SetRect(0, 18, 25, 23) // Adjusted position
b9.PaddingLeft = 10
b9.PaddingTop = 2
// 7. Thick Padding
b10 := widgets.NewParagraph()
b10.Text = "Thick Padding\n(4 all sides)"
b10.SetRect(26, 18, 51, 23) // Adjusted position
b10.PaddingLeft = 4
b10.PaddingTop = 4
b10.PaddingRight = 4
b10.PaddingBottom = 4
// Instructions
info := widgets.NewParagraph()
info.Text = "Press q to quit"
// 8. Background Color
b11 := widgets.NewParagraph()
b11.Text = "Blue Background\n(White Text)"
b11.SetRect(0, 22, 25, 27)
b11.BackgroundColor = ui.ColorBlue
b11.TextStyle = ui.NewStyle(ui.ColorWhite, ui.ColorBlue) // Text needs matching bg usually
ui.Render(b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, info)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
}
}
}