lipgloss 0.0.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26fcd053ad0cf7fd8973dd14bd9858ac8ed7b098234b5c90743c78f0fbd6e877
4
- data.tar.gz: 863a84b8de824a134508ee4629c62b6dcc5f4ed5f52fcc428004962fbaf75838
3
+ metadata.gz: 822cdc4a08be4d36feab181fe8933cf9486c1eba70935eca9d73eb6a573d47f1
4
+ data.tar.gz: 2ac7c9626a365e2747050dd8b2cd067ccad05992b4c063b3dbb3668eff6dbc10
5
5
  SHA512:
6
- metadata.gz: fb22bdaf2071ceb6c12bc58752d2526a850f38227359fd1ecfd641cf795a05a9f7e63ff86df6ffbbddcbe982e947d6912c8a2d3e9088c3bc1655a76e95613039
7
- data.tar.gz: '09e3ebe59c04153b0e4788040b5a48a3d73be80bd6837d1ecfbac7a1b63b19ee7af0899b04a99c9ed31a0fa23a6a86e8083b1cd34fb4491e8e31f35e2776885e'
6
+ metadata.gz: e1ee9fc15a1935945789032584bdac9fb983614e24daf66aca646593ae262dcc9cd395f4e5e74ebbe8589ab2f378245e07c660af66d2baf184451f4c843934ed
7
+ data.tar.gz: f67ac668b982e0f6f06ffa6b1c17031ea491a90df729cc2e9f655e0c0ba78b7217020e39adc940be4c0f9864c7f3418f995dd282ffa29996a4dd9609be4b2389
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Marco Roth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,39 +1,490 @@
1
- # Lipgloss
1
+ <div align="center">
2
+ <h1>Lipgloss for Ruby</h1>
3
+ <h4>Style Definitions for Nice Terminal Layouts</h4>
2
4
 
