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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static VALUE style_unset_bold(VALUE self) {
|
|
4
|
+
GET_STYLE(self, style);
|
|
5
|
+
unsigned long long new_handle = lipgloss_style_unset_bold(style->handle);
|
|
6
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static VALUE style_unset_italic(VALUE self) {
|
|
10
|
+
GET_STYLE(self, style);
|
|
11
|
+
unsigned long long new_handle = lipgloss_style_unset_italic(style->handle);
|
|
12
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static VALUE style_unset_underline(VALUE self) {
|
|
16
|
+
GET_STYLE(self, style);
|
|
17
|
+
unsigned long long new_handle = lipgloss_style_unset_underline(style->handle);
|
|
18
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static VALUE style_unset_strikethrough(VALUE self) {
|
|
22
|
+
GET_STYLE(self, style);
|
|
23
|
+
unsigned long long new_handle = lipgloss_style_unset_strikethrough(style->handle);
|
|
24
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static VALUE style_unset_reverse(VALUE self) {
|
|
28
|
+
GET_STYLE(self, style);
|
|
29
|
+
unsigned long long new_handle = lipgloss_style_unset_reverse(style->handle);
|
|
30
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static VALUE style_unset_blink(VALUE self) {
|
|
34
|
+
GET_STYLE(self, style);
|
|
35
|
+
unsigned long long new_handle = lipgloss_style_unset_blink(style->handle);
|
|
36
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static VALUE style_unset_faint(VALUE self) {
|
|
40
|
+
GET_STYLE(self, style);
|
|
41
|
+
unsigned long long new_handle = lipgloss_style_unset_faint(style->handle);
|
|
42
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static VALUE style_unset_foreground(VALUE self) {
|
|
46
|
+
GET_STYLE(self, style);
|
|
47
|
+
unsigned long long new_handle = lipgloss_style_unset_foreground(style->handle);
|
|
48
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static VALUE style_unset_background(VALUE self) {
|
|
52
|
+
GET_STYLE(self, style);
|
|
53
|
+
unsigned long long new_handle = lipgloss_style_unset_background(style->handle);
|
|
54
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static VALUE style_unset_width(VALUE self) {
|
|
58
|
+
GET_STYLE(self, style);
|
|
59
|
+
unsigned long long new_handle = lipgloss_style_unset_width(style->handle);
|
|
60
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE style_unset_height(VALUE self) {
|
|
64
|
+
GET_STYLE(self, style);
|
|
65
|
+
unsigned long long new_handle = lipgloss_style_unset_height(style->handle);
|
|
66
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static VALUE style_unset_padding_top(VALUE self) {
|
|
70
|
+
GET_STYLE(self, style);
|
|
71
|
+
unsigned long long new_handle = lipgloss_style_unset_padding_top(style->handle);
|
|
72
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static VALUE style_unset_padding_right(VALUE self) {
|
|
76
|
+
GET_STYLE(self, style);
|
|
77
|
+
unsigned long long new_handle = lipgloss_style_unset_padding_right(style->handle);
|
|
78
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static VALUE style_unset_padding_bottom(VALUE self) {
|
|
82
|
+
GET_STYLE(self, style);
|
|
83
|
+
unsigned long long new_handle = lipgloss_style_unset_padding_bottom(style->handle);
|
|
84
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static VALUE style_unset_padding_left(VALUE self) {
|
|
88
|
+
GET_STYLE(self, style);
|
|
89
|
+
unsigned long long new_handle = lipgloss_style_unset_padding_left(style->handle);
|
|
90
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static VALUE style_unset_margin_top(VALUE self) {
|
|
94
|
+
GET_STYLE(self, style);
|
|
95
|
+
unsigned long long new_handle = lipgloss_style_unset_margin_top(style->handle);
|
|
96
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static VALUE style_unset_margin_right(VALUE self) {
|
|
100
|
+
GET_STYLE(self, style);
|
|
101
|
+
unsigned long long new_handle = lipgloss_style_unset_margin_right(style->handle);
|
|
102
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static VALUE style_unset_margin_bottom(VALUE self) {
|
|
106
|
+
GET_STYLE(self, style);
|
|
107
|
+
unsigned long long new_handle = lipgloss_style_unset_margin_bottom(style->handle);
|
|
108
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static VALUE style_unset_margin_left(VALUE self) {
|
|
112
|
+
GET_STYLE(self, style);
|
|
113
|
+
unsigned long long new_handle = lipgloss_style_unset_margin_left(style->handle);
|
|
114
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static VALUE style_unset_border_style(VALUE self) {
|
|
118
|
+
GET_STYLE(self, style);
|
|
119
|
+
unsigned long long new_handle = lipgloss_style_unset_border_style(style->handle);
|
|
120
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static VALUE style_unset_inline(VALUE self) {
|
|
124
|
+
GET_STYLE(self, style);
|
|
125
|
+
unsigned long long new_handle = lipgloss_style_unset_inline(style->handle);
|
|
126
|
+
return style_wrap(rb_class_of(self), new_handle);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
void register_style_unset_methods(void) {
|
|
130
|
+
rb_define_method(cStyle, "unset_bold", style_unset_bold, 0);
|
|
131
|
+
rb_define_method(cStyle, "unset_italic", style_unset_italic, 0);
|
|
132
|
+
rb_define_method(cStyle, "unset_underline", style_unset_underline, 0);
|
|
133
|
+
rb_define_method(cStyle, "unset_strikethrough", style_unset_strikethrough, 0);
|
|
134
|
+
rb_define_method(cStyle, "unset_reverse", style_unset_reverse, 0);
|
|
135
|
+
rb_define_method(cStyle, "unset_blink", style_unset_blink, 0);
|
|
136
|
+
rb_define_method(cStyle, "unset_faint", style_unset_faint, 0);
|
|
137
|
+
rb_define_method(cStyle, "unset_foreground", style_unset_foreground, 0);
|
|
138
|
+
rb_define_method(cStyle, "unset_background", style_unset_background, 0);
|
|
139
|
+
rb_define_method(cStyle, "unset_width", style_unset_width, 0);
|
|
140
|
+
rb_define_method(cStyle, "unset_height", style_unset_height, 0);
|
|
141
|
+
rb_define_method(cStyle, "unset_padding_top", style_unset_padding_top, 0);
|
|
142
|
+
rb_define_method(cStyle, "unset_padding_right", style_unset_padding_right, 0);
|
|
143
|
+
rb_define_method(cStyle, "unset_padding_bottom", style_unset_padding_bottom, 0);
|
|
144
|
+
rb_define_method(cStyle, "unset_padding_left", style_unset_padding_left, 0);
|
|
145
|
+
rb_define_method(cStyle, "unset_margin_top", style_unset_margin_top, 0);
|
|
146
|
+
rb_define_method(cStyle, "unset_margin_right", style_unset_margin_right, 0);
|
|
147
|
+
rb_define_method(cStyle, "unset_margin_bottom", style_unset_margin_bottom, 0);
|
|
148
|
+
rb_define_method(cStyle, "unset_margin_left", style_unset_margin_left, 0);
|
|
149
|
+
rb_define_method(cStyle, "unset_border_style", style_unset_border_style, 0);
|
|
150
|
+
rb_define_method(cStyle, "unset_inline", style_unset_inline, 0);
|
|
151
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void table_free(void *pointer) {
|
|
4
|
+
lipgloss_table_t *table = (lipgloss_table_t *) pointer;
|
|
5
|
+
|
|
6
|
+
if (table->handle != 0) {
|
|
7
|
+
lipgloss_table_free(table->handle);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
xfree(table);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static size_t table_memsize(const void *pointer) {
|
|
14
|
+
return sizeof(lipgloss_table_t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rb_data_type_t table_type = {
|
|
18
|
+
.wrap_struct_name = "Lipgloss::Table",
|
|
19
|
+
.function = {
|
|
20
|
+
.dmark = NULL,
|
|
21
|
+
.dfree = table_free,
|
|
22
|
+
.dsize = table_memsize,
|
|
23
|
+
},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static VALUE table_alloc(VALUE klass) {
|
|
28
|
+
lipgloss_table_t *table = ALLOC(lipgloss_table_t);
|
|
29
|
+
table->handle = lipgloss_table_new();
|
|
30
|
+
return TypedData_Wrap_Struct(klass, &table_type, table);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
VALUE table_wrap(VALUE klass, unsigned long long handle) {
|
|
34
|
+
lipgloss_table_t *table = ALLOC(lipgloss_table_t);
|
|
35
|
+
table->handle = handle;
|
|
36
|
+
return TypedData_Wrap_Struct(klass, &table_type, table);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static VALUE table_initialize(VALUE self) {
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static VALUE table_headers(VALUE self, VALUE headers) {
|
|
44
|
+
GET_TABLE(self, table);
|
|
45
|
+
Check_Type(headers, T_ARRAY);
|
|
46
|
+
|
|
47
|
+
VALUE json_str = rb_funcall(headers, rb_intern("to_json"), 0);
|
|
48
|
+
unsigned long long new_handle = lipgloss_table_headers(table->handle, StringValueCStr(json_str));
|
|
49
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static VALUE table_row(VALUE self, VALUE row) {
|
|
53
|
+
GET_TABLE(self, table);
|
|
54
|
+
Check_Type(row, T_ARRAY);
|
|
55
|
+
|
|
56
|
+
VALUE json_str = rb_funcall(row, rb_intern("to_json"), 0);
|
|
57
|
+
unsigned long long new_handle = lipgloss_table_row(table->handle, StringValueCStr(json_str));
|
|
58
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static VALUE table_rows(VALUE self, VALUE rows) {
|
|
62
|
+
GET_TABLE(self, table);
|
|
63
|
+
Check_Type(rows, T_ARRAY);
|
|
64
|
+
|
|
65
|
+
VALUE json_str = rb_funcall(rows, rb_intern("to_json"), 0);
|
|
66
|
+
unsigned long long new_handle = lipgloss_table_rows(table->handle, StringValueCStr(json_str));
|
|
67
|
+
|
|
68
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static int symbol_to_table_border_type(VALUE symbol) {
|
|
72
|
+
if (symbol == ID2SYM(rb_intern("normal"))) return BORDER_NORMAL;
|
|
73
|
+
if (symbol == ID2SYM(rb_intern("rounded"))) return BORDER_ROUNDED;
|
|
74
|
+
if (symbol == ID2SYM(rb_intern("thick"))) return BORDER_THICK;
|
|
75
|
+
if (symbol == ID2SYM(rb_intern("double"))) return BORDER_DOUBLE;
|
|
76
|
+
if (symbol == ID2SYM(rb_intern("hidden"))) return BORDER_HIDDEN;
|
|
77
|
+
if (symbol == ID2SYM(rb_intern("block"))) return BORDER_BLOCK;
|
|
78
|
+
if (symbol == ID2SYM(rb_intern("outer_half_block"))) return BORDER_OUTER_HALF_BLOCK;
|
|
79
|
+
if (symbol == ID2SYM(rb_intern("inner_half_block"))) return BORDER_INNER_HALF_BLOCK;
|
|
80
|
+
if (symbol == ID2SYM(rb_intern("ascii"))) return BORDER_ASCII;
|
|
81
|
+
if (symbol == ID2SYM(rb_intern("markdown"))) return BORDER_MARKDOWN;
|
|
82
|
+
|
|
83
|
+
return BORDER_NORMAL;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static VALUE table_border(VALUE self, VALUE border_sym) {
|
|
87
|
+
GET_TABLE(self, table);
|
|
88
|
+
int border_type = symbol_to_table_border_type(border_sym);
|
|
89
|
+
unsigned long long new_handle = lipgloss_table_border(table->handle, border_type);
|
|
90
|
+
|
|
91
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static VALUE table_border_style(VALUE self, VALUE style_object) {
|
|
95
|
+
GET_TABLE(self, table);
|
|
96
|
+
lipgloss_style_t *style;
|
|
97
|
+
|
|
98
|
+
TypedData_Get_Struct(style_object, lipgloss_style_t, &style_type, style);
|
|
99
|
+
unsigned long long new_handle = lipgloss_table_border_style(table->handle, style->handle);
|
|
100
|
+
|
|
101
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static VALUE table_border_top(VALUE self, VALUE value) {
|
|
105
|
+
GET_TABLE(self, table);
|
|
106
|
+
unsigned long long new_handle = lipgloss_table_border_top(table->handle, RTEST(value) ? 1 : 0);
|
|
107
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static VALUE table_border_bottom(VALUE self, VALUE value) {
|
|
111
|
+
GET_TABLE(self, table);
|
|
112
|
+
unsigned long long new_handle = lipgloss_table_border_bottom(table->handle, RTEST(value) ? 1 : 0);
|
|
113
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static VALUE table_border_left(VALUE self, VALUE value) {
|
|
117
|
+
GET_TABLE(self, table);
|
|
118
|
+
unsigned long long new_handle = lipgloss_table_border_left(table->handle, RTEST(value) ? 1 : 0);
|
|
119
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE table_border_right(VALUE self, VALUE value) {
|
|
123
|
+
GET_TABLE(self, table);
|
|
124
|
+
unsigned long long new_handle = lipgloss_table_border_right(table->handle, RTEST(value) ? 1 : 0);
|
|
125
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static VALUE table_border_header(VALUE self, VALUE value) {
|
|
129
|
+
GET_TABLE(self, table);
|
|
130
|
+
unsigned long long new_handle = lipgloss_table_border_header(table->handle, RTEST(value) ? 1 : 0);
|
|
131
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static VALUE table_border_column(VALUE self, VALUE value) {
|
|
135
|
+
GET_TABLE(self, table);
|
|
136
|
+
unsigned long long new_handle = lipgloss_table_border_column(table->handle, RTEST(value) ? 1 : 0);
|
|
137
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static VALUE table_border_row_m(VALUE self, VALUE value) {
|
|
141
|
+
GET_TABLE(self, table);
|
|
142
|
+
unsigned long long new_handle = lipgloss_table_border_row(table->handle, RTEST(value) ? 1 : 0);
|
|
143
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static VALUE table_width(VALUE self, VALUE width) {
|
|
147
|
+
GET_TABLE(self, table);
|
|
148
|
+
unsigned long long new_handle = lipgloss_table_width(table->handle, NUM2INT(width));
|
|
149
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
static VALUE table_height(VALUE self, VALUE height) {
|
|
153
|
+
GET_TABLE(self, table);
|
|
154
|
+
unsigned long long new_handle = lipgloss_table_height(table->handle, NUM2INT(height));
|
|
155
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static VALUE table_offset(VALUE self, VALUE offset) {
|
|
159
|
+
GET_TABLE(self, table);
|
|
160
|
+
unsigned long long new_handle = lipgloss_table_offset(table->handle, NUM2INT(offset));
|
|
161
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
static VALUE table_wrap_m(VALUE self, VALUE value) {
|
|
165
|
+
GET_TABLE(self, table);
|
|
166
|
+
unsigned long long new_handle = lipgloss_table_wrap(table->handle, RTEST(value) ? 1 : 0);
|
|
167
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static VALUE table_clear_rows(VALUE self) {
|
|
171
|
+
GET_TABLE(self, table);
|
|
172
|
+
unsigned long long new_handle = lipgloss_table_clear_rows(table->handle);
|
|
173
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static VALUE table_render(VALUE self) {
|
|
177
|
+
GET_TABLE(self, table);
|
|
178
|
+
char *result = lipgloss_table_render(table->handle);
|
|
179
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
180
|
+
|
|
181
|
+
lipgloss_free(result);
|
|
182
|
+
|
|
183
|
+
return rb_result;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static VALUE table_to_s(VALUE self) {
|
|
187
|
+
return table_render(self);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Apply a pre-computed style map: { "row,col" => style_handle, ... }
|
|
191
|
+
static VALUE table_style_func_map(VALUE self, VALUE style_map) {
|
|
192
|
+
GET_TABLE(self, table);
|
|
193
|
+
Check_Type(style_map, T_HASH);
|
|
194
|
+
|
|
195
|
+
VALUE json_hash = rb_hash_new();
|
|
196
|
+
VALUE keys = rb_funcall(style_map, rb_intern("keys"), 0);
|
|
197
|
+
|
|
198
|
+
long length = RARRAY_LEN(keys);
|
|
199
|
+
|
|
200
|
+
for (long index = 0; index < length; index++) {
|
|
201
|
+
VALUE key = rb_ary_entry(keys, index);
|
|
202
|
+
VALUE style_object = rb_hash_aref(style_map, key);
|
|
203
|
+
|
|
204
|
+
lipgloss_style_t *style;
|
|
205
|
+
TypedData_Get_Struct(style_object, lipgloss_style_t, &style_type, style);
|
|
206
|
+
|
|
207
|
+
rb_hash_aset(json_hash, key, ULL2NUM(style->handle));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
VALUE json_str = rb_funcall(json_hash, rb_intern("to_json"), 0);
|
|
211
|
+
unsigned long long new_handle = lipgloss_table_style_func(table->handle, StringValueCStr(json_str));
|
|
212
|
+
|
|
213
|
+
return table_wrap(rb_class_of(self), new_handle);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void Init_lipgloss_table(void) {
|
|
217
|
+
cTable = rb_define_class_under(mLipgloss, "Table", rb_cObject);
|
|
218
|
+
|
|
219
|
+
rb_define_alloc_func(cTable, table_alloc);
|
|
220
|
+
|
|
221
|
+
rb_define_method(cTable, "initialize", table_initialize, 0);
|
|
222
|
+
rb_define_method(cTable, "headers", table_headers, 1);
|
|
223
|
+
rb_define_method(cTable, "row", table_row, 1);
|
|
224
|
+
rb_define_method(cTable, "rows", table_rows, 1);
|
|
225
|
+
rb_define_method(cTable, "border", table_border, 1);
|
|
226
|
+
rb_define_method(cTable, "border_style", table_border_style, 1);
|
|
227
|
+
rb_define_method(cTable, "border_top", table_border_top, 1);
|
|
228
|
+
rb_define_method(cTable, "border_bottom", table_border_bottom, 1);
|
|
229
|
+
rb_define_method(cTable, "border_left", table_border_left, 1);
|
|
230
|
+
rb_define_method(cTable, "border_right", table_border_right, 1);
|
|
231
|
+
rb_define_method(cTable, "border_header", table_border_header, 1);
|
|
232
|
+
rb_define_method(cTable, "border_column", table_border_column, 1);
|
|
233
|
+
rb_define_method(cTable, "border_row", table_border_row_m, 1);
|
|
234
|
+
rb_define_method(cTable, "width", table_width, 1);
|
|
235
|
+
rb_define_method(cTable, "height", table_height, 1);
|
|
236
|
+
rb_define_method(cTable, "offset", table_offset, 1);
|
|
237
|
+
rb_define_method(cTable, "wrap", table_wrap_m, 1);
|
|
238
|
+
rb_define_method(cTable, "clear_rows", table_clear_rows, 0);
|
|
239
|
+
rb_define_method(cTable, "_style_func_map", table_style_func_map, 1);
|
|
240
|
+
rb_define_method(cTable, "render", table_render, 0);
|
|
241
|
+
rb_define_method(cTable, "to_s", table_to_s, 0);
|
|
242
|
+
}
|
data/ext/lipgloss/tree.c
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#include "extension.h"
|
|
2
|
+
|
|
3
|
+
static void tree_free(void *pointer) {
|
|
4
|
+
lipgloss_tree_t *tree = (lipgloss_tree_t *) pointer;
|
|
5
|
+
|
|
6
|
+
if (tree->handle != 0) {
|
|
7
|
+
lipgloss_tree_free(tree->handle);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
xfree(tree);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static size_t tree_memsize(const void *pointer) {
|
|
14
|
+
return sizeof(lipgloss_tree_t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const rb_data_type_t tree_type = {
|
|
18
|
+
.wrap_struct_name = "Lipgloss::Tree",
|
|
19
|
+
.function = {
|
|
20
|
+
.dmark = NULL,
|
|
21
|
+
.dfree = tree_free,
|
|
22
|
+
.dsize = tree_memsize,
|
|
23
|
+
},
|
|
24
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static VALUE tree_alloc(VALUE klass) {
|
|
28
|
+
lipgloss_tree_t *tree = ALLOC(lipgloss_tree_t);
|
|
29
|
+
tree->handle = lipgloss_tree_new();
|
|
30
|
+
|
|
31
|
+
return TypedData_Wrap_Struct(klass, &tree_type, tree);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
VALUE tree_wrap_handle(VALUE klass, unsigned long long handle) {
|
|
35
|
+
lipgloss_tree_t *tree = ALLOC(lipgloss_tree_t);
|
|
36
|
+
tree->handle = handle;
|
|
37
|
+
|
|
38
|
+
return TypedData_Wrap_Struct(klass, &tree_type, tree);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static VALUE tree_initialize(int argc, VALUE *argv, VALUE self) {
|
|
42
|
+
if (argc == 1) {
|
|
43
|
+
GET_TREE(self, tree);
|
|
44
|
+
VALUE root = argv[0];
|
|
45
|
+
Check_Type(root, T_STRING);
|
|
46
|
+
tree->handle = lipgloss_tree_set_root(tree->handle, StringValueCStr(root));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static VALUE tree_root_m(VALUE klass, VALUE root) {
|
|
53
|
+
Check_Type(root, T_STRING);
|
|
54
|
+
unsigned long long handle = lipgloss_tree_root(StringValueCStr(root));
|
|
55
|
+
|
|
56
|
+
return tree_wrap_handle(klass, handle);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static VALUE tree_set_root(VALUE self, VALUE root) {
|
|
60
|
+
GET_TREE(self, tree);
|
|
61
|
+
Check_Type(root, T_STRING);
|
|
62
|
+
unsigned long long new_handle = lipgloss_tree_set_root(tree->handle, StringValueCStr(root));
|
|
63
|
+
|
|
64
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static VALUE tree_child(int argc, VALUE *argv, VALUE self) {
|
|
68
|
+
GET_TREE(self, tree);
|
|
69
|
+
|
|
70
|
+
if (argc == 0) {
|
|
71
|
+
rb_raise(rb_eArgError, "wrong number of arguments (given 0, expected 1+)");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
VALUE result = self;
|
|
75
|
+
for (int index = 0; index < argc; index++) {
|
|
76
|
+
lipgloss_tree_t *current;
|
|
77
|
+
TypedData_Get_Struct(result, lipgloss_tree_t, &tree_type, current);
|
|
78
|
+
|
|
79
|
+
VALUE child = argv[index];
|
|
80
|
+
|
|
81
|
+
if (rb_obj_is_kind_of(child, cTree)) {
|
|
82
|
+
lipgloss_tree_t *subtree;
|
|
83
|
+
TypedData_Get_Struct(child, lipgloss_tree_t, &tree_type, subtree);
|
|
84
|
+
unsigned long long new_handle = lipgloss_tree_child_tree(current->handle, subtree->handle);
|
|
85
|
+
result = tree_wrap_handle(rb_class_of(self), new_handle);
|
|
86
|
+
} else {
|
|
87
|
+
Check_Type(child, T_STRING);
|
|
88
|
+
unsigned long long new_handle = lipgloss_tree_child(current->handle, StringValueCStr(child));
|
|
89
|
+
result = tree_wrap_handle(rb_class_of(self), new_handle);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static VALUE tree_children(VALUE self, VALUE children) {
|
|
97
|
+
GET_TREE(self, tree);
|
|
98
|
+
Check_Type(children, T_ARRAY);
|
|
99
|
+
|
|
100
|
+
VALUE json_str = rb_funcall(children, rb_intern("to_json"), 0);
|
|
101
|
+
unsigned long long new_handle = lipgloss_tree_children(tree->handle, StringValueCStr(json_str));
|
|
102
|
+
|
|
103
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#define TREE_ENUMERATOR_DEFAULT 0
|
|
107
|
+
#define TREE_ENUMERATOR_ROUNDED 1
|
|
108
|
+
|
|
109
|
+
static int symbol_to_tree_enumerator(VALUE symbol) {
|
|
110
|
+
if (symbol == ID2SYM(rb_intern("default"))) return TREE_ENUMERATOR_DEFAULT;
|
|
111
|
+
if (symbol == ID2SYM(rb_intern("rounded"))) return TREE_ENUMERATOR_ROUNDED;
|
|
112
|
+
|
|
113
|
+
return TREE_ENUMERATOR_DEFAULT;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static VALUE tree_enumerator(VALUE self, VALUE enum_symbol) {
|
|
117
|
+
GET_TREE(self, tree);
|
|
118
|
+
int enum_type = symbol_to_tree_enumerator(enum_symbol);
|
|
119
|
+
unsigned long long new_handle = lipgloss_tree_enumerator(tree->handle, enum_type);
|
|
120
|
+
|
|
121
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static VALUE tree_enumerator_style(VALUE self, VALUE style_object) {
|
|
125
|
+
GET_TREE(self, tree);
|
|
126
|
+
lipgloss_style_t *style;
|
|
127
|
+
|
|
128
|
+
TypedData_Get_Struct(style_object, lipgloss_style_t, &style_type, style);
|
|
129
|
+
unsigned long long new_handle = lipgloss_tree_enumerator_style(tree->handle, style->handle);
|
|
130
|
+
|
|
131
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static VALUE tree_item_style(VALUE self, VALUE style_object) {
|
|
135
|
+
GET_TREE(self, tree);
|
|
136
|
+
lipgloss_style_t *style;
|
|
137
|
+
|
|
138
|
+
TypedData_Get_Struct(style_object, lipgloss_style_t, &style_type, style);
|
|
139
|
+
unsigned long long new_handle = lipgloss_tree_item_style(tree->handle, style->handle);
|
|
140
|
+
|
|
141
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static VALUE tree_root_style(VALUE self, VALUE style_object) {
|
|
145
|
+
GET_TREE(self, tree);
|
|
146
|
+
lipgloss_style_t *style;
|
|
147
|
+
|
|
148
|
+
TypedData_Get_Struct(style_object, lipgloss_style_t, &style_type, style);
|
|
149
|
+
unsigned long long new_handle = lipgloss_tree_root_style(tree->handle, style->handle);
|
|
150
|
+
|
|
151
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static VALUE tree_offset(VALUE self, VALUE start, VALUE end) {
|
|
155
|
+
GET_TREE(self, tree);
|
|
156
|
+
unsigned long long new_handle = lipgloss_tree_offset(tree->handle, NUM2INT(start), NUM2INT(end));
|
|
157
|
+
|
|
158
|
+
return tree_wrap_handle(rb_class_of(self), new_handle);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
static VALUE tree_render(VALUE self) {
|
|
162
|
+
GET_TREE(self, tree);
|
|
163
|
+
char *result = lipgloss_tree_render(tree->handle);
|
|
164
|
+
VALUE rb_result = rb_utf8_str_new_cstr(result);
|
|
165
|
+
|
|
166
|
+
lipgloss_free(result);
|
|
167
|
+
|
|
168
|
+
return rb_result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static VALUE tree_to_s(VALUE self) {
|
|
172
|
+
return tree_render(self);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
void Init_lipgloss_tree(void) {
|
|
176
|
+
cTree = rb_define_class_under(mLipgloss, "Tree", rb_cObject);
|
|
177
|
+
|
|
178
|
+
rb_define_alloc_func(cTree, tree_alloc);
|
|
179
|
+
rb_define_singleton_method(cTree, "root", tree_root_m, 1);
|
|
180
|
+
|
|
181
|
+
rb_define_method(cTree, "initialize", tree_initialize, -1);
|
|
182
|
+
rb_define_method(cTree, "root=", tree_set_root, 1);
|
|
183
|
+
rb_define_method(cTree, "child", tree_child, -1);
|
|
184
|
+
rb_define_method(cTree, "children", tree_children, 1);
|
|
185
|
+
rb_define_method(cTree, "enumerator", tree_enumerator, 1);
|
|
186
|
+
rb_define_method(cTree, "enumerator_style", tree_enumerator_style, 1);
|
|
187
|
+
rb_define_method(cTree, "item_style", tree_item_style, 1);
|
|
188
|
+
rb_define_method(cTree, "root_style", tree_root_style, 1);
|
|
189
|
+
rb_define_method(cTree, "offset", tree_offset, 2);
|
|
190
|
+
rb_define_method(cTree, "render", tree_render, 0);
|
|
191
|
+
rb_define_method(cTree, "to_s", tree_to_s, 0);
|
|
192
|
+
}
|
data/go/go.mod
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module github.com/marcoroth/lipgloss-ruby/go
|
|
2
|
+
|
|
3
|
+
go 1.23.0
|
|
4
|
+
|
|
5
|
+
require github.com/charmbracelet/lipgloss v1.1.0
|
|
6
|
+
|
|
7
|
+
require (
|
|
8
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
|
9
|
+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
|
|
10
|
+
github.com/charmbracelet/x/ansi v0.8.0 // indirect
|
|
11
|
+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
|
|
12
|
+
github.com/charmbracelet/x/term v0.2.1 // indirect
|
|
13
|
+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
|
14
|
+
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
15
|
+
github.com/mattn/go-runewidth v0.0.16 // indirect
|
|
16
|
+
github.com/muesli/termenv v0.16.0 // indirect
|
|
17
|
+
github.com/rivo/uniseg v0.4.7 // indirect
|
|
18
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
|
19
|
+
golang.org/x/sys v0.30.0 // indirect
|
|
20
|
+
)
|
data/go/go.sum
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
|
2
|
+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
|
3
|
+
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
|
4
|
+
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
|
5
|
+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
|
|
6
|
+
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
|
|
7
|
+
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
|
|
8
|
+
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
|
|
9
|
+
github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
|
|
10
|
+
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
|
11
|
+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
|
|
12
|
+
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
|
|
13
|
+
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a h1:G99klV19u0QnhiizODirwVksQB91TJKV/UaTnACcG30=
|
|
14
|
+
github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
|
15
|
+
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
|
16
|
+
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
|
17
|
+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
|
18
|
+
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
|
19
|
+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
20
|
+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
|
21
|
+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
|
22
|
+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
|
23
|
+
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
|
24
|
+
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
|
25
|
+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
26
|
+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
|
27
|
+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
|
28
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
|
29
|
+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
|
30
|
+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
|
|
31
|
+
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
|
|
32
|
+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
33
|
+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
|
34
|
+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|