lipgloss 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +438 -16
- data/ext/lipgloss/extconf.rb +61 -0
- data/ext/lipgloss/extension.c +150 -0
- data/ext/lipgloss/extension.h +76 -0
- data/ext/lipgloss/list.c +147 -0
- data/ext/lipgloss/style.c +398 -0
- data/ext/lipgloss/style_border.c +209 -0
- data/ext/lipgloss/style_spacing.c +97 -0
- data/ext/lipgloss/style_unset.c +151 -0
- data/ext/lipgloss/table.c +242 -0
- data/ext/lipgloss/tree.c +192 -0
- data/go/go.mod +20 -0
- data/go/go.sum +34 -0
- data/go/layout.go +71 -0
- data/go/lipgloss.go +78 -0
- data/go/list.go +118 -0
- data/go/style.go +281 -0
- data/go/style_border.go +197 -0
- data/go/style_spacing.go +94 -0
- data/go/style_unset.go +129 -0
- data/go/table.go +218 -0
- data/go/tree.go +138 -0
- data/lib/lipgloss/border.rb +48 -0
- data/lib/lipgloss/color.rb +97 -0
- data/lib/lipgloss/position.rb +27 -0
- data/lib/lipgloss/table.rb +63 -0
- data/lib/lipgloss/version.rb +2 -1
- data/lib/lipgloss.rb +21 -2
- data/lipgloss.gemspec +34 -0
- metadata +37 -14
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -132
- data/Rakefile +0 -12
- data/sig/lipgloss.rbs +0 -4
data/go/style_border.go
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"unsafe"
|
|
7
|
+
|
|
8
|
+
"github.com/charmbracelet/lipgloss"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
//export lipgloss_style_border
|
|
12
|
+
func lipgloss_style_border(id C.ulonglong, borderType C.int, sides *C.int, sidesCount C.int) C.ulonglong {
|
|
13
|
+
var border lipgloss.Border
|
|
14
|
+
|
|
15
|
+
switch int(borderType) {
|
|
16
|
+
case 0:
|
|
17
|
+
border = lipgloss.NormalBorder()
|
|
18
|
+
case 1:
|
|
19
|
+
border = lipgloss.RoundedBorder()
|
|
20
|
+
case 2:
|
|
21
|
+
border = lipgloss.ThickBorder()
|
|
22
|
+
case 3:
|
|
23
|
+
border = lipgloss.DoubleBorder()
|
|
24
|
+
case 4:
|
|
25
|
+
border = lipgloss.HiddenBorder()
|
|
26
|
+
case 5:
|
|
27
|
+
border = lipgloss.BlockBorder()
|
|
28
|
+
case 6:
|
|
29
|
+
border = lipgloss.OuterHalfBlockBorder()
|
|
30
|
+
case 7:
|
|
31
|
+
border = lipgloss.InnerHalfBlockBorder()
|
|
32
|
+
case 8:
|
|
33
|
+
border = lipgloss.ASCIIBorder()
|
|
34
|
+
default:
|
|
35
|
+
border = lipgloss.NormalBorder()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if sidesCount > 0 {
|
|
39
|
+
goSides := make([]bool, int(sidesCount))
|
|
40
|
+
slice := unsafe.Slice(sides, int(sidesCount))
|
|
41
|
+
|
|
42
|
+
for index, value := range slice {
|
|
43
|
+
goSides[index] = value != 0
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
style := getStyle(uint64(id)).Border(border, goSides...)
|
|
47
|
+
|
|
48
|
+
return C.ulonglong(allocStyle(style))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
style := getStyle(uint64(id)).Border(border)
|
|
52
|
+
|
|
53
|
+
return C.ulonglong(allocStyle(style))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//export lipgloss_style_border_style
|
|
57
|
+
func lipgloss_style_border_style(id C.ulonglong, borderType C.int) C.ulonglong {
|
|
58
|
+
var border lipgloss.Border
|
|
59
|
+
|
|
60
|
+
switch int(borderType) {
|
|
61
|
+
case 0:
|
|
62
|
+
border = lipgloss.NormalBorder()
|
|
63
|
+
case 1:
|
|
64
|
+
border = lipgloss.RoundedBorder()
|
|
65
|
+
case 2:
|
|
66
|
+
border = lipgloss.ThickBorder()
|
|
67
|
+
case 3:
|
|
68
|
+
border = lipgloss.DoubleBorder()
|
|
69
|
+
case 4:
|
|
70
|
+
border = lipgloss.HiddenBorder()
|
|
71
|
+
case 5:
|
|
72
|
+
border = lipgloss.BlockBorder()
|
|
73
|
+
case 6:
|
|
74
|
+
border = lipgloss.OuterHalfBlockBorder()
|
|
75
|
+
case 7:
|
|
76
|
+
border = lipgloss.InnerHalfBlockBorder()
|
|
77
|
+
case 8:
|
|
78
|
+
border = lipgloss.ASCIIBorder()
|
|
79
|
+
default:
|
|
80
|
+
border = lipgloss.NormalBorder()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
style := getStyle(uint64(id)).BorderStyle(border)
|
|
84
|
+
|
|
85
|
+
return C.ulonglong(allocStyle(style))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//export lipgloss_style_border_custom
|
|
89
|
+
func lipgloss_style_border_custom(id C.ulonglong, top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight, middleLeft, middleRight, middle, middleTop, middleBottom *C.char) C.ulonglong {
|
|
90
|
+
border := lipgloss.Border{
|
|
91
|
+
Top: C.GoString(top),
|
|
92
|
+
Bottom: C.GoString(bottom),
|
|
93
|
+
Left: C.GoString(left),
|
|
94
|
+
Right: C.GoString(right),
|
|
95
|
+
TopLeft: C.GoString(topLeft),
|
|
96
|
+
TopRight: C.GoString(topRight),
|
|
97
|
+
BottomLeft: C.GoString(bottomLeft),
|
|
98
|
+
BottomRight: C.GoString(bottomRight),
|
|
99
|
+
MiddleLeft: C.GoString(middleLeft),
|
|
100
|
+
MiddleRight: C.GoString(middleRight),
|
|
101
|
+
Middle: C.GoString(middle),
|
|
102
|
+
MiddleTop: C.GoString(middleTop),
|
|
103
|
+
MiddleBottom: C.GoString(middleBottom),
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
style := getStyle(uint64(id)).Border(border)
|
|
107
|
+
|
|
108
|
+
return C.ulonglong(allocStyle(style))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//export lipgloss_style_border_foreground
|
|
112
|
+
func lipgloss_style_border_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
113
|
+
style := getStyle(uint64(id)).BorderForeground(lipgloss.Color(C.GoString(color)))
|
|
114
|
+
return C.ulonglong(allocStyle(style))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//export lipgloss_style_border_background
|
|
118
|
+
func lipgloss_style_border_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
119
|
+
style := getStyle(uint64(id)).BorderBackground(lipgloss.Color(C.GoString(color)))
|
|
120
|
+
return C.ulonglong(allocStyle(style))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//export lipgloss_style_border_top
|
|
124
|
+
func lipgloss_style_border_top(id C.ulonglong, value C.int) C.ulonglong {
|
|
125
|
+
style := getStyle(uint64(id)).BorderTop(value != 0)
|
|
126
|
+
return C.ulonglong(allocStyle(style))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//export lipgloss_style_border_right
|
|
130
|
+
func lipgloss_style_border_right(id C.ulonglong, value C.int) C.ulonglong {
|
|
131
|
+
style := getStyle(uint64(id)).BorderRight(value != 0)
|
|
132
|
+
return C.ulonglong(allocStyle(style))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//export lipgloss_style_border_bottom
|
|
136
|
+
func lipgloss_style_border_bottom(id C.ulonglong, value C.int) C.ulonglong {
|
|
137
|
+
style := getStyle(uint64(id)).BorderBottom(value != 0)
|
|
138
|
+
return C.ulonglong(allocStyle(style))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//export lipgloss_style_border_left
|
|
142
|
+
func lipgloss_style_border_left(id C.ulonglong, value C.int) C.ulonglong {
|
|
143
|
+
style := getStyle(uint64(id)).BorderLeft(value != 0)
|
|
144
|
+
return C.ulonglong(allocStyle(style))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Per-side border foreground colors
|
|
148
|
+
|
|
149
|
+
//export lipgloss_style_border_top_foreground
|
|
150
|
+
func lipgloss_style_border_top_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
151
|
+
style := getStyle(uint64(id)).BorderTopForeground(lipgloss.Color(C.GoString(color)))
|
|
152
|
+
return C.ulonglong(allocStyle(style))
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//export lipgloss_style_border_right_foreground
|
|
156
|
+
func lipgloss_style_border_right_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
157
|
+
style := getStyle(uint64(id)).BorderRightForeground(lipgloss.Color(C.GoString(color)))
|
|
158
|
+
return C.ulonglong(allocStyle(style))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//export lipgloss_style_border_bottom_foreground
|
|
162
|
+
func lipgloss_style_border_bottom_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
163
|
+
style := getStyle(uint64(id)).BorderBottomForeground(lipgloss.Color(C.GoString(color)))
|
|
164
|
+
return C.ulonglong(allocStyle(style))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
//export lipgloss_style_border_left_foreground
|
|
168
|
+
func lipgloss_style_border_left_foreground(id C.ulonglong, color *C.char) C.ulonglong {
|
|
169
|
+
style := getStyle(uint64(id)).BorderLeftForeground(lipgloss.Color(C.GoString(color)))
|
|
170
|
+
return C.ulonglong(allocStyle(style))
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Per-side border background colors
|
|
174
|
+
|
|
175
|
+
//export lipgloss_style_border_top_background
|
|
176
|
+
func lipgloss_style_border_top_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
177
|
+
style := getStyle(uint64(id)).BorderTopBackground(lipgloss.Color(C.GoString(color)))
|
|
178
|
+
return C.ulonglong(allocStyle(style))
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//export lipgloss_style_border_right_background
|
|
182
|
+
func lipgloss_style_border_right_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
183
|
+
style := getStyle(uint64(id)).BorderRightBackground(lipgloss.Color(C.GoString(color)))
|
|
184
|
+
return C.ulonglong(allocStyle(style))
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
//export lipgloss_style_border_bottom_background
|
|
188
|
+
func lipgloss_style_border_bottom_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
189
|
+
style := getStyle(uint64(id)).BorderBottomBackground(lipgloss.Color(C.GoString(color)))
|
|
190
|
+
return C.ulonglong(allocStyle(style))
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//export lipgloss_style_border_left_background
|
|
194
|
+
func lipgloss_style_border_left_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
195
|
+
style := getStyle(uint64(id)).BorderLeftBackground(lipgloss.Color(C.GoString(color)))
|
|
196
|
+
return C.ulonglong(allocStyle(style))
|
|
197
|
+
}
|
data/go/style_spacing.go
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"github.com/charmbracelet/lipgloss"
|
|
7
|
+
"unsafe"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// Padding methods
|
|
11
|
+
|
|
12
|
+
//export lipgloss_style_padding
|
|
13
|
+
func lipgloss_style_padding(id C.ulonglong, values *C.int, count C.int) C.ulonglong {
|
|
14
|
+
goValues := make([]int, int(count))
|
|
15
|
+
slice := unsafe.Slice(values, int(count))
|
|
16
|
+
|
|
17
|
+
for index, value := range slice {
|
|
18
|
+
goValues[index] = int(value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
style := getStyle(uint64(id)).Padding(goValues...)
|
|
22
|
+
|
|
23
|
+
return C.ulonglong(allocStyle(style))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//export lipgloss_style_padding_top
|
|
27
|
+
func lipgloss_style_padding_top(id C.ulonglong, value C.int) C.ulonglong {
|
|
28
|
+
style := getStyle(uint64(id)).PaddingTop(int(value))
|
|
29
|
+
return C.ulonglong(allocStyle(style))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//export lipgloss_style_padding_right
|
|
33
|
+
func lipgloss_style_padding_right(id C.ulonglong, value C.int) C.ulonglong {
|
|
34
|
+
style := getStyle(uint64(id)).PaddingRight(int(value))
|
|
35
|
+
return C.ulonglong(allocStyle(style))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//export lipgloss_style_padding_bottom
|
|
39
|
+
func lipgloss_style_padding_bottom(id C.ulonglong, value C.int) C.ulonglong {
|
|
40
|
+
style := getStyle(uint64(id)).PaddingBottom(int(value))
|
|
41
|
+
return C.ulonglong(allocStyle(style))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//export lipgloss_style_padding_left
|
|
45
|
+
func lipgloss_style_padding_left(id C.ulonglong, value C.int) C.ulonglong {
|
|
46
|
+
style := getStyle(uint64(id)).PaddingLeft(int(value))
|
|
47
|
+
return C.ulonglong(allocStyle(style))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Margin methods
|
|
51
|
+
|
|
52
|
+
//export lipgloss_style_margin
|
|
53
|
+
func lipgloss_style_margin(id C.ulonglong, values *C.int, count C.int) C.ulonglong {
|
|
54
|
+
goValues := make([]int, int(count))
|
|
55
|
+
slice := unsafe.Slice(values, int(count))
|
|
56
|
+
|
|
57
|
+
for index, value := range slice {
|
|
58
|
+
goValues[index] = int(value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
style := getStyle(uint64(id)).Margin(goValues...)
|
|
62
|
+
|
|
63
|
+
return C.ulonglong(allocStyle(style))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//export lipgloss_style_margin_top
|
|
67
|
+
func lipgloss_style_margin_top(id C.ulonglong, value C.int) C.ulonglong {
|
|
68
|
+
style := getStyle(uint64(id)).MarginTop(int(value))
|
|
69
|
+
return C.ulonglong(allocStyle(style))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//export lipgloss_style_margin_right
|
|
73
|
+
func lipgloss_style_margin_right(id C.ulonglong, value C.int) C.ulonglong {
|
|
74
|
+
style := getStyle(uint64(id)).MarginRight(int(value))
|
|
75
|
+
return C.ulonglong(allocStyle(style))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//export lipgloss_style_margin_bottom
|
|
79
|
+
func lipgloss_style_margin_bottom(id C.ulonglong, value C.int) C.ulonglong {
|
|
80
|
+
style := getStyle(uint64(id)).MarginBottom(int(value))
|
|
81
|
+
return C.ulonglong(allocStyle(style))
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//export lipgloss_style_margin_left
|
|
85
|
+
func lipgloss_style_margin_left(id C.ulonglong, value C.int) C.ulonglong {
|
|
86
|
+
style := getStyle(uint64(id)).MarginLeft(int(value))
|
|
87
|
+
return C.ulonglong(allocStyle(style))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//export lipgloss_style_margin_background
|
|
91
|
+
func lipgloss_style_margin_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
92
|
+
style := getStyle(uint64(id)).MarginBackground(lipgloss.Color(C.GoString(color)))
|
|
93
|
+
return C.ulonglong(allocStyle(style))
|
|
94
|
+
}
|
data/go/style_unset.go
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
//export lipgloss_style_unset_bold
|
|
6
|
+
func lipgloss_style_unset_bold(id C.ulonglong) C.ulonglong {
|
|
7
|
+
style := getStyle(uint64(id)).UnsetBold()
|
|
8
|
+
return C.ulonglong(allocStyle(style))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//export lipgloss_style_unset_italic
|
|
12
|
+
func lipgloss_style_unset_italic(id C.ulonglong) C.ulonglong {
|
|
13
|
+
style := getStyle(uint64(id)).UnsetItalic()
|
|
14
|
+
return C.ulonglong(allocStyle(style))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//export lipgloss_style_unset_underline
|
|
18
|
+
func lipgloss_style_unset_underline(id C.ulonglong) C.ulonglong {
|
|
19
|
+
style := getStyle(uint64(id)).UnsetUnderline()
|
|
20
|
+
return C.ulonglong(allocStyle(style))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//export lipgloss_style_unset_strikethrough
|
|
24
|
+
func lipgloss_style_unset_strikethrough(id C.ulonglong) C.ulonglong {
|
|
25
|
+
style := getStyle(uint64(id)).UnsetStrikethrough()
|
|
26
|
+
return C.ulonglong(allocStyle(style))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//export lipgloss_style_unset_reverse
|
|
30
|
+
func lipgloss_style_unset_reverse(id C.ulonglong) C.ulonglong {
|
|
31
|
+
style := getStyle(uint64(id)).UnsetReverse()
|
|
32
|
+
return C.ulonglong(allocStyle(style))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//export lipgloss_style_unset_blink
|
|
36
|
+
func lipgloss_style_unset_blink(id C.ulonglong) C.ulonglong {
|
|
37
|
+
style := getStyle(uint64(id)).UnsetBlink()
|
|
38
|
+
return C.ulonglong(allocStyle(style))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//export lipgloss_style_unset_faint
|
|
42
|
+
func lipgloss_style_unset_faint(id C.ulonglong) C.ulonglong {
|
|
43
|
+
style := getStyle(uint64(id)).UnsetFaint()
|
|
44
|
+
return C.ulonglong(allocStyle(style))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//export lipgloss_style_unset_foreground
|
|
48
|
+
func lipgloss_style_unset_foreground(id C.ulonglong) C.ulonglong {
|
|
49
|
+
style := getStyle(uint64(id)).UnsetForeground()
|
|
50
|
+
return C.ulonglong(allocStyle(style))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//export lipgloss_style_unset_background
|
|
54
|
+
func lipgloss_style_unset_background(id C.ulonglong) C.ulonglong {
|
|
55
|
+
style := getStyle(uint64(id)).UnsetBackground()
|
|
56
|
+
return C.ulonglong(allocStyle(style))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//export lipgloss_style_unset_width
|
|
60
|
+
func lipgloss_style_unset_width(id C.ulonglong) C.ulonglong {
|
|
61
|
+
style := getStyle(uint64(id)).UnsetWidth()
|
|
62
|
+
return C.ulonglong(allocStyle(style))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//export lipgloss_style_unset_height
|
|
66
|
+
func lipgloss_style_unset_height(id C.ulonglong) C.ulonglong {
|
|
67
|
+
style := getStyle(uint64(id)).UnsetHeight()
|
|
68
|
+
return C.ulonglong(allocStyle(style))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//export lipgloss_style_unset_padding_top
|
|
72
|
+
func lipgloss_style_unset_padding_top(id C.ulonglong) C.ulonglong {
|
|
73
|
+
style := getStyle(uint64(id)).UnsetPaddingTop()
|
|
74
|
+
return C.ulonglong(allocStyle(style))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//export lipgloss_style_unset_padding_right
|
|
78
|
+
func lipgloss_style_unset_padding_right(id C.ulonglong) C.ulonglong {
|
|
79
|
+
style := getStyle(uint64(id)).UnsetPaddingRight()
|
|
80
|
+
return C.ulonglong(allocStyle(style))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//export lipgloss_style_unset_padding_bottom
|
|
84
|
+
func lipgloss_style_unset_padding_bottom(id C.ulonglong) C.ulonglong {
|
|
85
|
+
style := getStyle(uint64(id)).UnsetPaddingBottom()
|
|
86
|
+
return C.ulonglong(allocStyle(style))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//export lipgloss_style_unset_padding_left
|
|
90
|
+
func lipgloss_style_unset_padding_left(id C.ulonglong) C.ulonglong {
|
|
91
|
+
style := getStyle(uint64(id)).UnsetPaddingLeft()
|
|
92
|
+
return C.ulonglong(allocStyle(style))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//export lipgloss_style_unset_margin_top
|
|
96
|
+
func lipgloss_style_unset_margin_top(id C.ulonglong) C.ulonglong {
|
|
97
|
+
style := getStyle(uint64(id)).UnsetMarginTop()
|
|
98
|
+
return C.ulonglong(allocStyle(style))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//export lipgloss_style_unset_margin_right
|
|
102
|
+
func lipgloss_style_unset_margin_right(id C.ulonglong) C.ulonglong {
|
|
103
|
+
style := getStyle(uint64(id)).UnsetMarginRight()
|
|
104
|
+
return C.ulonglong(allocStyle(style))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//export lipgloss_style_unset_margin_bottom
|
|
108
|
+
func lipgloss_style_unset_margin_bottom(id C.ulonglong) C.ulonglong {
|
|
109
|
+
style := getStyle(uint64(id)).UnsetMarginBottom()
|
|
110
|
+
return C.ulonglong(allocStyle(style))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//export lipgloss_style_unset_margin_left
|
|
114
|
+
func lipgloss_style_unset_margin_left(id C.ulonglong) C.ulonglong {
|
|
115
|
+
style := getStyle(uint64(id)).UnsetMarginLeft()
|
|
116
|
+
return C.ulonglong(allocStyle(style))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//export lipgloss_style_unset_border_style
|
|
120
|
+
func lipgloss_style_unset_border_style(id C.ulonglong) C.ulonglong {
|
|
121
|
+
style := getStyle(uint64(id)).UnsetBorderStyle()
|
|
122
|
+
return C.ulonglong(allocStyle(style))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//export lipgloss_style_unset_inline
|
|
126
|
+
func lipgloss_style_unset_inline(id C.ulonglong) C.ulonglong {
|
|
127
|
+
style := getStyle(uint64(id)).UnsetInline()
|
|
128
|
+
return C.ulonglong(allocStyle(style))
|
|
129
|
+
}
|
data/go/table.go
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"fmt"
|
|
8
|
+
"github.com/charmbracelet/lipgloss"
|
|
9
|
+
lipglosstable "github.com/charmbracelet/lipgloss/table"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
func allocTable(table *lipglosstable.Table) uint64 {
|
|
13
|
+
tablesMu.Lock()
|
|
14
|
+
defer tablesMu.Unlock()
|
|
15
|
+
id := getNextID()
|
|
16
|
+
tables[id] = table
|
|
17
|
+
|
|
18
|
+
return id
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func getTable(id uint64) *lipglosstable.Table {
|
|
22
|
+
tablesMu.RLock()
|
|
23
|
+
defer tablesMu.RUnlock()
|
|
24
|
+
|
|
25
|
+
return tables[id]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//export lipgloss_table_new
|
|
29
|
+
func lipgloss_table_new() C.ulonglong {
|
|
30
|
+
return C.ulonglong(allocTable(lipglosstable.New()))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//export lipgloss_table_free
|
|
34
|
+
func lipgloss_table_free(id C.ulonglong) {
|
|
35
|
+
tablesMu.Lock()
|
|
36
|
+
defer tablesMu.Unlock()
|
|
37
|
+
delete(tables, uint64(id))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//export lipgloss_table_headers
|
|
41
|
+
func lipgloss_table_headers(id C.ulonglong, headersJSON *C.char) C.ulonglong {
|
|
42
|
+
var headers []string
|
|
43
|
+
|
|
44
|
+
if err := json.Unmarshal([]byte(C.GoString(headersJSON)), &headers); err != nil {
|
|
45
|
+
return id
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
table := getTable(uint64(id)).Headers(headers...)
|
|
49
|
+
|
|
50
|
+
return C.ulonglong(allocTable(table))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//export lipgloss_table_row
|
|
54
|
+
func lipgloss_table_row(id C.ulonglong, rowJSON *C.char) C.ulonglong {
|
|
55
|
+
var row []string
|
|
56
|
+
|
|
57
|
+
if err := json.Unmarshal([]byte(C.GoString(rowJSON)), &row); err != nil {
|
|
58
|
+
return id
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
table := getTable(uint64(id)).Row(row...)
|
|
62
|
+
|
|
63
|
+
return C.ulonglong(allocTable(table))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//export lipgloss_table_rows
|
|
67
|
+
func lipgloss_table_rows(id C.ulonglong, rowsJSON *C.char) C.ulonglong {
|
|
68
|
+
var rows [][]string
|
|
69
|
+
|
|
70
|
+
if err := json.Unmarshal([]byte(C.GoString(rowsJSON)), &rows); err != nil {
|
|
71
|
+
return id
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
table := getTable(uint64(id)).Rows(rows...)
|
|
75
|
+
|
|
76
|
+
return C.ulonglong(allocTable(table))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//export lipgloss_table_border
|
|
80
|
+
func lipgloss_table_border(id C.ulonglong, borderType C.int) C.ulonglong {
|
|
81
|
+
var border lipgloss.Border
|
|
82
|
+
|
|
83
|
+
switch int(borderType) {
|
|
84
|
+
case 0:
|
|
85
|
+
border = lipgloss.NormalBorder()
|
|
86
|
+
case 1:
|
|
87
|
+
border = lipgloss.RoundedBorder()
|
|
88
|
+
case 2:
|
|
89
|
+
border = lipgloss.ThickBorder()
|
|
90
|
+
case 3:
|
|
91
|
+
border = lipgloss.DoubleBorder()
|
|
92
|
+
case 4:
|
|
93
|
+
border = lipgloss.HiddenBorder()
|
|
94
|
+
case 5:
|
|
95
|
+
border = lipgloss.BlockBorder()
|
|
96
|
+
case 6:
|
|
97
|
+
border = lipgloss.OuterHalfBlockBorder()
|
|
98
|
+
case 7:
|
|
99
|
+
border = lipgloss.InnerHalfBlockBorder()
|
|
100
|
+
case 8:
|
|
101
|
+
border = lipgloss.ASCIIBorder()
|
|
102
|
+
case 9:
|
|
103
|
+
border = lipgloss.MarkdownBorder()
|
|
104
|
+
default:
|
|
105
|
+
border = lipgloss.NormalBorder()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
table := getTable(uint64(id)).Border(border)
|
|
109
|
+
|
|
110
|
+
return C.ulonglong(allocTable(table))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//export lipgloss_table_border_style
|
|
114
|
+
func lipgloss_table_border_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
|
|
115
|
+
style := getStyle(uint64(styleID))
|
|
116
|
+
table := getTable(uint64(id)).BorderStyle(style)
|
|
117
|
+
return C.ulonglong(allocTable(table))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//export lipgloss_table_border_top
|
|
121
|
+
func lipgloss_table_border_top(id C.ulonglong, value C.int) C.ulonglong {
|
|
122
|
+
table := getTable(uint64(id)).BorderTop(value != 0)
|
|
123
|
+
return C.ulonglong(allocTable(table))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//export lipgloss_table_border_bottom
|
|
127
|
+
func lipgloss_table_border_bottom(id C.ulonglong, value C.int) C.ulonglong {
|
|
128
|
+
table := getTable(uint64(id)).BorderBottom(value != 0)
|
|
129
|
+
return C.ulonglong(allocTable(table))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//export lipgloss_table_border_left
|
|
133
|
+
func lipgloss_table_border_left(id C.ulonglong, value C.int) C.ulonglong {
|
|
134
|
+
table := getTable(uint64(id)).BorderLeft(value != 0)
|
|
135
|
+
return C.ulonglong(allocTable(table))
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//export lipgloss_table_border_right
|
|
139
|
+
func lipgloss_table_border_right(id C.ulonglong, value C.int) C.ulonglong {
|
|
140
|
+
table := getTable(uint64(id)).BorderRight(value != 0)
|
|
141
|
+
return C.ulonglong(allocTable(table))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//export lipgloss_table_border_header
|
|
145
|
+
func lipgloss_table_border_header(id C.ulonglong, value C.int) C.ulonglong {
|
|
146
|
+
table := getTable(uint64(id)).BorderHeader(value != 0)
|
|
147
|
+
return C.ulonglong(allocTable(table))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//export lipgloss_table_border_column
|
|
151
|
+
func lipgloss_table_border_column(id C.ulonglong, value C.int) C.ulonglong {
|
|
152
|
+
table := getTable(uint64(id)).BorderColumn(value != 0)
|
|
153
|
+
return C.ulonglong(allocTable(table))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//export lipgloss_table_border_row
|
|
157
|
+
func lipgloss_table_border_row(id C.ulonglong, value C.int) C.ulonglong {
|
|
158
|
+
table := getTable(uint64(id)).BorderRow(value != 0)
|
|
159
|
+
return C.ulonglong(allocTable(table))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//export lipgloss_table_width
|
|
163
|
+
func lipgloss_table_width(id C.ulonglong, width C.int) C.ulonglong {
|
|
164
|
+
table := getTable(uint64(id)).Width(int(width))
|
|
165
|
+
return C.ulonglong(allocTable(table))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//export lipgloss_table_height
|
|
169
|
+
func lipgloss_table_height(id C.ulonglong, height C.int) C.ulonglong {
|
|
170
|
+
table := getTable(uint64(id)).Height(int(height))
|
|
171
|
+
return C.ulonglong(allocTable(table))
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//export lipgloss_table_offset
|
|
175
|
+
func lipgloss_table_offset(id C.ulonglong, offset C.int) C.ulonglong {
|
|
176
|
+
table := getTable(uint64(id)).Offset(int(offset))
|
|
177
|
+
return C.ulonglong(allocTable(table))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
//export lipgloss_table_wrap
|
|
181
|
+
func lipgloss_table_wrap(id C.ulonglong, value C.int) C.ulonglong {
|
|
182
|
+
table := getTable(uint64(id)).Wrap(value != 0)
|
|
183
|
+
return C.ulonglong(allocTable(table))
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
//export lipgloss_table_clear_rows
|
|
187
|
+
func lipgloss_table_clear_rows(id C.ulonglong) C.ulonglong {
|
|
188
|
+
table := getTable(uint64(id)).ClearRows()
|
|
189
|
+
return C.ulonglong(allocTable(table))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//export lipgloss_table_render
|
|
193
|
+
func lipgloss_table_render(id C.ulonglong) *C.char {
|
|
194
|
+
table := getTable(uint64(id))
|
|
195
|
+
return C.CString(table.Render())
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//export lipgloss_table_style_func
|
|
199
|
+
func lipgloss_table_style_func(id C.ulonglong, styleMapJSON *C.char) C.ulonglong {
|
|
200
|
+
var styleMap map[string]uint64
|
|
201
|
+
|
|
202
|
+
if err := json.Unmarshal([]byte(C.GoString(styleMapJSON)), &styleMap); err != nil {
|
|
203
|
+
return id
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
styleFunc := func(row, column int) lipgloss.Style {
|
|
207
|
+
key := fmt.Sprintf("%d,%d", row, column)
|
|
208
|
+
|
|
209
|
+
if styleID, ok := styleMap[key]; ok {
|
|
210
|
+
return getStyle(styleID)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return lipgloss.NewStyle()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
table := getTable(uint64(id)).StyleFunc(styleFunc)
|
|
217
|
+
return C.ulonglong(allocTable(table))
|
|
218
|
+
}
|