3
- TODO: Delete this and the text below, and describe your gem
5
+ <p>
6
+ <a href="https://rubygems.org/gems/lipgloss"><img alt="Gem Version" src="https://img.shields.io/gem/v/lipgloss"></a>
7
+ <a href="https://github.com/marcoroth/lipgloss-ruby/blob/main/LICENSE.txt"><img alt="License" src="https://img.shields.io/github/license/marcoroth/lipgloss-ruby"></a>
8
+ </p>
4
9
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lipgloss`. To experiment with that code, run `bin/console` for an interactive prompt.
10
+ <p>Ruby bindings for <a href="https://github.com/charmbracelet/lipgloss">charmbracelet/lipgloss</a>.<br/>Style definitions for nice terminal layouts. Built with TUIs in mind.</p>
11
+ </div>
6
12
 
7
13
  ## Installation
8
14
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
15
+ **Add to your Gemfile:**
10
16
 
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ ```ruby
18
+ gem "lipgloss"
15
19
  ```
16
20
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ **Or install directly:**
18
22
 
19
23
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ gem install lipgloss
21
25
  ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ### Basic Styling
30
+
31
+ **Create and render styled text:**
32
+
33
+ ```ruby
34
+ require "lipgloss"
35
+
36
+ style = Lipgloss::Style.new
37
+ .bold(true)
38
+ .foreground("#FAFAFA")
39
+ .background("#7D56F4")
40
+ .padding(1, 2)
41
+
42
+ puts style.render("Hello, Lipgloss!")
43
+ ```
44
+
45
+ **Reusable styles:**
46
+
47
+ ```ruby
48
+ heading = Lipgloss::Style.new
49
+ .bold(true)
50
+ .foreground("#FF6B6B")
51
+ .margin_bottom(1)
52
+
53
+ body = Lipgloss::Style.new
54
+ .width(40)
55
+ .align(:center)
56
+
57
+ puts heading.render("Welcome")
58
+ puts body.render("Styled terminal output")
59
+ ```
60
+
61
+ ### Borders
62
+
63
+ **Add borders to your content:**
64
+
65
+ ```ruby
66
+ box = Lipgloss::Style.new
67
+ .border(:rounded)
68
+ .border_foreground("#874BFD")
69
+ .padding(1, 2)
70
+
71
+ puts box.render("Boxed content")
72
+ ```
73
+
74
+ **Available border styles:**
75
+
76
+ | Style | Description |
77
+ |------------|-----------------------------------|
78
+ | `:normal` | Standard box drawing characters |
79
+ | `:rounded` | Rounded corners |
80
+ | `:thick` | Thick lines |
81
+ | `:double` | Double lines |
82
+ | `:hidden` | Hidden (spacing only) |
83
+ | `:block` | Block characters |
84
+ | `:ascii` | ASCII characters (`+`, `-`, `\|`) |
85
+
86
+ **Custom borders:**
87
+
88
+ ```ruby
89
+ style = Lipgloss::Style.new
90
+ .border_custom(
91
+ top: "~", bottom: "~",
92
+ left: "|", right: "|",
93
+ top_left: "+", top_right: "+",
94
+ bottom_left: "+", bottom_right: "+"
95
+ )
96
+
97
+ puts style.render("Custom border!")
98
+ ```
99
+
100
+ **Per-side border colors:**
101
+
102
+ ```ruby
103
+ style = Lipgloss::Style.new
104
+ .border(:rounded)
105
+ .border_top_foreground("#FF0000")
106
+ .border_right_foreground("#00FF00")
107
+ .border_bottom_foreground("#0000FF")
108
+ .border_left_foreground("#FFFF00")
109
+
110
+ puts style.render("Rainbow border!")
111
+ ```
112
+
113
+ ### Layout
114
+
115
+ **Join content horizontally:**
116
+
117
+ ```ruby
118
+ left = box.render("Left")
119
+ right = box.render("Right")
120
+
121
+ puts Lipgloss.join_horizontal(:top, left, right)
122
+ ```
123
+
124
+ **Join content vertically:**
125
+
126
+ ```ruby
127
+ puts Lipgloss.join_vertical(:center, left, right)
128
+ ```
129
+
130
+ **Place content in whitespace:**
131
+
132
+ ```ruby
133
+ puts Lipgloss.place(40, 10, :center, :center, "Centered")
134
+ ```
135
+
136
+ **Position symbols:** `:top`, `:bottom`, `:left`, `:right`, `:center` (or numeric 0.0-1.0)
137
+
138
+ ### Colors
139
+
140
+ **Simple hex colors:**
141
+
142
+ ```ruby
143
+ style = Lipgloss::Style.new
144
+ .foreground("#FF0000")
145
+ .background("#0000FF")
146
+ ```
147
+
148
+ **Adaptive colors (auto-detect light/dark terminal):**
149
+
150
+ ```ruby
151
+ style = Lipgloss::Style.new
152
+ .foreground(Lipgloss::AdaptiveColor.new(light: "#000", dark: "#FFF"))
153
+ ```
154
+
155
+ **Complete colors with fallbacks:**
156
+
157
+ ```ruby
158
+ color = Lipgloss::CompleteColor.new(
159
+ true_color: "#FF6B6B", # 24-bit color
160
+ ansi256: 196, # 256-color fallback (integer)
161
+ ansi: :bright_red # 16-color fallback (symbol)
162
+ )
163
+
164
+ style = Lipgloss::Style.new.foreground(color)
165
+ ```
166
+
167
+ **ANSI color symbols:** `:black`, `:red`, `:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, `:white`, and bright variants (`:bright_red`, etc.)
168
+
169
+ **Complete adaptive colors:**
170
+
171
+ ```ruby
172
+ light = Lipgloss::CompleteColor.new(true_color: "#000", ansi256: :black, ansi: :black)
173
+ dark = Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256: :bright_white, ansi: :bright_white)
174
+ color = Lipgloss::CompleteAdaptiveColor.new(light: light, dark: dark)
175
+
176
+ style = Lipgloss::Style.new.foreground(color)
177
+ ```
178
+
179
+ ### Style Inheritance
180
+
181
+ **Inherit styles from a parent:**
182
+
183
+ ```ruby
184
+ base = Lipgloss::Style.new
185
+ .foreground("#FF0000")
186
+ .bold(true)
187
+
188
+ child = Lipgloss::Style.new
189
+ .padding(1)
190
+ .inherit(base) # Inherits foreground and bold
191
+
192
+ puts child.render("Inherited style!")
193
+ ```
194
+
195
+ **Unset specific properties:**
196
+
197
+ ```ruby
198
+ style = Lipgloss::Style.new
199
+ .bold(true)
200
+ .foreground("#FF0000")
201
+ .unset_bold # Remove bold
202
+ .unset_foreground # Remove foreground color
203
+ ```
204
+
205
+ ### SetString
206
+
207
+ **Set default text for a style:**
208
+
209
+ ```ruby
210
+ style = Lipgloss::Style.new
211
+ .bold(true)
212
+ .foreground("#7D56F4")
213
+ .set_string("Hello!")
214
+
215
+ puts style.to_s # Renders "Hello!" with the style
216
+ ```
217
+
218
+ ### Tables
219
+
220
+ **Create styled tables:**
221
+
222
+ ```ruby
223
+ table = Lipgloss::Table.new
224
+ .headers(["Language", "Greeting"])
225
+ .rows([
226
+ ["English", "Hello"],
227
+ ["Spanish", "Hola"],
228
+ ["Japanese", "こんにちは"]
229
+ ])
230
+ .border(:rounded)
231
+
232
+ puts table.render
233
+ ```
234
+
235
+ **Style cells with StyleFunc:**
236
+
237
+ ```ruby
238
+ header_style = Lipgloss::Style.new.bold(true).background("#5A56E0")
239
+ even_style = Lipgloss::Style.new.background("#3C3C3C")
240
+ odd_style = Lipgloss::Style.new.background("#4A4A4A")
241
+
242
+ table = Lipgloss::Table.new
243
+ .headers(["Name", "Role"])
244
+ .rows([["Alice", "Engineer"], ["Bob", "Designer"]])
245
+ .border(:rounded)
246
+ .style_func(rows: 2, columns: 2) do |row, column|
247
+ if row == Lipgloss::Table::HEADER_ROW
248
+ header_style
249
+ elsif row.even?
250
+ even_style
251
+ else
252
+ odd_style
253
+ end
254
+ end
255
+
256
+ puts table.render
257
+ ```
258
+
259
+ ### Lists
260
+
261
+ **Create styled lists:**
262
+
263
+ ```ruby
264
+ list = Lipgloss::List.new
265
+ .items(["First item", "Second item", "Third item"])
266
+ .enumerator(:bullet)
267
+
268
+ puts list.render
269
+ ```
270
+
271
+ **Available enumerators:**
272
+
273
+ | Enumerator | Output |
274
+ |-------------|--------------------|
275
+ | `:bullet` | `•` |
276
+ | `:dash` | `-` |
277
+ | `:asterisk` | `*` |
278
+ | `:arabic` | `1.`, `2.`, `3.` |
279
+ | `:alphabet` | `A.`, `B.`, `C.` |
280
+ | `:roman` | `I.`, `II.`, `III.` |
281
+
282
+ **Styled list items:**
283
+
284
+ ```ruby
285
+ list = Lipgloss::List.new
286
+ .items(["Red", "Green", "Blue"])
287
+ .enumerator(:bullet)
288
+ .enumerator_style(Lipgloss::Style.new.foreground("#FF0000"))
289
+ .item_style(Lipgloss::Style.new.bold(true))
290
+
291
+ puts list.render
292
+ ```
293
+
294
+ ### Trees
295
+
296
+ **Create tree structures:**
297
+
298
+ ```ruby
299
+ tree = Lipgloss::Tree.new
300
+ .root("Project")
301
+ .child("src")
302
+ .child("lib")
303
+ .child("test")
304
+
305
+ puts tree.render
306
+ ```
307
+
308
+ **Nested trees:**
309
+
310
+ ```ruby
311
+ src = Lipgloss::Tree.new.root("src").child("main.rb").child("helper.rb")
312
+ test = Lipgloss::Tree.new.root("test").child("test_main.rb")
313
+
314
+ tree = Lipgloss::Tree.new
315
+ .root("Project")
316
+ .child(src)
317
+ .child(test)
318
+
319
+ puts tree.render
320
+ ```
321
+
322
+ ## Style Methods
323
+
324
+ ### Text Formatting
325
+
326
+ | Method | Description |
327
+ |-----------------------|-------------------------------|
328
+ | `bold(bool)` | Bold text |
329
+ | `italic(bool)` | Italic text |
330
+ | `underline(bool)` | Underlined text |
331
+ | `strikethrough(bool)` | Strikethrough text |
332
+ | `reverse(bool)` | Reverse foreground/background |
333
+ | `blink(bool)` | Blinking text |
334
+ | `faint(bool)` | Dimmed text |
335
+
336
+ ### Colors
337
+
338
+ | Method | Description |
339
+ |----------------------------|-------------------------|
340
+ | `foreground(color)` | Text color |
341
+ | `background(color)` | Background color |
342
+ | `margin_background(color)` | Margin background color |
343
+
344
+ ### Dimensions
345
+
346
+ | Method | Description |
347
+ |------------------|----------------|
348
+ | `width(int)` | Set width |
349
+ | `height(int)` | Set height |
350
+ | `max_width(int)` | Maximum width |
351
+ | `max_height(int)`| Maximum height |
352
+
353
+ ### Spacing
354
+
355
+ | Method | Description |
356
+ |------------------------------------------------|-----------------------|
357
+ | `padding(top, right, bottom, left)` | Padding (CSS shorthand) |
358
+ | `padding_top(int)`, `padding_right(int)`, etc. | Individual padding |
359
+ | `margin(top, right, bottom, left)` | Margin (CSS shorthand) |
360
+ | `margin_top(int)`, `margin_right(int)`, etc. | Individual margin |
361
+
362
+ ### Borders
363
+
364
+ | Method | Description |
365
+ |------------------------------------------------|-----------------------------|
366
+ | `border(type, *sides)` | Set border type and sides |
367
+ | `border_style(type)` | Set border type only |
368
+ | `border_foreground(color)` | Border color (all sides) |
369
+ | `border_background(color)` | Border background (all sides) |
370
+ | `border_top_foreground(color)`, etc. | Per-side border colors |
371
+ | `border_top_background(color)`, etc. | Per-side border backgrounds |
372
+ | `border_top(bool)`, `border_right(bool)`, etc. | Enable/disable sides |
373
+ | `border_custom(**opts)` | Custom border characters |
374
+
375
+ ### Alignment
376
+
377
+ | Method | Description |
378
+ |-------------------------------|----------------------|
379
+ | `align(horizontal, vertical)` | Set alignment |
380
+ | `align_horizontal(position)` | Horizontal alignment |
381
+ | `align_vertical(position)` | Vertical alignment |
382
+
383
+ **Position symbols:** `:top`, `:bottom`, `:left`, `:right`, `:center` (or numeric 0.0-1.0)
384
+
385
+ ### Other
386
+
387
+ | Method | Description |
388
+ |--------------------|-------------------------------------------|
389
+ | `inline(bool)` | Render inline (no margins/padding/borders) |
390
+ | `tab_width(int)` | Tab character width (-1 to disable) |
391
+ | `set_string(text)` | Set default text |
392
+ | `inherit(style)` | Inherit from another style |
393
+ | `to_s` | Render with default text |
394
+
395
+ ### Unset Methods
396
+
397
+ | Method | Description |
398
+ |----------------------------------------|----------------------|
399
+ | `unset_bold`, `unset_italic`, etc. | Clear text formatting |
400
+ | `unset_foreground`, `unset_background` | Clear colors |
401
+ | `unset_width`, `unset_height` | Clear dimensions |
402
+ | `unset_padding_top`, etc. | Clear padding |
403
+ | `unset_margin_top`, etc. | Clear margin |
404
+ | `unset_border_style` | Clear border |
405
+ | `unset_inline` | Clear inline |
406
+
407
+ ## Module Methods
408
+
409
+ | Method | Description |
410
+ |-----------------------------------------------------------|---------------------------|
411
+ | `Lipgloss.join_horizontal(position, *strings)` | Join strings horizontally |
412
+ | `Lipgloss.join_vertical(position, *strings)` | Join strings vertically |
413
+ | `Lipgloss.width(string)` | Get rendered width |
414
+ | `Lipgloss.height(string)` | Get rendered height |
415
+ | `Lipgloss.size(string)` | Get `[width, height]` |
416
+ | `Lipgloss.place(width, height, h_pos, v_pos, string)` | Place in whitespace |
417
+ | `Lipgloss.place_horizontal(width, position, string)` | Place horizontally |
418
+ | `Lipgloss.place_vertical(height, position, string)` | Place vertically |
419
+ | `Lipgloss.has_dark_background?` | Check terminal background |
420
+
421
+ ### Color Blending
422
+
423
+ | Method | Description |
424
+ |----------------------------------------------------------------|--------------------------------|
425
+ | `Lipgloss::ColorBlend.blend(c1, c2, t, mode:)` | Blend two colors (0.0-1.0) |
426
+ | `Lipgloss::ColorBlend.blends(c1, c2, steps, mode:)` | Generate color gradient array |
427
+ | `Lipgloss::ColorBlend.grid(c1, c2, c3, c4, x, y, mode:)` | Generate 2D color grid |
428
+
429
+ **Blend modes:** `:luv` (default, perceptually uniform), `:rgb`, `:hcl`
430
+
431
+ #### Generate a 5-color gradient
432
+
433
+ ```ruby
434
+ colors = Lipgloss::ColorBlend.blends("#FF0000", "#0000FF", 5)
435
+ # => ["#ff0000", "#c1007f", "#7a00c1", "#0000ff", ...]
436
+ ```
437
+
438
+ #### Blend two colors at 50%
439
+
440
+ ```ruby
441
+ mid = Lipgloss::ColorBlend.blend("#FF0000", "#00FF00", 0.5)
442
+ # => "#b5b500"
443
+ ```
26
444
 
