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.
data/go/layout.go ADDED
@@ -0,0 +1,71 @@
1
+ package main
2
+
3
+ import "C"
4
+
5
+ import (
6
+ "encoding/json"
7
+ "github.com/charmbracelet/lipgloss"
8
+ )
9
+
10
+ //export lipgloss_join_horizontal
11
+ func lipgloss_join_horizontal(position C.double, stringsJSON *C.char) *C.char {
12
+ var strings []string
13
+
14
+ if err := json.Unmarshal([]byte(C.GoString(stringsJSON)), &strings); err != nil {
15
+ return C.CString("")
16
+ }
17
+
18
+ result := lipgloss.JoinHorizontal(lipgloss.Position(position), strings...)
19
+
20
+ return C.CString(result)
21
+ }
22
+
23
+ //export lipgloss_join_vertical
24
+ func lipgloss_join_vertical(position C.double, stringsJSON *C.char) *C.char {
25
+ var strings []string
26
+
27
+ if err := json.Unmarshal([]byte(C.GoString(stringsJSON)), &strings); err != nil {
28
+ return C.CString("")
29
+ }
30
+
31
+ result := lipgloss.JoinVertical(lipgloss.Position(position), strings...)
32
+
33
+ return C.CString(result)
34
+ }
35
+
36
+ //export lipgloss_width
37
+ func lipgloss_width(text *C.char) C.int {
38
+ return C.int(lipgloss.Width(C.GoString(text)))
39
+ }
40
+
41
+ //export lipgloss_height
42
+ func lipgloss_height(text *C.char) C.int {
43
+ return C.int(lipgloss.Height(C.GoString(text)))
44
+ }
45
+
46
+ //export lipgloss_place
47
+ func lipgloss_place(width C.int, height C.int, horizontalPosition C.double, verticalPosition C.double, text *C.char) *C.char {
48
+ result := lipgloss.Place(int(width), int(height), lipgloss.Position(horizontalPosition), lipgloss.Position(verticalPosition), C.GoString(text))
49
+ return C.CString(result)
50
+ }
51
+
52
+ //export lipgloss_place_horizontal
53
+ func lipgloss_place_horizontal(width C.int, position C.double, text *C.char) *C.char {
54
+ result := lipgloss.PlaceHorizontal(int(width), lipgloss.Position(position), C.GoString(text))
55
+ return C.CString(result)
56
+ }
57
+
58
+ //export lipgloss_place_vertical
59
+ func lipgloss_place_vertical(height C.int, position C.double, text *C.char) *C.char {
60
+ result := lipgloss.PlaceVertical(int(height), lipgloss.Position(position), C.GoString(text))
61
+ return C.CString(result)
62
+ }
63
+
64
+ //export lipgloss_has_dark_background
65
+ func lipgloss_has_dark_background() C.int {
66
+ if lipgloss.HasDarkBackground() {
67
+ return 1
68
+ }
69
+
70
+ return 0
71
+ }
data/go/lipgloss.go ADDED
@@ -0,0 +1,78 @@
1
+ package main
2
+
3
+ /*
4
+ #include <stdlib.h>
5
+ */
6
+ import "C"
7
+
8
+ import (
9
+ "github.com/charmbracelet/lipgloss"
10
+ lipglosslist "github.com/charmbracelet/lipgloss/list"
11
+ lipglosstable "github.com/charmbracelet/lipgloss/table"
12
+ lipglosstree "github.com/charmbracelet/lipgloss/tree"
13
+ "runtime/debug"
14
+ "sync"
15
+ "unsafe"
16
+ )
17
+
18
+ // Shared ID counter for all handle types
19
+ var (
20
+ nextID uint64 = 1
21
+ nextIDMu sync.Mutex
22
+ )
23
+
24
+ func getNextID() uint64 {
25
+ nextIDMu.Lock()
26
+ defer nextIDMu.Unlock()
27
+ id := nextID
28
+ nextID++
29
+ return id
30
+ }
31
+
32
+ // Style storage
33
+ var (
34
+ styles = make(map[uint64]lipgloss.Style)
35
+ stylesMu sync.RWMutex
36
+ )
37
+
38
+ // Table storage
39
+ var (
40
+ tables = make(map[uint64]*lipglosstable.Table)
41
+ tablesMu sync.RWMutex
42
+ )
43
+
44
+ // List storage
45
+ var (
46
+ lists = make(map[uint64]*lipglosslist.List)
47
+ listsMu sync.RWMutex
48
+ )
49
+
50
+ // Tree storage
51
+ var (
52
+ trees = make(map[uint64]*lipglosstree.Tree)
53
+ treesMu sync.RWMutex
54
+ )
55
+
56
+ //export lipgloss_free
57
+ func lipgloss_free(pointer *C.char) {
58
+ C.free(unsafe.Pointer(pointer))
59
+ }
60
+
61
+ //export lipgloss_upstream_version
62
+ func lipgloss_upstream_version() *C.char {
63
+ info, ok := debug.ReadBuildInfo()
64
+
65
+ if !ok {
66
+ return C.CString("unknown")
67
+ }
68
+
69
+ for _, dep := range info.Deps {
70
+ if dep.Path == "github.com/charmbracelet/lipgloss" {
71
+ return C.CString(dep.Version)
72
+ }
73
+ }
74
+
75
+ return C.CString("unknown")
76
+ }
77
+
78
+ func main() {}
data/go/list.go ADDED
@@ -0,0 +1,118 @@
1
+ package main
2
+
3
+ import "C"
4
+
5
+ import (
6
+ "encoding/json"
7
+ lipglosslist "github.com/charmbracelet/lipgloss/list"
8
+ )
9
+
10
+ func allocList(list *lipglosslist.List) uint64 {
11
+ listsMu.Lock()
12
+ defer listsMu.Unlock()
13
+ id := getNextID()
14
+ lists[id] = list
15
+
16
+ return id
17
+ }
18
+
19
+ func getList(id uint64) *lipglosslist.List {
20
+ listsMu.RLock()
21
+ defer listsMu.RUnlock()
22
+
23
+ return lists[id]
24
+ }
25
+
26
+ //export lipgloss_list_new
27
+ func lipgloss_list_new() C.ulonglong {
28
+ return C.ulonglong(allocList(lipglosslist.New()))
29
+ }
30
+
31
+ //export lipgloss_list_free
32
+ func lipgloss_list_free(id C.ulonglong) {
33
+ listsMu.Lock()
34
+ defer listsMu.Unlock()
35
+ delete(lists, uint64(id))
36
+ }
37
+
38
+ //export lipgloss_list_item
39
+ func lipgloss_list_item(id C.ulonglong, item *C.char) C.ulonglong {
40
+ list := getList(uint64(id)).Item(C.GoString(item))
41
+ return C.ulonglong(allocList(list))
42
+ }
43
+
44
+ //export lipgloss_list_item_list
45
+ func lipgloss_list_item_list(id C.ulonglong, sublistID C.ulonglong) C.ulonglong {
46
+ sublist := getList(uint64(sublistID))
47
+ list := getList(uint64(id)).Item(sublist)
48
+
49
+ return C.ulonglong(allocList(list))
50
+ }
51
+
52
+ //export lipgloss_list_items
53
+ func lipgloss_list_items(id C.ulonglong, itemsJSON *C.char) C.ulonglong {
54
+ var items []string
55
+
56
+ if err := json.Unmarshal([]byte(C.GoString(itemsJSON)), &items); err != nil {
57
+ return id
58
+ }
59
+
60
+ anyItems := make([]any, len(items))
61
+
62
+ for index, item := range items {
63
+ anyItems[index] = item
64
+ }
65
+
66
+ list := getList(uint64(id)).Items(anyItems...)
67
+
68
+ return C.ulonglong(allocList(list))
69
+ }
70
+
71
+ //export lipgloss_list_enumerator
72
+ func lipgloss_list_enumerator(id C.ulonglong, enumType C.int) C.ulonglong {
73
+ var enumerator lipglosslist.Enumerator
74
+
75
+ switch int(enumType) {
76
+ case 0:
77
+ enumerator = lipglosslist.Bullet
78
+ case 1:
79
+ enumerator = lipglosslist.Arabic
80
+ case 2:
81
+ enumerator = lipglosslist.Alphabet
82
+ case 3:
83
+ enumerator = lipglosslist.Roman
84
+ case 4:
85
+ enumerator = lipglosslist.Dash
86
+ case 5:
87
+ enumerator = lipglosslist.Asterisk
88
+ default:
89
+ enumerator = lipglosslist.Bullet
90
+ }
91
+
92
+ list := getList(uint64(id)).Enumerator(enumerator)
93
+
94
+ return C.ulonglong(allocList(list))
95
+ }
96
+
97
+ //export lipgloss_list_enumerator_style
98
+ func lipgloss_list_enumerator_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
99
+ style := getStyle(uint64(styleID))
100
+ list := getList(uint64(id)).EnumeratorStyle(style)
101
+
102
+ return C.ulonglong(allocList(list))
103
+ }
104
+
105
+ //export lipgloss_list_item_style
106
+ func lipgloss_list_item_style(id C.ulonglong, styleID C.ulonglong) C.ulonglong {
107
+ style := getStyle(uint64(styleID))
108
+ list := getList(uint64(id)).ItemStyle(style)
109
+
110
+ return C.ulonglong(allocList(list))
111
+ }
112
+
113
+ //export lipgloss_list_render
114
+ func lipgloss_list_render(id C.ulonglong) *C.char {
115
+ list := getList(uint64(id))
116
+
117
+ return C.CString(list.String())
118
+ }
data/go/style.go ADDED
@@ -0,0 +1,281 @@
1
+ package main
2
+
3
+ import "C"
4
+
5
+ import (
6
+ "unsafe"
7
+
8
+ "github.com/charmbracelet/lipgloss"
9
+ )
10
+
11
+ func allocStyle(style lipgloss.Style) uint64 {
12
+ stylesMu.Lock()
13
+ defer stylesMu.Unlock()
14
+ id := getNextID()
15
+ styles[id] = style
16
+
17
+ return id
18
+ }
19
+
20
+ func getStyle(id uint64) lipgloss.Style {
21
+ stylesMu.RLock()
22
+ defer stylesMu.RUnlock()
23
+
24
+ return styles[id]
25
+ }
26
+
27
+ //export lipgloss_new_style
28
+ func lipgloss_new_style() C.ulonglong {
29
+ return C.ulonglong(allocStyle(lipgloss.NewStyle()))
30
+ }
31
+
32
+ //export lipgloss_free_style
33
+ func lipgloss_free_style(id C.ulonglong) {
34
+ stylesMu.Lock()
35
+ defer stylesMu.Unlock()
36
+ delete(styles, uint64(id))
37
+ }
38
+
39
+ //export lipgloss_style_render
40
+ func lipgloss_style_render(id C.ulonglong, text *C.char) *C.char {
41
+ style := getStyle(uint64(id))
42
+ result := style.Render(C.GoString(text))
43
+
44
+ return C.CString(result)
45
+ }
46
+
47
+ // Text formatting methods
48
+
49
+ //export lipgloss_style_bold
50
+ func lipgloss_style_bold(id C.ulonglong, value C.int) C.ulonglong {
51
+ style := getStyle(uint64(id)).Bold(value != 0)
52
+ return C.ulonglong(allocStyle(style))
53
+ }
54
+
55
+ //export lipgloss_style_italic
56
+ func lipgloss_style_italic(id C.ulonglong, value C.int) C.ulonglong {
57
+ style := getStyle(uint64(id)).Italic(value != 0)
58
+ return C.ulonglong(allocStyle(style))
59
+ }
60
+
61
+ //export lipgloss_style_underline
62
+ func lipgloss_style_underline(id C.ulonglong, value C.int) C.ulonglong {
63
+ style := getStyle(uint64(id)).Underline(value != 0)
64
+ return C.ulonglong(allocStyle(style))
65
+ }
66
+
67
+ //export lipgloss_style_strikethrough
68
+ func lipgloss_style_strikethrough(id C.ulonglong, value C.int) C.ulonglong {
69
+ style := getStyle(uint64(id)).Strikethrough(value != 0)
70
+ return C.ulonglong(allocStyle(style))
71
+ }
72
+
73
+ //export lipgloss_style_reverse
74
+ func lipgloss_style_reverse(id C.ulonglong, value C.int) C.ulonglong {
75
+ style := getStyle(uint64(id)).Reverse(value != 0)
76
+ return C.ulonglong(allocStyle(style))
77
+ }
78
+
79
+ //export lipgloss_style_blink
80
+ func lipgloss_style_blink(id C.ulonglong, value C.int) C.ulonglong {
81
+ style := getStyle(uint64(id)).Blink(value != 0)
82
+ return C.ulonglong(allocStyle(style))
83
+ }
84
+
85
+ //export lipgloss_style_faint
86
+ func lipgloss_style_faint(id C.ulonglong, value C.int) C.ulonglong {
87
+ style := getStyle(uint64(id)).Faint(value != 0)
88
+ return C.ulonglong(allocStyle(style))
89
+ }
90
+
91
+ // Color methods
92
+
93
+ //export lipgloss_style_foreground
94
+ func lipgloss_style_foreground(id C.ulonglong, color *C.char) C.ulonglong {
95
+ style := getStyle(uint64(id)).Foreground(lipgloss.Color(C.GoString(color)))
96
+ return C.ulonglong(allocStyle(style))
97
+ }
98
+
99
+ //export lipgloss_style_background
100
+ func lipgloss_style_background(id C.ulonglong, color *C.char) C.ulonglong {
101
+ style := getStyle(uint64(id)).Background(lipgloss.Color(C.GoString(color)))
102
+ return C.ulonglong(allocStyle(style))
103
+ }
104
+
105
+ //export lipgloss_style_foreground_adaptive
106
+ func lipgloss_style_foreground_adaptive(id C.ulonglong, light *C.char, dark *C.char) C.ulonglong {
107
+ style := getStyle(uint64(id)).Foreground(lipgloss.AdaptiveColor{
108
+ Light: C.GoString(light),
109
+ Dark: C.GoString(dark),
110
+ })
111
+
112
+ return C.ulonglong(allocStyle(style))
113
+ }
114
+
115
+ //export lipgloss_style_background_adaptive
116
+ func lipgloss_style_background_adaptive(id C.ulonglong, light *C.char, dark *C.char) C.ulonglong {
117
+ style := getStyle(uint64(id)).Background(lipgloss.AdaptiveColor{
118
+ Light: C.GoString(light),
119
+ Dark: C.GoString(dark),
120
+ })
121
+
122
+ return C.ulonglong(allocStyle(style))
123
+ }
124
+
125
+ //export lipgloss_style_foreground_complete
126
+ func lipgloss_style_foreground_complete(id C.ulonglong, trueColor *C.char, ansi256 *C.char, ansi *C.char) C.ulonglong {
127
+ style := getStyle(uint64(id)).Foreground(lipgloss.CompleteColor{
128
+ TrueColor: C.GoString(trueColor),
129
+ ANSI256: C.GoString(ansi256),
130
+ ANSI: C.GoString(ansi),
131
+ })
132
+
133
+ return C.ulonglong(allocStyle(style))
134
+ }
135
+
136
+ //export lipgloss_style_background_complete
137
+ func lipgloss_style_background_complete(id C.ulonglong, trueColor *C.char, ansi256 *C.char, ansi *C.char) C.ulonglong {
138
+ style := getStyle(uint64(id)).Background(lipgloss.CompleteColor{
139
+ TrueColor: C.GoString(trueColor),
140
+ ANSI256: C.GoString(ansi256),
141
+ ANSI: C.GoString(ansi),
142
+ })
143
+
144
+ return C.ulonglong(allocStyle(style))
145
+ }
146
+
147
+ //export lipgloss_style_foreground_complete_adaptive
148
+ func lipgloss_style_foreground_complete_adaptive(id C.ulonglong, lightTrue *C.char, lightAnsi256 *C.char, lightAnsi *C.char, darkTrue *C.char, darkAnsi256 *C.char, darkAnsi *C.char) C.ulonglong {
149
+ style := getStyle(uint64(id)).Foreground(lipgloss.CompleteAdaptiveColor{
150
+ Light: lipgloss.CompleteColor{
151
+ TrueColor: C.GoString(lightTrue),
152
+ ANSI256: C.GoString(lightAnsi256),
153
+ ANSI: C.GoString(lightAnsi),
154
+ },
155
+ Dark: lipgloss.CompleteColor{
156
+ TrueColor: C.GoString(darkTrue),
157
+ ANSI256: C.GoString(darkAnsi256),
158
+ ANSI: C.GoString(darkAnsi),
159
+ },
160
+ })
161
+
162
+ return C.ulonglong(allocStyle(style))
163
+ }
164
+
165
+ //export lipgloss_style_background_complete_adaptive
166
+ func lipgloss_style_background_complete_adaptive(id C.ulonglong, lightTrue *C.char, lightAnsi256 *C.char, lightAnsi *C.char, darkTrue *C.char, darkAnsi256 *C.char, darkAnsi *C.char) C.ulonglong {
167
+ style := getStyle(uint64(id)).Background(lipgloss.CompleteAdaptiveColor{
168
+ Light: lipgloss.CompleteColor{
169
+ TrueColor: C.GoString(lightTrue),
170
+ ANSI256: C.GoString(lightAnsi256),
171
+ ANSI: C.GoString(lightAnsi),
172
+ },
173
+ Dark: lipgloss.CompleteColor{
174
+ TrueColor: C.GoString(darkTrue),
175
+ ANSI256: C.GoString(darkAnsi256),
176
+ ANSI: C.GoString(darkAnsi),
177
+ },
178
+ })
179
+
180
+ return C.ulonglong(allocStyle(style))
181
+ }
182
+
183
+ // Size methods
184
+
185
+ //export lipgloss_style_width
186
+ func lipgloss_style_width(id C.ulonglong, width C.int) C.ulonglong {
187
+ style := getStyle(uint64(id)).Width(int(width))
188
+ return C.ulonglong(allocStyle(style))
189
+ }
190
+
191
+ //export lipgloss_style_height
192
+ func lipgloss_style_height(id C.ulonglong, height C.int) C.ulonglong {
193
+ style := getStyle(uint64(id)).Height(int(height))
194
+ return C.ulonglong(allocStyle(style))
195
+ }
196
+
197
+ //export lipgloss_style_max_width
198
+ func lipgloss_style_max_width(id C.ulonglong, width C.int) C.ulonglong {
199
+ style := getStyle(uint64(id)).MaxWidth(int(width))
200
+ return C.ulonglong(allocStyle(style))
201
+ }
202
+
203
+ //export lipgloss_style_max_height
204
+ func lipgloss_style_max_height(id C.ulonglong, height C.int) C.ulonglong {
205
+ style := getStyle(uint64(id)).MaxHeight(int(height))
206
+ return C.ulonglong(allocStyle(style))
207
+ }
208
+
209
+ // Alignment methods
210
+
211
+ //export lipgloss_style_align
212
+ func lipgloss_style_align(id C.ulonglong, positions *C.double, count C.int) C.ulonglong {
213
+ goPositions := make([]lipgloss.Position, int(count))
214
+ slice := unsafe.Slice(positions, int(count))
215
+
216
+ for index, value := range slice {
217
+ goPositions[index] = lipgloss.Position(value)
218
+ }
219
+
220
+ style := getStyle(uint64(id)).Align(goPositions...)
221
+
222
+ return C.ulonglong(allocStyle(style))
223
+ }
224
+
225
+ //export lipgloss_style_align_horizontal
226
+ func lipgloss_style_align_horizontal(id C.ulonglong, position C.double) C.ulonglong {
227
+ style := getStyle(uint64(id)).AlignHorizontal(lipgloss.Position(position))
228
+ return C.ulonglong(allocStyle(style))
229
+ }
230
+
231
+ //export lipgloss_style_align_vertical
232
+ func lipgloss_style_align_vertical(id C.ulonglong, position C.double) C.ulonglong {
233
+ style := getStyle(uint64(id)).AlignVertical(lipgloss.Position(position))
234
+ return C.ulonglong(allocStyle(style))
235
+ }
236
+
237
+ // Other style methods
238
+
239
+ //export lipgloss_style_inline
240
+ func lipgloss_style_inline(id C.ulonglong, value C.int) C.ulonglong {
241
+ style := getStyle(uint64(id)).Inline(value != 0)
242
+ return C.ulonglong(allocStyle(style))
243
+ }
244
+
245
+ //export lipgloss_style_tab_width
246
+ func lipgloss_style_tab_width(id C.ulonglong, width C.int) C.ulonglong {
247
+ style := getStyle(uint64(id)).TabWidth(int(width))
248
+ return C.ulonglong(allocStyle(style))
249
+ }
250
+
251
+ //export lipgloss_style_underline_spaces
252
+ func lipgloss_style_underline_spaces(id C.ulonglong, value C.int) C.ulonglong {
253
+ style := getStyle(uint64(id)).UnderlineSpaces(value != 0)
254
+ return C.ulonglong(allocStyle(style))
255
+ }
256
+
257
+ //export lipgloss_style_strikethrough_spaces
258
+ func lipgloss_style_strikethrough_spaces(id C.ulonglong, value C.int) C.ulonglong {
259
+ style := getStyle(uint64(id)).StrikethroughSpaces(value != 0)
260
+ return C.ulonglong(allocStyle(style))
261
+ }
262
+
263
+ // SetString and Inherit
264
+
265
+ //export lipgloss_style_set_string
266
+ func lipgloss_style_set_string(id C.ulonglong, text *C.char) C.ulonglong {
267
+ style := getStyle(uint64(id)).SetString(C.GoString(text))
268
+ return C.ulonglong(allocStyle(style))
269
+ }
270
+
271
+ //export lipgloss_style_inherit
272
+ func lipgloss_style_inherit(id C.ulonglong, inheritFromID C.ulonglong) C.ulonglong {
273
+ style := getStyle(uint64(id)).Inherit(getStyle(uint64(inheritFromID)))
274
+ return C.ulonglong(allocStyle(style))
275
+ }
276
+
277
+ //export lipgloss_style_string
278
+ func lipgloss_style_string(id C.ulonglong) *C.char {
279
+ style := getStyle(uint64(id))
280
+ return C.CString(style.String())
281
+ }