lipgloss 0.1.0-x86_64-darwin → 0.2.0-x86_64-darwin
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/README.md +51 -22
- data/ext/lipgloss/color.c +158 -0
- data/ext/lipgloss/extconf.rb +11 -1
- data/ext/lipgloss/extension.c +61 -19
- data/ext/lipgloss/extension.h +3 -0
- data/ext/lipgloss/style.c +89 -13
- data/ext/lipgloss/style_border.c +28 -0
- data/go/build/darwin_amd64/liblipgloss.a +0 -0
- data/go/build/darwin_amd64/liblipgloss.h +21 -0
- data/go/color.go +168 -0
- data/go/layout.go +42 -0
- data/go/style.go +107 -0
- data/go/style_border.go +20 -0
- data/lib/lipgloss/3.2/lipgloss.bundle +0 -0
- data/lib/lipgloss/3.3/lipgloss.bundle +0 -0
- data/lib/lipgloss/3.4/lipgloss.bundle +0 -0
- data/lib/lipgloss/4.0/lipgloss.bundle +0 -0
- data/lib/lipgloss/color.rb +44 -8
- data/lib/lipgloss/position.rb +23 -0
- data/lib/lipgloss/style.rb +24 -0
- data/lib/lipgloss/version.rb +1 -1
- data/lib/lipgloss.rb +51 -1
- data/lipgloss.gemspec +2 -2
- metadata +9 -5
|
@@ -20,6 +20,7 @@ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
|
|
23
24
|
#line 3 "lipgloss.go"
|
|
24
25
|
|
|
25
26
|
#include <stdlib.h>
|
|
@@ -87,11 +88,18 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
|
|
87
88
|
extern "C" {
|
|
88
89
|
#endif
|
|
89
90
|
|
|
91
|
+
extern char* lipgloss_color_blend_luv(char* c1, char* c2, double t);
|
|
92
|
+
extern char* lipgloss_color_blend_rgb(char* c1, char* c2, double t);
|
|
93
|
+
extern char* lipgloss_color_blend_hcl(char* c1, char* c2, double t);
|
|
94
|
+
extern char* lipgloss_color_blends(char* c1, char* c2, int steps, int blendMode);
|
|
95
|
+
extern char* lipgloss_color_grid(char* x0y0, char* x1y0, char* x0y1, char* x1y1, int xSteps, int ySteps, int blendMode);
|
|
90
96
|
extern char* lipgloss_join_horizontal(double position, char* stringsJSON);
|
|
91
97
|
extern char* lipgloss_join_vertical(double position, char* stringsJSON);
|
|
92
98
|
extern int lipgloss_width(char* text);
|
|
93
99
|
extern int lipgloss_height(char* text);
|
|
94
100
|
extern char* lipgloss_place(int width, int height, double horizontalPosition, double verticalPosition, char* text);
|
|
101
|
+
extern char* lipgloss_place_with_whitespace(int width, int height, double horizontalPosition, double verticalPosition, char* text, char* whitespaceChars, char* whitespaceForeground);
|
|
102
|
+
extern char* lipgloss_place_with_whitespace_adaptive(int width, int height, double horizontalPosition, double verticalPosition, char* text, char* whitespaceChars, char* whitespaceForegroundLight, char* whitespaceForegroundDark);
|
|
95
103
|
extern char* lipgloss_place_horizontal(int width, double position, char* text);
|
|
96
104
|
extern char* lipgloss_place_vertical(int height, double position, char* text);
|
|
97
105
|
extern int lipgloss_has_dark_background();
|
|
@@ -138,11 +146,24 @@ extern long long unsigned int lipgloss_style_strikethrough_spaces(long long unsi
|
|
|
138
146
|
extern long long unsigned int lipgloss_style_set_string(long long unsigned int id, char* text);
|
|
139
147
|
extern long long unsigned int lipgloss_style_inherit(long long unsigned int id, long long unsigned int inheritFromID);
|
|
140
148
|
extern char* lipgloss_style_string(long long unsigned int id);
|
|
149
|
+
extern int lipgloss_style_get_bold(long long unsigned int id);
|
|
150
|
+
extern int lipgloss_style_get_italic(long long unsigned int id);
|
|
151
|
+
extern int lipgloss_style_get_underline(long long unsigned int id);
|
|
152
|
+
extern int lipgloss_style_get_strikethrough(long long unsigned int id);
|
|
153
|
+
extern int lipgloss_style_get_reverse(long long unsigned int id);
|
|
154
|
+
extern int lipgloss_style_get_blink(long long unsigned int id);
|
|
155
|
+
extern int lipgloss_style_get_faint(long long unsigned int id);
|
|
156
|
+
extern char* lipgloss_style_get_foreground(long long unsigned int id);
|
|
157
|
+
extern char* lipgloss_style_get_background(long long unsigned int id);
|
|
158
|
+
extern int lipgloss_style_get_width(long long unsigned int id);
|
|
159
|
+
extern int lipgloss_style_get_height(long long unsigned int id);
|
|
141
160
|
extern long long unsigned int lipgloss_style_border(long long unsigned int id, int borderType, int* sides, int sidesCount);
|
|
142
161
|
extern long long unsigned int lipgloss_style_border_style(long long unsigned int id, int borderType);
|
|
143
162
|
extern long long unsigned int lipgloss_style_border_custom(long long unsigned int id, char* top, char* bottom, char* left, char* right, char* topLeft, char* topRight, char* bottomLeft, char* bottomRight, char* middleLeft, char* middleRight, char* middle, char* middleTop, char* middleBottom);
|
|
144
163
|
extern long long unsigned int lipgloss_style_border_foreground(long long unsigned int id, char* color);
|
|
164
|
+
extern long long unsigned int lipgloss_style_border_foreground_adaptive(long long unsigned int id, char* light, char* dark);
|
|
145
165
|
extern long long unsigned int lipgloss_style_border_background(long long unsigned int id, char* color);
|
|
166
|
+
extern long long unsigned int lipgloss_style_border_background_adaptive(long long unsigned int id, char* light, char* dark);
|
|
146
167
|
extern long long unsigned int lipgloss_style_border_top(long long unsigned int id, int value);
|
|
147
168
|
extern long long unsigned int lipgloss_style_border_right(long long unsigned int id, int value);
|
|
148
169
|
extern long long unsigned int lipgloss_style_border_bottom(long long unsigned int id, int value);
|
data/go/color.go
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import "C"
|
|
4
|
+
|
|
5
|
+
import (
|
|
6
|
+
"encoding/json"
|
|
7
|
+
"github.com/lucasb-eyer/go-colorful"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
//export lipgloss_color_blend_luv
|
|
11
|
+
func lipgloss_color_blend_luv(c1 *C.char, c2 *C.char, t C.double) *C.char {
|
|
12
|
+
color1, err := colorful.Hex(C.GoString(c1))
|
|
13
|
+
if err != nil {
|
|
14
|
+
return C.CString(C.GoString(c1))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
color2, err := colorful.Hex(C.GoString(c2))
|
|
18
|
+
if err != nil {
|
|
19
|
+
return C.CString(C.GoString(c1))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
blended := color1.BlendLuv(color2, float64(t))
|
|
23
|
+
return C.CString(blended.Hex())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//export lipgloss_color_blend_rgb
|
|
27
|
+
func lipgloss_color_blend_rgb(c1 *C.char, c2 *C.char, t C.double) *C.char {
|
|
28
|
+
color1, err := colorful.Hex(C.GoString(c1))
|
|
29
|
+
if err != nil {
|
|
30
|
+
return C.CString(C.GoString(c1))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
color2, err := colorful.Hex(C.GoString(c2))
|
|
34
|
+
if err != nil {
|
|
35
|
+
return C.CString(C.GoString(c1))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
blended := color1.BlendRgb(color2, float64(t))
|
|
39
|
+
return C.CString(blended.Hex())
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//export lipgloss_color_blend_hcl
|
|
43
|
+
func lipgloss_color_blend_hcl(c1 *C.char, c2 *C.char, t C.double) *C.char {
|
|
44
|
+
color1, err := colorful.Hex(C.GoString(c1))
|
|
45
|
+
if err != nil {
|
|
46
|
+
return C.CString(C.GoString(c1))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
color2, err := colorful.Hex(C.GoString(c2))
|
|
50
|
+
if err != nil {
|
|
51
|
+
return C.CString(C.GoString(c1))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
blended := color1.BlendHcl(color2, float64(t))
|
|
55
|
+
return C.CString(blended.Hex())
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//export lipgloss_color_blends
|
|
59
|
+
func lipgloss_color_blends(c1 *C.char, c2 *C.char, steps C.int, blendMode C.int) *C.char {
|
|
60
|
+
color1, err := colorful.Hex(C.GoString(c1))
|
|
61
|
+
if err != nil {
|
|
62
|
+
return C.CString("[]")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
color2, err := colorful.Hex(C.GoString(c2))
|
|
66
|
+
if err != nil {
|
|
67
|
+
return C.CString("[]")
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
n := int(steps)
|
|
71
|
+
colors := make([]string, n)
|
|
72
|
+
|
|
73
|
+
for i := 0; i < n; i++ {
|
|
74
|
+
t := float64(i) / float64(n-1)
|
|
75
|
+
if n == 1 {
|
|
76
|
+
t = 0
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var blended colorful.Color
|
|
80
|
+
switch int(blendMode) {
|
|
81
|
+
case 0: // LUV
|
|
82
|
+
blended = color1.BlendLuv(color2, t)
|
|
83
|
+
case 1: // RGB
|
|
84
|
+
blended = color1.BlendRgb(color2, t)
|
|
85
|
+
case 2: // HCL
|
|
86
|
+
blended = color1.BlendHcl(color2, t)
|
|
87
|
+
default:
|
|
88
|
+
blended = color1.BlendLuv(color2, t)
|
|
89
|
+
}
|
|
90
|
+
colors[i] = blended.Hex()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
result, _ := json.Marshal(colors)
|
|
94
|
+
return C.CString(string(result))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//export lipgloss_color_grid
|
|
98
|
+
func lipgloss_color_grid(x0y0 *C.char, x1y0 *C.char, x0y1 *C.char, x1y1 *C.char, xSteps C.int, ySteps C.int, blendMode C.int) *C.char {
|
|
99
|
+
c00, err := colorful.Hex(C.GoString(x0y0))
|
|
100
|
+
if err != nil {
|
|
101
|
+
return C.CString("[]")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
c10, err := colorful.Hex(C.GoString(x1y0))
|
|
105
|
+
if err != nil {
|
|
106
|
+
return C.CString("[]")
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
c01, err := colorful.Hex(C.GoString(x0y1))
|
|
110
|
+
if err != nil {
|
|
111
|
+
return C.CString("[]")
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
c11, err := colorful.Hex(C.GoString(x1y1))
|
|
115
|
+
if err != nil {
|
|
116
|
+
return C.CString("[]")
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
nx := int(xSteps)
|
|
120
|
+
ny := int(ySteps)
|
|
121
|
+
mode := int(blendMode)
|
|
122
|
+
|
|
123
|
+
blendFunc := func(a, b colorful.Color, t float64) colorful.Color {
|
|
124
|
+
switch mode {
|
|
125
|
+
case 0: // LUV
|
|
126
|
+
return a.BlendLuv(b, t)
|
|
127
|
+
case 1: // RGB
|
|
128
|
+
return a.BlendRgb(b, t)
|
|
129
|
+
case 2: // HCL
|
|
130
|
+
return a.BlendHcl(b, t)
|
|
131
|
+
default:
|
|
132
|
+
return a.BlendLuv(b, t)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
x0 := make([]colorful.Color, ny)
|
|
137
|
+
x1 := make([]colorful.Color, ny)
|
|
138
|
+
|
|
139
|
+
for y := 0; y < ny; y++ {
|
|
140
|
+
t := float64(y) / float64(ny)
|
|
141
|
+
|
|
142
|
+
if ny == 1 {
|
|
143
|
+
t = 0
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
x0[y] = blendFunc(c00, c01, t)
|
|
147
|
+
x1[y] = blendFunc(c10, c11, t)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
grid := make([][]string, ny)
|
|
151
|
+
|
|
152
|
+
for y := 0; y < ny; y++ {
|
|
153
|
+
grid[y] = make([]string, nx)
|
|
154
|
+
|
|
155
|
+
for x := 0; x < nx; x++ {
|
|
156
|
+
t := float64(x) / float64(nx)
|
|
157
|
+
|
|
158
|
+
if nx == 1 {
|
|
159
|
+
t = 0
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
grid[y][x] = blendFunc(x0[y], x1[y], t).Hex()
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
result, _ := json.Marshal(grid)
|
|
167
|
+
return C.CString(string(result))
|
|
168
|
+
}
|
data/go/layout.go
CHANGED
|
@@ -49,6 +49,48 @@ func lipgloss_place(width C.int, height C.int, horizontalPosition C.double, vert
|
|
|
49
49
|
return C.CString(result)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
//export lipgloss_place_with_whitespace
|
|
53
|
+
func lipgloss_place_with_whitespace(width C.int, height C.int, horizontalPosition C.double, verticalPosition C.double, text *C.char, whitespaceChars *C.char, whitespaceForeground *C.char) *C.char {
|
|
54
|
+
opts := []lipgloss.WhitespaceOption{}
|
|
55
|
+
|
|
56
|
+
wsChars := C.GoString(whitespaceChars)
|
|
57
|
+
if wsChars != "" {
|
|
58
|
+
opts = append(opts, lipgloss.WithWhitespaceChars(wsChars))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
wsFg := C.GoString(whitespaceForeground)
|
|
62
|
+
if wsFg != "" {
|
|
63
|
+
opts = append(opts, lipgloss.WithWhitespaceForeground(lipgloss.Color(wsFg)))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
result := lipgloss.Place(int(width), int(height), lipgloss.Position(horizontalPosition), lipgloss.Position(verticalPosition), C.GoString(text), opts...)
|
|
67
|
+
return C.CString(result)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//export lipgloss_place_with_whitespace_adaptive
|
|
71
|
+
func lipgloss_place_with_whitespace_adaptive(width C.int, height C.int, horizontalPosition C.double, verticalPosition C.double, text *C.char, whitespaceChars *C.char, whitespaceForegroundLight *C.char, whitespaceForegroundDark *C.char) *C.char {
|
|
72
|
+
opts := []lipgloss.WhitespaceOption{}
|
|
73
|
+
|
|
74
|
+
wsChars := C.GoString(whitespaceChars)
|
|
75
|
+
if wsChars != "" {
|
|
76
|
+
opts = append(opts, lipgloss.WithWhitespaceChars(wsChars))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
wsFgLight := C.GoString(whitespaceForegroundLight)
|
|
80
|
+
wsFgDark := C.GoString(whitespaceForegroundDark)
|
|
81
|
+
|
|
82
|
+
if wsFgLight != "" || wsFgDark != "" {
|
|
83
|
+
opts = append(opts, lipgloss.WithWhitespaceForeground(lipgloss.AdaptiveColor{
|
|
84
|
+
Light: wsFgLight,
|
|
85
|
+
Dark: wsFgDark,
|
|
86
|
+
}))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
result := lipgloss.Place(int(width), int(height), lipgloss.Position(horizontalPosition), lipgloss.Position(verticalPosition), C.GoString(text), opts...)
|
|
90
|
+
|
|
91
|
+
return C.CString(result)
|
|
92
|
+
}
|
|
93
|
+
|
|
52
94
|
//export lipgloss_place_horizontal
|
|
53
95
|
func lipgloss_place_horizontal(width C.int, position C.double, text *C.char) *C.char {
|
|
54
96
|
result := lipgloss.PlaceHorizontal(int(width), lipgloss.Position(position), C.GoString(text))
|
data/go/style.go
CHANGED
|
@@ -279,3 +279,110 @@ func lipgloss_style_string(id C.ulonglong) *C.char {
|
|
|
279
279
|
style := getStyle(uint64(id))
|
|
280
280
|
return C.CString(style.String())
|
|
281
281
|
}
|
|
282
|
+
|
|
283
|
+
// Getter methods
|
|
284
|
+
|
|
285
|
+
//export lipgloss_style_get_bold
|
|
286
|
+
func lipgloss_style_get_bold(id C.ulonglong) C.int {
|
|
287
|
+
style := getStyle(uint64(id))
|
|
288
|
+
if style.GetBold() {
|
|
289
|
+
return 1
|
|
290
|
+
}
|
|
291
|
+
return 0
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//export lipgloss_style_get_italic
|
|
295
|
+
func lipgloss_style_get_italic(id C.ulonglong) C.int {
|
|
296
|
+
style := getStyle(uint64(id))
|
|
297
|
+
if style.GetItalic() {
|
|
298
|
+
return 1
|
|
299
|
+
}
|
|
300
|
+
return 0
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
//export lipgloss_style_get_underline
|
|
304
|
+
func lipgloss_style_get_underline(id C.ulonglong) C.int {
|
|
305
|
+
style := getStyle(uint64(id))
|
|
306
|
+
if style.GetUnderline() {
|
|
307
|
+
return 1
|
|
308
|
+
}
|
|
309
|
+
return 0
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
//export lipgloss_style_get_strikethrough
|
|
313
|
+
func lipgloss_style_get_strikethrough(id C.ulonglong) C.int {
|
|
314
|
+
style := getStyle(uint64(id))
|
|
315
|
+
if style.GetStrikethrough() {
|
|
316
|
+
return 1
|
|
317
|
+
}
|
|
318
|
+
return 0
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
//export lipgloss_style_get_reverse
|
|
322
|
+
func lipgloss_style_get_reverse(id C.ulonglong) C.int {
|
|
323
|
+
style := getStyle(uint64(id))
|
|
324
|
+
if style.GetReverse() {
|
|
325
|
+
return 1
|
|
326
|
+
}
|
|
327
|
+
return 0
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
//export lipgloss_style_get_blink
|
|
331
|
+
func lipgloss_style_get_blink(id C.ulonglong) C.int {
|
|
332
|
+
style := getStyle(uint64(id))
|
|
333
|
+
if style.GetBlink() {
|
|
334
|
+
return 1
|
|
335
|
+
}
|
|
336
|
+
return 0
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
//export lipgloss_style_get_faint
|
|
340
|
+
func lipgloss_style_get_faint(id C.ulonglong) C.int {
|
|
341
|
+
style := getStyle(uint64(id))
|
|
342
|
+
if style.GetFaint() {
|
|
343
|
+
return 1
|
|
344
|
+
}
|
|
345
|
+
return 0
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// terminalColorToString converts a TerminalColor to its string representation
|
|
349
|
+
func terminalColorToString(tc lipgloss.TerminalColor) string {
|
|
350
|
+
if tc == nil {
|
|
351
|
+
return ""
|
|
352
|
+
}
|
|
353
|
+
switch c := tc.(type) {
|
|
354
|
+
case lipgloss.Color:
|
|
355
|
+
return string(c)
|
|
356
|
+
case lipgloss.NoColor:
|
|
357
|
+
return ""
|
|
358
|
+
default:
|
|
359
|
+
// For adaptive/complete colors, we can't easily extract a single value
|
|
360
|
+
return ""
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
//export lipgloss_style_get_foreground
|
|
365
|
+
func lipgloss_style_get_foreground(id C.ulonglong) *C.char {
|
|
366
|
+
style := getStyle(uint64(id))
|
|
367
|
+
color := terminalColorToString(style.GetForeground())
|
|
368
|
+
return C.CString(color)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
//export lipgloss_style_get_background
|
|
372
|
+
func lipgloss_style_get_background(id C.ulonglong) *C.char {
|
|
373
|
+
style := getStyle(uint64(id))
|
|
374
|
+
color := terminalColorToString(style.GetBackground())
|
|
375
|
+
return C.CString(color)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
//export lipgloss_style_get_width
|
|
379
|
+
func lipgloss_style_get_width(id C.ulonglong) C.int {
|
|
380
|
+
style := getStyle(uint64(id))
|
|
381
|
+
return C.int(style.GetWidth())
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//export lipgloss_style_get_height
|
|
385
|
+
func lipgloss_style_get_height(id C.ulonglong) C.int {
|
|
386
|
+
style := getStyle(uint64(id))
|
|
387
|
+
return C.int(style.GetHeight())
|
|
388
|
+
}
|
data/go/style_border.go
CHANGED
|
@@ -114,12 +114,32 @@ func lipgloss_style_border_foreground(id C.ulonglong, color *C.char) C.ulonglong
|
|
|
114
114
|
return C.ulonglong(allocStyle(style))
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
//export lipgloss_style_border_foreground_adaptive
|
|
118
|
+
func lipgloss_style_border_foreground_adaptive(id C.ulonglong, light *C.char, dark *C.char) C.ulonglong {
|
|
119
|
+
style := getStyle(uint64(id)).BorderForeground(lipgloss.AdaptiveColor{
|
|
120
|
+
Light: C.GoString(light),
|
|
121
|
+
Dark: C.GoString(dark),
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
return C.ulonglong(allocStyle(style))
|
|
125
|
+
}
|
|
126
|
+
|
|
117
127
|
//export lipgloss_style_border_background
|
|
118
128
|
func lipgloss_style_border_background(id C.ulonglong, color *C.char) C.ulonglong {
|
|
119
129
|
style := getStyle(uint64(id)).BorderBackground(lipgloss.Color(C.GoString(color)))
|
|
120
130
|
return C.ulonglong(allocStyle(style))
|
|
121
131
|
}
|
|
122
132
|
|
|
133
|
+
//export lipgloss_style_border_background_adaptive
|
|
134
|
+
func lipgloss_style_border_background_adaptive(id C.ulonglong, light *C.char, dark *C.char) C.ulonglong {
|
|
135
|
+
style := getStyle(uint64(id)).BorderBackground(lipgloss.AdaptiveColor{
|
|
136
|
+
Light: C.GoString(light),
|
|
137
|
+
Dark: C.GoString(dark),
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
return C.ulonglong(allocStyle(style))
|
|
141
|
+
}
|
|
142
|
+
|
|
123
143
|
//export lipgloss_style_border_top
|
|
124
144
|
func lipgloss_style_border_top(id C.ulonglong, value C.int) C.ulonglong {
|
|
125
145
|
style := getStyle(uint64(id)).BorderTop(value != 0)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/lipgloss/color.rb
CHANGED
|
@@ -7,6 +7,42 @@ module Lipgloss
|
|
|
7
7
|
# type complete_color_hash = { true_color: String, ansi256: String, ansi: String }
|
|
8
8
|
# type complete_adaptive_color_hash = { light: complete_color_hash, dark: complete_color_hash }
|
|
9
9
|
|
|
10
|
+
module ANSIColor
|
|
11
|
+
# @rbs!
|
|
12
|
+
# type ansi_color_symbol = :black | :red | :green | :yellow | :blue | :magenta | :cyan | :white | :bright_black | :bright_red | :bright_green | :bright_yellow | :bright_blue | :bright_magenta | :bright_cyan | :bright_white
|
|
13
|
+
# type ansi_color_value = ansi_color_symbol | Symbol | String | Integer
|
|
14
|
+
|
|
15
|
+
COLORS = {
|
|
16
|
+
black: "0",
|
|
17
|
+
red: "1",
|
|
18
|
+
green: "2",
|
|
19
|
+
yellow: "3",
|
|
20
|
+
blue: "4",
|
|
21
|
+
magenta: "5",
|
|
22
|
+
cyan: "6",
|
|
23
|
+
white: "7",
|
|
24
|
+
bright_black: "8",
|
|
25
|
+
bright_red: "9",
|
|
26
|
+
bright_green: "10",
|
|
27
|
+
bright_yellow: "11",
|
|
28
|
+
bright_blue: "12",
|
|
29
|
+
bright_magenta: "13",
|
|
30
|
+
bright_cyan: "14",
|
|
31
|
+
bright_white: "15"
|
|
32
|
+
}.freeze #: Hash[Symbol, String]
|
|
33
|
+
|
|
34
|
+
# @rbs value: ansi_color_value
|
|
35
|
+
# @rbs return: String
|
|
36
|
+
def self.resolve(value)
|
|
37
|
+
case value
|
|
38
|
+
when Symbol then COLORS.fetch(value) { raise ArgumentError, "Unknown ANSI color: #{value.inspect}" }
|
|
39
|
+
when String then value
|
|
40
|
+
when Integer then value.to_s
|
|
41
|
+
else raise ArgumentError, "ANSI color must be a Symbol, String, or Integer, got #{value.class}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
10
46
|
# Adaptive color that changes based on terminal background
|
|
11
47
|
#
|
|
12
48
|
# @example
|
|
@@ -38,8 +74,8 @@ module Lipgloss
|
|
|
38
74
|
# @example
|
|
39
75
|
# color = Lipgloss::CompleteColor.new(
|
|
40
76
|
# true_color: "#0000FF",
|
|
41
|
-
# ansi256:
|
|
42
|
-
# ansi:
|
|
77
|
+
# ansi256: 21,
|
|
78
|
+
# ansi: :blue
|
|
43
79
|
# )
|
|
44
80
|
class CompleteColor
|
|
45
81
|
# @rbs @true_color: String
|
|
@@ -51,13 +87,13 @@ module Lipgloss
|
|
|
51
87
|
attr_reader :ansi #: String
|
|
52
88
|
|
|
53
89
|
# @rbs true_color: String -- 24-bit color (e.g., "#0000FF")
|
|
54
|
-
# @rbs ansi256:
|
|
55
|
-
# @rbs ansi:
|
|
90
|
+
# @rbs ansi256: ANSIColor::ansi_color_value -- 8-bit ANSI color (0-255, or symbol for 0-15)
|
|
91
|
+
# @rbs ansi: ANSIColor::ansi_color_value -- 4-bit ANSI color (:red, :blue, etc., or 0-15)
|
|
56
92
|
# @rbs return: void
|
|
57
93
|
def initialize(true_color:, ansi256:, ansi:)
|
|
58
94
|
@true_color = true_color
|
|
59
|
-
@ansi256 = ansi256
|
|
60
|
-
@ansi = ansi
|
|
95
|
+
@ansi256 = ANSIColor.resolve(ansi256)
|
|
96
|
+
@ansi = ANSIColor.resolve(ansi)
|
|
61
97
|
end
|
|
62
98
|
|
|
63
99
|
# @rbs return: complete_color_hash
|
|
@@ -71,8 +107,8 @@ module Lipgloss
|
|
|
71
107
|
#
|
|
72
108
|
# @example
|
|
73
109
|
# color = Lipgloss::CompleteAdaptiveColor.new(
|
|
74
|
-
# light: Lipgloss::CompleteColor.new(true_color: "#000", ansi256:
|
|
75
|
-
# dark: Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256:
|
|
110
|
+
# light: Lipgloss::CompleteColor.new(true_color: "#000", ansi256: :black, ansi: :black),
|
|
111
|
+
# dark: Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256: :bright_white, ansi: :bright_white)
|
|
76
112
|
# )
|
|
77
113
|
class CompleteAdaptiveColor
|
|
78
114
|
# @rbs @light: CompleteColor
|
data/lib/lipgloss/position.rb
CHANGED
|
@@ -23,5 +23,28 @@ module Lipgloss
|
|
|
23
23
|
|
|
24
24
|
# Center alignment (0.5)
|
|
25
25
|
CENTER = 0.5
|
|
26
|
+
|
|
27
|
+
# @rbs!
|
|
28
|
+
# type position_symbol = :top | :bottom | :left | :right | :center
|
|
29
|
+
# type position_value = position_symbol | Symbol | String | Integer | Float
|
|
30
|
+
|
|
31
|
+
SYMBOLS = {
|
|
32
|
+
top: TOP,
|
|
33
|
+
bottom: BOTTOM,
|
|
34
|
+
left: LEFT,
|
|
35
|
+
right: RIGHT,
|
|
36
|
+
center: CENTER
|
|
37
|
+
}.freeze #: Hash[Symbol, Float]
|
|
38
|
+
|
|
39
|
+
# @rbs value: position_value
|
|
40
|
+
# @rbs return: Float
|
|
41
|
+
def self.resolve(value)
|
|
42
|
+
case value
|
|
43
|
+
when Symbol then SYMBOLS.fetch(value) { raise ArgumentError, "Unknown position: #{value.inspect}" }
|
|
44
|
+
when String then SYMBOLS.fetch(value.to_sym) { raise ArgumentError, "Unknown position: #{value.inspect}" }
|
|
45
|
+
when Numeric then value.to_f
|
|
46
|
+
else raise ArgumentError, "Position must be a Symbol or Numeric, got #{value.class}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
26
49
|
end
|
|
27
50
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Lipgloss
|
|
5
|
+
class Style
|
|
6
|
+
# @rbs *positions: Position::position_value
|
|
7
|
+
# @rbs return: Style
|
|
8
|
+
def align(*positions)
|
|
9
|
+
_align(*positions.map { |p| Position.resolve(p) })
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @rbs position: Position::position_value
|
|
13
|
+
# @rbs return: Style
|
|
14
|
+
def align_horizontal(position)
|
|
15
|
+
_align_horizontal(Position.resolve(position))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @rbs position: Position::position_value
|
|
19
|
+
# @rbs return: Style
|
|
20
|
+
def align_vertical(position)
|
|
21
|
+
_align_vertical(Position.resolve(position))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/lipgloss/version.rb
CHANGED
data/lib/lipgloss.rb
CHANGED
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
# rbs_inline: enabled
|
|
3
3
|
|
|
4
4
|
require_relative "lipgloss/version"
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
major, minor, _patch = RUBY_VERSION.split(".") #: [String, String, String]
|
|
8
|
+
require_relative "lipgloss/#{major}.#{minor}/lipgloss"
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require_relative "lipgloss/lipgloss"
|
|
11
|
+
end
|
|
12
|
+
|
|
6
13
|
require_relative "lipgloss/position"
|
|
7
14
|
require_relative "lipgloss/border"
|
|
8
15
|
require_relative "lipgloss/color"
|
|
16
|
+
require_relative "lipgloss/style"
|
|
9
17
|
require_relative "lipgloss/table"
|
|
10
18
|
|
|
11
19
|
module Lipgloss
|
|
@@ -24,4 +32,46 @@ module Lipgloss
|
|
|
24
32
|
ASCII_BORDER = Border::ASCII #: Symbol
|
|
25
33
|
|
|
26
34
|
NO_TAB_CONVERSION = -1 #: Integer
|
|
35
|
+
|
|
36
|
+
class << self
|
|
37
|
+
# @rbs position: Position::position_value
|
|
38
|
+
# @rbs *strings: String
|
|
39
|
+
# @rbs return: String
|
|
40
|
+
def join_horizontal(position, *strings)
|
|
41
|
+
_join_horizontal(Position.resolve(position), strings)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs position: Position::position_value
|
|
45
|
+
# @rbs *strings: String
|
|
46
|
+
# @rbs return: String
|
|
47
|
+
def join_vertical(position, *strings)
|
|
48
|
+
_join_vertical(Position.resolve(position), strings)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @rbs width: Integer
|
|
52
|
+
# @rbs height: Integer
|
|
53
|
+
# @rbs horizontal: Position::position_value
|
|
54
|
+
# @rbs vertical: Position::position_value
|
|
55
|
+
# @rbs string: String
|
|
56
|
+
# @rbs return: String
|
|
57
|
+
def place(width, height, horizontal, vertical, string, **opts)
|
|
58
|
+
_place(width, height, Position.resolve(horizontal), Position.resolve(vertical), string, **opts)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @rbs width: Integer
|
|
62
|
+
# @rbs position: Position::position_value
|
|
63
|
+
# @rbs string: String
|
|
64
|
+
# @rbs return: String
|
|
65
|
+
def place_horizontal(width, position, string)
|
|
66
|
+
_place_horizontal(width, Position.resolve(position), string)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @rbs height: Integer
|
|
70
|
+
# @rbs position: Position::position_value
|
|
71
|
+
# @rbs string: String
|
|
72
|
+
# @rbs return: String
|
|
73
|
+
def place_vertical(height, position, string)
|
|
74
|
+
_place_vertical(height, Position.resolve(position), string)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
27
77
|
end
|
data/lipgloss.gemspec
CHANGED
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
|
8
8
|
spec.authors = ["Marco Roth"]
|
|
9
9
|
spec.email = ["marco.roth@intergga.ch"]
|
|
10
10
|
|
|
11
|
-
spec.summary = "Ruby wrapper for Charm's lipgloss CSS-like terminal styling library."
|
|
12
|
-
spec.description =
|
|
11
|
+
spec.summary = "Ruby wrapper for Charm's lipgloss. CSS-like terminal styling library."
|
|
12
|
+
spec.description = "Style Definitions for Nice Terminal Layouts. Built with TUIs in mind."
|
|
13
13
|
spec.homepage = "https://github.com/marcoroth/lipgloss-ruby"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
spec.required_ruby_version = ">= 3.2.0"
|