27
445
  ## Development
28
446
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
447
+ **Requirements:**
448
+ - Go 1.23+
449
+ - Ruby 3.2+
450
+
451
+ **Install dependencies:**
452
+
453
+ ```bash
454
+ bundle install
455
+ ```
456
+
457
+ **Build the Go library and compile the extension:**
458
+
459
+ ```bash
460
+ bundle exec rake compile
461
+ ```
462
+
463
+ **Run tests:**
30
464
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
465
+ ```bash
466
+ bundle exec rake test
467
+ ```
468
+
469
+ **Run demos:**
470
+
471
+ ```bash
472
+ ./demo/basic
473
+ ./demo/colors
474
+ ./demo/layout
475
+ ./demo/table
476
+ ./demo/list
477
+ ./demo/tree
478
+ ```
32
479
 
33
480
  ## Contributing
34
481
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/lipgloss. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcoroth/lipgloss/blob/main/CODE_OF_CONDUCT.md).
482
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/lipgloss-ruby.
483
+
484
+ ## License
485
+
486
+ The gem is available as open source under the terms of the MIT License.
36
487
 
37
- ## Code of Conduct
488
+ ## Acknowledgments
38
489
 
39
- Everyone interacting in the Lipgloss project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/lipgloss/blob/main/CODE_OF_CONDUCT.md).
490
+ This gem wraps [charmbracelet/lipgloss](https://github.com/charmbracelet/lipgloss), part of the excellent [Charm](https://charm.sh) ecosystem.
@@ -0,0 +1,158 @@
1
+ #include "extension.h"
2
+
3
+ VALUE mColor;
4
+
5
+ #define BLEND_LUV 0
6
+ #define BLEND_RGB 1
7
+ #define BLEND_HCL 2
8
+
9
+ static int blend_mode_from_symbol(VALUE mode) {
10
+ if (NIL_P(mode)) {
11
+ return BLEND_LUV;
12
+ }
13
+
14
+ ID mode_id = SYM2ID(mode);
15
+
16
+ if (mode_id == rb_intern("luv")) {
17
+ return BLEND_LUV;
18
+ } else if (mode_id == rb_intern("rgb")) {
19
+ return BLEND_RGB;
20
+ } else if (mode_id == rb_intern("hcl")) {
21
+ return BLEND_HCL;
22
+ }
23
+
24
+ return BLEND_LUV;
25
+ }
26
+
27
+ static VALUE color_blend(int argc, VALUE *argv, VALUE self) {
28
+ VALUE c1, c2, t, opts;
29
+ rb_scan_args(argc, argv, "3:", &c1, &c2, &t, &opts);
30
+
31
+ Check_Type(c1, T_STRING);
32
+ Check_Type(c2, T_STRING);
33
+
34
+ VALUE mode = Qnil;
35
+ if (!NIL_P(opts)) {
36
+ mode = rb_hash_aref(opts, ID2SYM(rb_intern("mode")));
37
+ }
38
+
39
+ int blend_mode = blend_mode_from_symbol(mode);
40
+ char *result;
41
+
42
+ switch (blend_mode) {
43
+ case BLEND_RGB:
44
+ result = lipgloss_color_blend_rgb(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
45
+ break;
46
+ case BLEND_HCL:
47
+ result = lipgloss_color_blend_hcl(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
48
+ break;
49
+ default:
50
+ result = lipgloss_color_blend_luv(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
51
+ break;
52
+ }
53
+
54
+ VALUE rb_result = rb_utf8_str_new_cstr(result);
55
+ lipgloss_free(result);
56
+
57
+ return rb_result;
58
+ }
59
+
60
+ static VALUE color_blend_luv(VALUE self, VALUE c1, VALUE c2, VALUE t) {
61
+ Check_Type(c1, T_STRING);
62
+ Check_Type(c2, T_STRING);
63
+
64
+ char *result = lipgloss_color_blend_luv(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
65
+ VALUE rb_result = rb_utf8_str_new_cstr(result);
66
+ lipgloss_free(result);
67
+
68
+ return rb_result;
69
+ }
70
+
71
+ static VALUE color_blend_rgb(VALUE self, VALUE c1, VALUE c2, VALUE t) {
72
+ Check_Type(c1, T_STRING);
73
+ Check_Type(c2, T_STRING);
74
+
75
+ char *result = lipgloss_color_blend_rgb(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
76
+ VALUE rb_result = rb_utf8_str_new_cstr(result);
77
+ lipgloss_free(result);
78
+
79
+ return rb_result;
80
+ }
81
+
82
+ static VALUE color_blend_hcl(VALUE self, VALUE c1, VALUE c2, VALUE t) {
83
+ Check_Type(c1, T_STRING);
84
+ Check_Type(c2, T_STRING);
85
+
86
+ char *result = lipgloss_color_blend_hcl(StringValueCStr(c1), StringValueCStr(c2), NUM2DBL(t));
87
+ VALUE rb_result = rb_utf8_str_new_cstr(result);
88
+ lipgloss_free(result);
89
+
90
+ return rb_result;
91
+ }
92
+
93
+ static VALUE color_blends(int argc, VALUE *argv, VALUE self) {
94
+ VALUE c1, c2, steps, opts;
95
+ rb_scan_args(argc, argv, "3:", &c1, &c2, &steps, &opts);
96
+
97
+ Check_Type(c1, T_STRING);
98
+ Check_Type(c2, T_STRING);
99
+
100
+ VALUE mode = Qnil;
101
+ if (!NIL_P(opts)) {
102
+ mode = rb_hash_aref(opts, ID2SYM(rb_intern("mode")));
103
+ }
104
+
105
+ int blend_mode = blend_mode_from_symbol(mode);
106
+ char *result = lipgloss_color_blends(StringValueCStr(c1), StringValueCStr(c2), NUM2INT(steps), blend_mode);
107
+ VALUE json_string = rb_utf8_str_new_cstr(result);
108
+ lipgloss_free(result);
109
+
110
+ return rb_funcall(rb_const_get(rb_cObject, rb_intern("JSON")), rb_intern("parse"), 1, json_string);
111
+ }
112
+
113
+ static VALUE color_grid(int argc, VALUE *argv, VALUE self) {
114
+ VALUE x0y0, x1y0, x0y1, x1y1, x_steps, y_steps, opts;
115
+ rb_scan_args(argc, argv, "6:", &x0y0, &x1y0, &x0y1, &x1y1, &x_steps, &y_steps, &opts);
116
+
117
+ Check_Type(x0y0, T_STRING);
118
+ Check_Type(x1y0, T_STRING);
119
+ Check_Type(x0y1, T_STRING);
120
+ Check_Type(x1y1, T_STRING);
121
+
122
+ VALUE mode = Qnil;
123
+ if (!NIL_P(opts)) {
124
+ mode = rb_hash_aref(opts, ID2SYM(rb_intern("mode")));
125
+ }
126
+
127
+ int blend_mode = blend_mode_from_symbol(mode);
128
+
129
+ char *result = lipgloss_color_grid(
130
+ StringValueCStr(x0y0),
131
+ StringValueCStr(x1y0),
132
+ StringValueCStr(x0y1),
133
+ StringValueCStr(x1y1),
134
+ NUM2INT(x_steps),
135
+ NUM2INT(y_steps),
136
+ blend_mode
137
+ );
138
+
139
+ VALUE json_string = rb_utf8_str_new_cstr(result);
140
+ lipgloss_free(result);
141
+
142
+ return rb_funcall(rb_const_get(rb_cObject, rb_intern("JSON")), rb_intern("parse"), 1, json_string);
143
+ }
144
+
145
+ void Init_lipgloss_color(void) {
146
+ VALUE mColorBlend = rb_define_module_under(mLipgloss, "ColorBlend");
147
+
148
+ rb_define_singleton_method(mColorBlend, "blend", color_blend, -1);
149
+ rb_define_singleton_method(mColorBlend, "blend_luv", color_blend_luv, 3);
150
+ rb_define_singleton_method(mColorBlend, "blend_rgb", color_blend_rgb, 3);
151
+ rb_define_singleton_method(mColorBlend, "blend_hcl", color_blend_hcl, 3);
152
+ rb_define_singleton_method(mColorBlend, "blends", color_blends, -1);
153
+ rb_define_singleton_method(mColorBlend, "grid", color_grid, -1);
154
+
155
+ rb_define_const(mColorBlend, "LUV", ID2SYM(rb_intern("luv")));
156
+ rb_define_const(mColorBlend, "RGB", ID2SYM(rb_intern("rgb")));
157
+ rb_define_const(mColorBlend, "HCL", ID2SYM(rb_intern("hcl")));
158
+ }