forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtypes.go
More file actions
219 lines (198 loc) · 4.38 KB
/
types.go
File metadata and controls
219 lines (198 loc) · 4.38 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package gotui
import (
"image"
"io"
"sync"
"github.com/gdamore/tcell/v3"
"github.com/metaspartan/gotui/v5/drawille"
)
type ttyAdapter struct {
rw io.ReadWriter
width, height int
resizeCh chan<- bool
}
// Drawable represents a widget that can be drawn to the buffer.
type Drawable interface {
GetRect() image.Rectangle
SetRect(int, int, int, int)
Draw(*Buffer)
sync.Locker
}
// EventHandler represents a widget that can handle events.
type EventHandler interface {
HandleEvent(Event) bool
}
// Widget represents a Drawable that also handles events.
type Widget interface {
Drawable
EventHandler
}
// TTYHandle represents a handle to a TTY.
type TTYHandle interface {
io.ReadWriter
}
// InitConfig represents the configuration for initializing the library.
type InitConfig struct {
CustomTTY TTYHandle
Width, Height int
SimulationMode bool
SimulationSize image.Point
}
// EventType represents the type of an event.
type EventType uint
// Event represents an event that occurred.
type Event struct {
Type EventType
ID string
Payload any
}
type Mouse struct {
Drag bool
X int
Y int
}
type Resize struct {
Width int
Height int
}
type Color = tcell.Color
type Modifier = tcell.AttrMask
// Style represents the style of a cell.
type Style struct {
Fg Color
Bg Color
Modifier Modifier
}
// Gradient represents a color gradient.
type Gradient struct {
Enabled bool
Start Color
End Color
Stops []Color
Direction int
}
// Cell represents a single cell in the terminal.
type Cell struct {
Rune rune
Style Style
}
// Buffer represents a buffer of cells.
type Buffer struct {
image.Rectangle
Cells []Cell
}
// Alignment represents the alignment of text.
type Alignment uint
// gridItemType represents the type of a grid item.
type gridItemType uint
// Grid allows you to lay out widgets in a grid.
type Grid struct {
Block
Items []*GridItem
}
// GridItem represents an item in the grid.
type GridItem struct {
Type gridItemType
XRatio float64
YRatio float64
WidthRatio float64
HeightRatio float64
Entry any
IsLeaf bool
ratio float64
}
// Block is the base struct for all widgets.
type Block struct {
Border bool
BorderStyle Style
BackgroundColor Color
FillBorder bool
BorderLeft, BorderRight, BorderTop, BorderBottom bool
BorderCollapse bool
BorderRounded bool
BorderType BorderType
PaddingLeft, PaddingRight, PaddingTop, PaddingBottom int
image.Rectangle
Inner image.Rectangle
Title string
TitleLeft string
TitleRight string
TitleStyle Style
TitleAlignment Alignment
TitleBottom string
TitleBottomLeft string
TitleBottomRight string
TitleBottomStyle Style
TitleBottomAlignment Alignment
BorderGradient Gradient
BorderSet *BorderSet
sync.Mutex
}
// Canvas is a widget that allows drawing points and lines using braille characters.
type Canvas struct {
Block
drawille.Canvas
}
type RootTheme struct {
Default Style
Block BlockTheme
BarChart BarChartTheme
Gauge GaugeTheme
Plot PlotTheme
List ListTheme
Tree TreeTheme
Paragraph ParagraphTheme
PieChart PieChartTheme
Sparkline SparklineTheme
StackedBarChart StackedBarChartTheme
Tab TabTheme
Table TableTheme
}
type BlockTheme struct {
Title Style
Border Style
}
type BarChartTheme struct {
Bars []Color
Nums []Style
Labels []Style
}
type GaugeTheme struct {
Bar Color
Label Style
}
type PlotTheme struct {
Lines []Color
Axes Color
}
type ListTheme struct {
Text Style
}
type TreeTheme struct {
Text Style
Collapsed rune
Expanded rune
}
type ParagraphTheme struct {
Text Style
}
type PieChartTheme struct {
Slices []Color
}
type SparklineTheme struct {
Title Style
Line Color
}
type StackedBarChartTheme struct {
Bars []Color
Nums []Style
Labels []Style
}
type TabTheme struct {
Active Style
Inactive Style
}
// TableTheme represents the theme for a table.
type TableTheme struct {
Text Style
}