lipgloss 0.2.1 → 0.2.3

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: 21670956c057c75cc20ecddc90d112ec73c0329d6dcacef3b3db667de202cfef
4
- data.tar.gz: 99456be1f0aad47ffb9fc43668dd69748f5cde6812c644532a6c7d135238309f
3
+ metadata.gz: 64298cd49ffbe321b89fd15467e5a2f8a004df9766a3c496503deda02570d5a1
4
+ data.tar.gz: d5cc36929140d8447811478accbf01bf1ca34579e3121ba019c577b80e321221
5
5
  SHA512:
6
- metadata.gz: 6ce3d0fff553eb4dcef76b170ed9315dc1b9446e980a25c655a178828a69787af198cf584863e4d237e42bd48e2ffc4bb33fdfef4f17e15acd5d3f1c3c6859fc
7
- data.tar.gz: 92646ae76273f4451e8c7ad36b6b541199c05955310e691b43bd0f6dc36e387035cb7739f388ad195e9031ccc132c3181f000db2307dd5d6613675df58c8772a
6
+ metadata.gz: e1dfd94aaf1ab37927e9da42f64726a59cd78cbf15f8a559ecd333f81f589e7f06b3ac056639970970147dca46bf429868d993003bd2cbe073d1bbb06bf35cba
7
+ data.tar.gz: 576fa3a0014de56d0f0f82159b79ef35b7e2a22e52fd9ce9c24790be9e3d1da999242cd47b8087f35e5f3882ef04a4258a359a99b6c1c73bd543a2672d289f62
data/README.md CHANGED
@@ -176,6 +176,17 @@ color = Lipgloss::CompleteAdaptiveColor.new(light: light, dark: dark)
176
176
  style = Lipgloss::Style.new.foreground(color)
177
177
  ```
178
178
 
179
+ **Color profile:**
180
+
181
+ Lip Gloss detects how many colors the terminal supports when it first renders. Set the profile to force colors on, for example in CI or golden tests, or off:
182
+
183
+ ```ruby
184
+ Lipgloss.color_profile # => :true_color, :ansi256, :ansi, or :ascii
185
+ Lipgloss.color_profile = :true_color # always render colors
186
+ Lipgloss.color_profile = :ascii # never render colors
187
+ Lipgloss.has_dark_background = true # pick the dark variant of adaptive colors
188
+ ```
189
+
179
190
  ### Style Inheritance
180
191
 
181
192
  **Inherit styles from a parent:**
@@ -415,6 +426,9 @@ puts tree.render
415
426
  | `Lipgloss.place_horizontal(width, position, string)` | Place horizontally |
416
427
  | `Lipgloss.place_vertical(height, position, string)` | Place vertically |
417
428
  | `Lipgloss.has_dark_background?` | Check terminal background |
429
+ | `Lipgloss.has_dark_background = bool` | Set terminal background |
430
+ | `Lipgloss.color_profile` | Get the color profile |
431
+ | `Lipgloss.color_profile = profile` | Set the color profile |
418
432
 
419
433
  ### Color Blending
420
434
 
@@ -150,6 +150,20 @@ static VALUE lipgloss_has_dark_background_rb(VALUE self) {
150
150
  return lipgloss_has_dark_background() ? Qtrue : Qfalse;
151
151
  }
152
152
 
153
+ static VALUE lipgloss_color_profile_rb(VALUE self) {
154
+ return INT2NUM(lipgloss_color_profile());
155
+ }
156
+
157
+ static VALUE lipgloss_set_color_profile_rb(VALUE self, VALUE profile) {
158
+ lipgloss_set_color_profile(NUM2INT(profile));
159
+ return profile;
160
+ }
161
+
162
+ static VALUE lipgloss_set_has_dark_background_rb(VALUE self, VALUE dark) {
163
+ lipgloss_set_has_dark_background(RTEST(dark) ? 1 : 0);
164
+ return dark;
165
+ }
166
+
153
167
  static VALUE lipgloss_upstream_version_rb(VALUE self) {
154
168
  char *version = lipgloss_upstream_version();
155
169
  VALUE rb_version = rb_utf8_str_new_cstr(version);
@@ -187,6 +201,9 @@ __attribute__((__visibility__("default"))) void Init_lipgloss(void) {
187
201
  rb_define_singleton_method(mLipgloss, "_place_horizontal", lipgloss_place_horizontal_rb, 3);
188
202
  rb_define_singleton_method(mLipgloss, "_place_vertical", lipgloss_place_vertical_rb, 3);
189
203
  rb_define_singleton_method(mLipgloss, "has_dark_background?", lipgloss_has_dark_background_rb, 0);
204
+ rb_define_singleton_method(mLipgloss, "has_dark_background=", lipgloss_set_has_dark_background_rb, 1);
205
+ rb_define_singleton_method(mLipgloss, "_color_profile", lipgloss_color_profile_rb, 0);
206
+ rb_define_singleton_method(mLipgloss, "_set_color_profile", lipgloss_set_color_profile_rb, 1);
190
207
  rb_define_singleton_method(mLipgloss, "upstream_version", lipgloss_upstream_version_rb, 0);
191
208
  rb_define_singleton_method(mLipgloss, "version", lipgloss_version_rb, 0);
192
209
  }
data/ext/lipgloss/style.c CHANGED
@@ -344,6 +344,16 @@ static VALUE style_to_s(VALUE self) {
344
344
  return rb_result;
345
345
  }
346
346
 
347
+ static VALUE style_to_json(VALUE self) {
348
+ GET_STYLE(self, style);
349
+ char *result = lipgloss_style_to_json(style->handle);
350
+ VALUE rb_result = rb_utf8_str_new_cstr(result);
351
+
352
+ lipgloss_free(result);
353
+
354
+ return rb_result;
355
+ }
356
+
347
357
  // Getter methods
348
358
 
349
359
  static VALUE style_get_bold(VALUE self) {
@@ -455,6 +465,7 @@ void Init_lipgloss_style(void) {
455
465
  rb_define_method(cStyle, "set_string", style_set_string, 1);
456
466
  rb_define_method(cStyle, "inherit", style_inherit, 1);
457
467
  rb_define_method(cStyle, "to_s", style_to_s, 0);
468
+ rb_define_method(cStyle, "_to_json", style_to_json, 0);
458
469
 
459
470
  rb_define_method(cStyle, "bold?", style_get_bold, 0);
460
471
  rb_define_method(cStyle, "italic?", style_get_italic, 0);
data/ext/lipgloss/table.c CHANGED
@@ -40,29 +40,49 @@ static VALUE table_initialize(VALUE self) {
40
40
  return self;
41
41
  }
42
42
 
43
+ static VALUE table_cells_to_s(VALUE cells) {
44
+ Check_Type(cells, T_ARRAY);
45
+
46
+ long length = RARRAY_LEN(cells);
47
+ VALUE result = rb_ary_new_capa(length);
48
+
49
+ for (long index = 0; index < length; index++) {
50
+ rb_ary_push(result, rb_obj_as_string(rb_ary_entry(cells, index)));
51
+ }
52
+
53
+ return result;
54
+ }
55
+
56
+ static VALUE table_rows_to_s(VALUE rows) {
57
+ Check_Type(rows, T_ARRAY);
58
+
59
+ long length = RARRAY_LEN(rows);
60
+ VALUE result = rb_ary_new_capa(length);
61
+
62
+ for (long index = 0; index < length; index++) {
63
+ rb_ary_push(result, table_cells_to_s(rb_ary_entry(rows, index)));
64
+ }
65
+
66
+ return result;
67
+ }
68
+
43
69
  static VALUE table_headers(VALUE self, VALUE headers) {
44
70
  GET_TABLE(self, table);
45
- Check_Type(headers, T_ARRAY);
46
-
47
- VALUE json_str = rb_funcall(headers, rb_intern("to_json"), 0);
71
+ VALUE json_str = rb_funcall(table_cells_to_s(headers), rb_intern("to_json"), 0);
48
72
  unsigned long long new_handle = lipgloss_table_headers(table->handle, StringValueCStr(json_str));
49
73
  return table_wrap(rb_class_of(self), new_handle);
50
74
  }
51
75
 
52
76
  static VALUE table_row(VALUE self, VALUE row) {
53
77
  GET_TABLE(self, table);
54
- Check_Type(row, T_ARRAY);
55
-
56
- VALUE json_str = rb_funcall(row, rb_intern("to_json"), 0);
78
+ VALUE json_str = rb_funcall(table_cells_to_s(row), rb_intern("to_json"), 0);
57
79
  unsigned long long new_handle = lipgloss_table_row(table->handle, StringValueCStr(json_str));
58
80
  return table_wrap(rb_class_of(self), new_handle);
59
81
  }
60
82
 
61
83
  static VALUE table_rows(VALUE self, VALUE rows) {
62
84
  GET_TABLE(self, table);
63
- Check_Type(rows, T_ARRAY);
64
-
65
- VALUE json_str = rb_funcall(rows, rb_intern("to_json"), 0);
85
+ VALUE json_str = rb_funcall(table_rows_to_s(rows), rb_intern("to_json"), 0);
66
86
  unsigned long long new_handle = lipgloss_table_rows(table->handle, StringValueCStr(json_str));
67
87
 
68
88
  return table_wrap(rb_class_of(self), new_handle);
data/go/go.mod CHANGED
@@ -2,7 +2,11 @@ module github.com/marcoroth/lipgloss-ruby/go
2
2
 
3
3
  go 1.23.0
4
4
 
5
- require github.com/charmbracelet/lipgloss v1.1.0
5
+ require (
6
+ github.com/charmbracelet/lipgloss v1.1.0
7
+ github.com/lucasb-eyer/go-colorful v1.2.0
8
+ github.com/muesli/termenv v0.16.0
9
+ )
6
10
 
7
11
  require (
8
12
  github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
@@ -10,10 +14,8 @@ require (
10
14
  github.com/charmbracelet/x/ansi v0.8.0 // indirect
11
15
  github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
12
16
  github.com/charmbracelet/x/term v0.2.1 // indirect
13
- github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
14
17
  github.com/mattn/go-isatty v0.0.20 // indirect
15
18
  github.com/mattn/go-runewidth v0.0.16 // indirect
16
- github.com/muesli/termenv v0.16.0 // indirect
17
19
  github.com/rivo/uniseg v0.4.7 // indirect
18
20
  github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
19
21
  golang.org/x/sys v0.30.0 // indirect
data/go/layout.go CHANGED
@@ -5,6 +5,7 @@ import "C"
5
5
  import (
6
6
  "encoding/json"
7
7
  "github.com/charmbracelet/lipgloss"
8
+ "github.com/muesli/termenv"
8
9
  )
9
10
 
10
11
  //export lipgloss_join_horizontal
@@ -111,3 +112,18 @@ func lipgloss_has_dark_background() C.int {
111
112
 
112
113
  return 0
113
114
  }
115
+
116
+ //export lipgloss_color_profile
117
+ func lipgloss_color_profile() C.int {
118
+ return C.int(lipgloss.ColorProfile())
119
+ }
120
+
121
+ //export lipgloss_set_color_profile
122
+ func lipgloss_set_color_profile(profile C.int) {
123
+ lipgloss.SetColorProfile(termenv.Profile(profile))
124
+ }
125
+
126
+ //export lipgloss_set_has_dark_background
127
+ func lipgloss_set_has_dark_background(dark C.int) {
128
+ lipgloss.SetHasDarkBackground(dark != 0)
129
+ }
data/go/style_hash.go ADDED
@@ -0,0 +1,144 @@
1
+ package main
2
+
3
+ import "C"
4
+
5
+ import (
6
+ "encoding/json"
7
+
8
+ "github.com/charmbracelet/lipgloss"
9
+ )
10
+
11
+ func colorToValue(tc lipgloss.TerminalColor) any {
12
+ switch c := tc.(type) {
13
+ case nil, lipgloss.NoColor:
14
+ return nil
15
+ case lipgloss.Color:
16
+ if c == "" {
17
+ return nil
18
+ }
19
+ return string(c)
20
+ case lipgloss.AdaptiveColor:
21
+ return map[string]any{"light": c.Light, "dark": c.Dark}
22
+ case lipgloss.CompleteColor:
23
+ return map[string]any{"true_color": c.TrueColor, "ansi256": c.ANSI256, "ansi": c.ANSI}
24
+ case lipgloss.CompleteAdaptiveColor:
25
+ return map[string]any{
26
+ "light": map[string]any{"true_color": c.Light.TrueColor, "ansi256": c.Light.ANSI256, "ansi": c.Light.ANSI},
27
+ "dark": map[string]any{"true_color": c.Dark.TrueColor, "ansi256": c.Dark.ANSI256, "ansi": c.Dark.ANSI},
28
+ }
29
+ }
30
+ return nil
31
+ }
32
+
33
+ func borderToValue(b lipgloss.Border) map[string]any {
34
+ return map[string]any{
35
+ "top": b.Top,
36
+ "bottom": b.Bottom,
37
+ "left": b.Left,
38
+ "right": b.Right,
39
+ "top_left": b.TopLeft,
40
+ "top_right": b.TopRight,
41
+ "bottom_left": b.BottomLeft,
42
+ "bottom_right": b.BottomRight,
43
+ "middle_left": b.MiddleLeft,
44
+ "middle_right": b.MiddleRight,
45
+ "middle": b.Middle,
46
+ "middle_top": b.MiddleTop,
47
+ "middle_bottom": b.MiddleBottom,
48
+ }
49
+ }
50
+
51
+ func setIf(h map[string]any, key string, value any) {
52
+ switch v := value.(type) {
53
+ case nil:
54
+ return
55
+ case bool:
56
+ if !v {
57
+ return
58
+ }
59
+ case int:
60
+ if v == 0 {
61
+ return
62
+ }
63
+ }
64
+ h[key] = value
65
+ }
66
+
67
+ func styleToHash(s lipgloss.Style) map[string]any {
68
+ h := map[string]any{}
69
+
70
+ setIf(h, "bold", s.GetBold())
71
+ setIf(h, "italic", s.GetItalic())
72
+ setIf(h, "underline", s.GetUnderline())
73
+ setIf(h, "strikethrough", s.GetStrikethrough())
74
+ setIf(h, "reverse", s.GetReverse())
75
+ setIf(h, "blink", s.GetBlink())
76
+ setIf(h, "faint", s.GetFaint())
77
+ setIf(h, "inline", s.GetInline())
78
+
79
+ setIf(h, "foreground", colorToValue(s.GetForeground()))
80
+ setIf(h, "background", colorToValue(s.GetBackground()))
81
+
82
+ setIf(h, "width", s.GetWidth())
83
+ setIf(h, "height", s.GetHeight())
84
+ setIf(h, "max_width", s.GetMaxWidth())
85
+ setIf(h, "max_height", s.GetMaxHeight())
86
+
87
+ if horizontal := s.GetAlignHorizontal(); horizontal != lipgloss.Left {
88
+ h["align_horizontal"] = float64(horizontal)
89
+ }
90
+ if vertical := s.GetAlignVertical(); vertical != lipgloss.Top {
91
+ h["align_vertical"] = float64(vertical)
92
+ }
93
+
94
+ if t, r, b, l := s.GetPadding(); t+r+b+l > 0 {
95
+ h["padding"] = []int{t, r, b, l}
96
+ }
97
+ if t, r, b, l := s.GetMargin(); t+r+b+l > 0 {
98
+ h["margin"] = []int{t, r, b, l}
99
+ }
100
+
101
+ border, top, right, bottom, left := s.GetBorder()
102
+ if top || right || bottom || left {
103
+ h["border"] = borderToValue(border)
104
+ h["border_sides"] = []bool{top, right, bottom, left}
105
+
106
+ foregrounds := []any{
107
+ colorToValue(s.GetBorderTopForeground()),
108
+ colorToValue(s.GetBorderRightForeground()),
109
+ colorToValue(s.GetBorderBottomForeground()),
110
+ colorToValue(s.GetBorderLeftForeground()),
111
+ }
112
+ backgrounds := []any{
113
+ colorToValue(s.GetBorderTopBackground()),
114
+ colorToValue(s.GetBorderRightBackground()),
115
+ colorToValue(s.GetBorderBottomBackground()),
116
+ colorToValue(s.GetBorderLeftBackground()),
117
+ }
118
+
119
+ for _, c := range foregrounds {
120
+ if c != nil {
121
+ h["border_foreground"] = foregrounds
122
+ break
123
+ }
124
+ }
125
+ for _, c := range backgrounds {
126
+ if c != nil {
127
+ h["border_background"] = backgrounds
128
+ break
129
+ }
130
+ }
131
+ }
132
+
133
+ return h
134
+ }
135
+
136
+ //export lipgloss_style_to_json
137
+ func lipgloss_style_to_json(id C.ulonglong) *C.char {
138
+ data, err := json.Marshal(styleToHash(getStyle(uint64(id))))
139
+ if err != nil {
140
+ return C.CString("{}")
141
+ }
142
+
143
+ return C.CString(string(data))
144
+ }
@@ -20,5 +20,10 @@ module Lipgloss
20
20
  def align_vertical(position)
21
21
  _align_vertical(Position.resolve(position))
22
22
  end
23
+
24
+ # @rbs return: Hash[Symbol, untyped]
25
+ def to_h
26
+ JSON.parse(_to_json, symbolize_names: true)
27
+ end
23
28
  end
24
29
  end
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Lipgloss
5
- VERSION = "0.2.1" #: String
5
+ VERSION = "0.2.3" #: String
6
6
  end
data/lib/lipgloss.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  # rbs_inline: enabled
3
3
 
4
+ require "json"
4
5
  require_relative "lipgloss/version"
5
6
 
6
7
  begin
@@ -33,6 +34,11 @@ module Lipgloss
33
34
 
34
35
  NO_TAB_CONVERSION = -1 #: Integer
35
36
 
37
+ # @rbs!
38
+ # type color_profile = :true_color | :ansi256 | :ansi | :ascii
39
+
40
+ COLOR_PROFILES = [:true_color, :ansi256, :ansi, :ascii].freeze #: Array[color_profile]
41
+
36
42
  class << self
37
43
  # @rbs position: Position::position_value
38
44
  # @rbs *strings: String
@@ -73,5 +79,20 @@ module Lipgloss
73
79
  def place_vertical(height, position, string)
74
80
  _place_vertical(height, Position.resolve(position), string)
75
81
  end
82
+
83
+ # @rbs return: color_profile
84
+ def color_profile
85
+ COLOR_PROFILES.fetch(_color_profile)
86
+ end
87
+
88
+ # @rbs profile: color_profile
89
+ # @rbs return: void
90
+ def color_profile=(profile)
91
+ index = COLOR_PROFILES.index(profile)
92
+
93
+ raise ArgumentError, "unknown color profile #{profile.inspect}, expected one of #{COLOR_PROFILES.inspect}" unless index
94
+
95
+ _set_color_profile(index)
96
+ end
76
97
  end
77
98
  end
data/lipgloss.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  "lipgloss.gemspec",
24
24
  "LICENSE.txt",
25
25
  "README.md",
26
+ "sig/**/*.rbs",
26
27
  "lib/**/*.rb",
27
28
  "ext/**/*.{c,h,rb}",
28
29
  "go/**/*.{go,mod,sum}",
@@ -0,0 +1,48 @@
1
+ # Generated from lib/lipgloss/border.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ module Border
5
+ # Standard border with normal weight and 90 degree corners
6
+ # ┌───┐
7
+ # │ │
8
+ # └───┘
9
+ NORMAL: ::Symbol
10
+
11
+ # Border with rounded corners
12
+ # ╭───╮
13
+ # │ │
14
+ # ╰───╯
15
+ ROUNDED: ::Symbol
16
+
17
+ # Thicker border
18
+ # ┏━━━┓
19
+ # ┃ ┃
20
+ # ┗━━━┛
21
+ THICK: ::Symbol
22
+
23
+ # Double-line border
24
+ # ╔═══╗
25
+ # ║ ║
26
+ # ╚═══╝
27
+ DOUBLE: ::Symbol
28
+
29
+ # ASCII border (compatible with all terminals)
30
+ # +---+
31
+ # | |
32
+ # +---+
33
+ ASCII: ::Symbol
34
+
35
+ # Hidden border (spaces, maintains layout)
36
+ HIDDEN: ::Symbol
37
+
38
+ # Block border (full blocks)
39
+ # ████
40
+ # █ █
41
+ # ████
42
+ BLOCK: ::Symbol
43
+
44
+ OUTER_HALF_BLOCK: ::Symbol
45
+
46
+ INNER_HALF_BLOCK: ::Symbol
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ # Generated from lib/lipgloss/color.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ type adaptive_color_hash = { light: String, dark: String }
5
+
6
+ type complete_color_hash = { true_color: String, ansi256: String, ansi: String }
7
+
8
+ type complete_adaptive_color_hash = { light: complete_color_hash, dark: complete_color_hash }
9
+
10
+ module ANSIColor
11
+ 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
12
+
13
+ type ansi_color_value = ansi_color_symbol | Symbol | String | Integer
14
+
15
+ COLORS: Hash[Symbol, String]
16
+
17
+ # @rbs value: ansi_color_value
18
+ # @rbs return: String
19
+ def self.resolve: (ansi_color_value value) -> String
20
+ end
21
+
22
+ # Adaptive color that changes based on terminal background
23
+ #
24
+ # @example
25
+ # color = Lipgloss::AdaptiveColor.new(light: "#000000", dark: "#FFFFFF")
26
+ # style = Lipgloss::Style.new.foreground(color)
27
+ class AdaptiveColor
28
+ @light: String
29
+
30
+ @dark: String
31
+
32
+ attr_reader light: String
33
+
34
+ attr_reader dark: String
35
+
36
+ # @rbs light: String -- color to use on light backgrounds
37
+ # @rbs dark: String -- color to use on dark backgrounds
38
+ # @rbs return: void
39
+ def initialize: (light: String, dark: String) -> void
40
+
41
+ # @rbs return: adaptive_color_hash
42
+ def to_h: () -> adaptive_color_hash
43
+ end
44
+
45
+ # Complete color with explicit values for each color profile
46
+ #
47
+ # @example
48
+ # color = Lipgloss::CompleteColor.new(
49
+ # true_color: "#0000FF",
50
+ # ansi256: 21,
51
+ # ansi: :blue
52
+ # )
53
+ class CompleteColor
54
+ @true_color: String
55
+
56
+ @ansi256: String
57
+
58
+ @ansi: String
59
+
60
+ attr_reader true_color: String
61
+
62
+ attr_reader ansi256: String
63
+
64
+ attr_reader ansi: String
65
+
66
+ # @rbs true_color: String -- 24-bit color (e.g., "#0000FF")
67
+ # @rbs ansi256: ANSIColor::ansi_color_value -- 8-bit ANSI color (0-255, or symbol for 0-15)
68
+ # @rbs ansi: ANSIColor::ansi_color_value -- 4-bit ANSI color (:red, :blue, etc., or 0-15)
69
+ # @rbs return: void
70
+ def initialize: (true_color: String, ansi256: ANSIColor::ansi_color_value, ansi: ANSIColor::ansi_color_value) -> void
71
+
72
+ # @rbs return: complete_color_hash
73
+ def to_h: () -> complete_color_hash
74
+ end
75
+
76
+ # Complete adaptive color with explicit values for each color profile
77
+ # and separate options for light and dark backgrounds
78
+ #
79
+ # @example
80
+ # color = Lipgloss::CompleteAdaptiveColor.new(
81
+ # light: Lipgloss::CompleteColor.new(true_color: "#000", ansi256: :black, ansi: :black),
82
+ # dark: Lipgloss::CompleteColor.new(true_color: "#FFF", ansi256: :bright_white, ansi: :bright_white)
83
+ # )
84
+ class CompleteAdaptiveColor
85
+ @light: CompleteColor
86
+
87
+ @dark: CompleteColor
88
+
89
+ attr_reader light: CompleteColor
90
+
91
+ attr_reader dark: CompleteColor
92
+
93
+ # @rbs light: CompleteColor -- color for light backgrounds
94
+ # @rbs dark: CompleteColor -- color for dark backgrounds
95
+ # @rbs return: void
96
+ def initialize: (light: CompleteColor, dark: CompleteColor) -> void
97
+
98
+ # @rbs return: complete_adaptive_color_hash
99
+ def to_h: () -> complete_adaptive_color_hash
100
+ end
101
+ end
@@ -0,0 +1,185 @@
1
+ # Signatures for the C extension (ext/lipgloss/extension.c)
2
+
3
+ module Lipgloss
4
+ def self._join_horizontal: (Float position, Array[String] strings) -> String
5
+ def self._join_vertical: (Float position, Array[String] strings) -> String
6
+ def self.width: (String string) -> Integer
7
+ def self.height: (String string) -> Integer
8
+ def self.size: (String string) -> [Integer, Integer]
9
+ def self._place: (Integer width, Integer height, Float horizontal_position, Float vertical_position, String string, **untyped opts) -> String
10
+ def self._place_horizontal: (Integer width, Float position, String string) -> String
11
+ def self._place_vertical: (Integer height, Float position, String string) -> String
12
+ def self.has_dark_background?: () -> bool
13
+ def self.has_dark_background=: (bool dark) -> bool
14
+ def self._color_profile: () -> Integer
15
+ def self._set_color_profile: (Integer profile) -> Integer
16
+ def self.upstream_version: () -> String
17
+ def self.version: () -> String
18
+
19
+ class Style
20
+ def initialize: () -> void
21
+ def render: (String string) -> String
22
+ def to_s: () -> String
23
+
24
+ def bold: (bool value) -> Style
25
+ def italic: (bool value) -> Style
26
+ def underline: (bool value) -> Style
27
+ def strikethrough: (bool value) -> Style
28
+ def reverse: (bool value) -> Style
29
+ def blink: (bool value) -> Style
30
+ def faint: (bool value) -> Style
31
+
32
+ def foreground: (String | AdaptiveColor | CompleteColor | CompleteAdaptiveColor color) -> Style
33
+ def background: (String | AdaptiveColor | CompleteColor | CompleteAdaptiveColor color) -> Style
34
+ def margin_background: (String color) -> Style
35
+
36
+ def width: (Integer width) -> Style
37
+ def height: (Integer height) -> Style
38
+ def max_width: (Integer width) -> Style
39
+ def max_height: (Integer height) -> Style
40
+
41
+ def padding: (*Integer values) -> Style
42
+ def padding_top: (Integer value) -> Style
43
+ def padding_right: (Integer value) -> Style
44
+ def padding_bottom: (Integer value) -> Style
45
+ def padding_left: (Integer value) -> Style
46
+
47
+ def margin: (*Integer values) -> Style
48
+ def margin_top: (Integer value) -> Style
49
+ def margin_right: (Integer value) -> Style
50
+ def margin_bottom: (Integer value) -> Style
51
+ def margin_left: (Integer value) -> Style
52
+
53
+ def border: (Symbol border_type, *bool sides) -> Style
54
+ def border_style: (Symbol border_type) -> Style
55
+ def border_foreground: (String color) -> Style
56
+ def border_background: (String color) -> Style
57
+ def border_top: (bool value) -> Style
58
+ def border_right: (bool value) -> Style
59
+ def border_bottom: (bool value) -> Style
60
+ def border_left: (bool value) -> Style
61
+
62
+ def border_top_foreground: (String color) -> Style
63
+ def border_right_foreground: (String color) -> Style
64
+ def border_bottom_foreground: (String color) -> Style
65
+ def border_left_foreground: (String color) -> Style
66
+ def border_top_background: (String color) -> Style
67
+ def border_right_background: (String color) -> Style
68
+ def border_bottom_background: (String color) -> Style
69
+ def border_left_background: (String color) -> Style
70
+
71
+ def border_custom: (
72
+ ?top: String,
73
+ ?bottom: String,
74
+ ?left: String,
75
+ ?right: String,
76
+ ?top_left: String,
77
+ ?top_right: String,
78
+ ?bottom_left: String,
79
+ ?bottom_right: String,
80
+ ?middle_left: String,
81
+ ?middle_right: String,
82
+ ?middle: String,
83
+ ?middle_top: String,
84
+ ?middle_bottom: String
85
+ ) -> Style
86
+
87
+ def _align: (*Float positions) -> Style
88
+ def _align_horizontal: (Float position) -> Style
89
+ def _align_vertical: (Float position) -> Style
90
+
91
+ def inline: (bool value) -> Style
92
+ def tab_width: (Integer width) -> Style
93
+ def underline_spaces: (bool value) -> Style
94
+ def strikethrough_spaces: (bool value) -> Style
95
+
96
+ def set_string: (String string) -> Style
97
+ def inherit: (Style other) -> Style
98
+ def _to_json: () -> String
99
+
100
+ def unset_bold: () -> Style
101
+ def unset_italic: () -> Style
102
+ def unset_underline: () -> Style
103
+ def unset_strikethrough: () -> Style
104
+ def unset_reverse: () -> Style
105
+ def unset_blink: () -> Style
106
+ def unset_faint: () -> Style
107
+ def unset_foreground: () -> Style
108
+ def unset_background: () -> Style
109
+ def unset_width: () -> Style
110
+ def unset_height: () -> Style
111
+ def unset_padding_top: () -> Style
112
+ def unset_padding_right: () -> Style
113
+ def unset_padding_bottom: () -> Style
114
+ def unset_padding_left: () -> Style
115
+ def unset_margin_top: () -> Style
116
+ def unset_margin_right: () -> Style
117
+ def unset_margin_bottom: () -> Style
118
+ def unset_margin_left: () -> Style
119
+ def unset_border_style: () -> Style
120
+ def unset_inline: () -> Style
121
+ end
122
+
123
+ class Table
124
+ def initialize: () -> void
125
+ def headers: (Array[_ToS] headers) -> Table
126
+ def row: (Array[_ToS] row) -> Table
127
+ def rows: (Array[Array[_ToS]] rows) -> Table
128
+ def border: (Symbol border_type) -> Table
129
+ def border_style: (Style style) -> Table
130
+ def border_top: (bool value) -> Table
131
+ def border_bottom: (bool value) -> Table
132
+ def border_left: (bool value) -> Table
133
+ def border_right: (bool value) -> Table
134
+ def border_header: (bool value) -> Table
135
+ def border_column: (bool value) -> Table
136
+ def border_row: (bool value) -> Table
137
+ def width: (Integer width) -> Table
138
+ def height: (Integer height) -> Table
139
+ def offset: (Integer offset) -> Table
140
+ def wrap: (bool value) -> Table
141
+ def clear_rows: () -> Table
142
+ def render: () -> String
143
+ def to_s: () -> String
144
+ def _style_func_map: (Hash[String, Style] style_map) -> Table
145
+ end
146
+
147
+ class List
148
+ def initialize: (*String items) -> void
149
+ def item: (String | List item) -> List
150
+ def items: (Array[String] items) -> List
151
+ def enumerator: (Symbol enum_type) -> List
152
+ def enumerator_style: (Style style) -> List
153
+ def item_style: (Style style) -> List
154
+ def render: () -> String
155
+ def to_s: () -> String
156
+ end
157
+
158
+ class Tree
159
+ def initialize: (?String root) -> void
160
+ def self.root: (String root) -> Tree
161
+ def root=: (String root) -> Tree
162
+ def child: (*(String | Tree) children) -> Tree
163
+ def children: (Array[String] children) -> Tree
164
+ def enumerator: (Symbol enum_type) -> Tree
165
+ def enumerator_style: (Style style) -> Tree
166
+ def item_style: (Style style) -> Tree
167
+ def root_style: (Style style) -> Tree
168
+ def offset: (Integer start, Integer end) -> Tree
169
+ def render: () -> String
170
+ def to_s: () -> String
171
+ end
172
+
173
+ module ColorBlend
174
+ LUV: Symbol
175
+ RGB: Symbol
176
+ HCL: Symbol
177
+
178
+ def self.blend: (String c1, String c2, Float t, ?mode: Symbol) -> String
179
+ def self.blend_luv: (String c1, String c2, Float t) -> String
180
+ def self.blend_rgb: (String c1, String c2, Float t) -> String
181
+ def self.blend_hcl: (String c1, String c2, Float t) -> String
182
+ def self.blends: (String c1, String c2, Integer steps, ?mode: Symbol) -> Array[String]
183
+ def self.grid: (String c1, String c2, String c3, String c4, Integer x, Integer y, ?mode: Symbol) -> Array[Array[String]]
184
+ end
185
+ end
@@ -0,0 +1,36 @@
1
+ # Generated from lib/lipgloss/position.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ # Position constants for alignment
5
+ #
6
+ # Positions are represented as floats from 0.0 to 1.0:
7
+ # - 0.0 = top/left
8
+ # - 0.5 = center
9
+ # - 1.0 = bottom/right
10
+ module Position
11
+ # Top alignment (0.0)
12
+ TOP: ::Float
13
+
14
+ # Bottom alignment (1.0)
15
+ BOTTOM: ::Float
16
+
17
+ # Left alignment (0.0)
18
+ LEFT: ::Float
19
+
20
+ # Right alignment (1.0)
21
+ RIGHT: ::Float
22
+
23
+ # Center alignment (0.5)
24
+ CENTER: ::Float
25
+
26
+ type position_symbol = :top | :bottom | :left | :right | :center
27
+
28
+ type position_value = position_symbol | Symbol | String | Integer | Float
29
+
30
+ SYMBOLS: Hash[Symbol, Float]
31
+
32
+ # @rbs value: position_value
33
+ # @rbs return: Float
34
+ def self.resolve: (position_value value) -> Float
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ # Generated from lib/lipgloss/style.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ class Style
5
+ # @rbs *positions: Position::position_value
6
+ # @rbs return: Style
7
+ def align: (*Position::position_value positions) -> Style
8
+
9
+ # @rbs position: Position::position_value
10
+ # @rbs return: Style
11
+ def align_horizontal: (Position::position_value position) -> Style
12
+
13
+ # @rbs position: Position::position_value
14
+ # @rbs return: Style
15
+ def align_vertical: (Position::position_value position) -> Style
16
+
17
+ # @rbs return: Hash[Symbol, untyped]
18
+ def to_h: () -> Hash[Symbol, untyped]
19
+ end
20
+ end
@@ -0,0 +1,40 @@
1
+ # Generated from lib/lipgloss/table.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ # Ruby enhancements for the Table class
5
+ #
6
+ # The Table class is implemented in C, but this module adds
7
+ # Ruby-level conveniences like style_func with blocks.
8
+ class Table
9
+ # Header row constant (used in style_func)
10
+ HEADER_ROW: ::Integer
11
+
12
+ # Set a style function that determines the style for each cell
13
+ #
14
+ # @example Alternating row colors
15
+ # table.style_func(rows: 2, columns: 2) do |row, column|
16
+ # if row == Lipgloss::Table::HEADER_ROW
17
+ # Lipgloss::Style.new.bold(true)
18
+ # elsif row.even?
19
+ # Lipgloss::Style.new.background("#333")
20
+ # else
21
+ # Lipgloss::Style.new.background("#444")
22
+ # end
23
+ # end
24
+ #
25
+ # @example Column-specific styling
26
+ # table.style_func(rows: 2, columns: 2) do |row, column|
27
+ # case column
28
+ # when 0 then Lipgloss::Style.new.bold(true)
29
+ # when 1 then Lipgloss::Style.new.foreground("#00FF00")
30
+ # else Lipgloss::Style.new
31
+ # end
32
+ # end
33
+ #
34
+ # @rbs rows: Integer -- number of data rows in the table
35
+ # @rbs columns: Integer -- number of columns in the table
36
+ # @rbs &block: (Integer, Integer) -> Style? -- block called for each cell position
37
+ # @rbs return: Table -- a new table with the style function applied
38
+ def style_func: (rows: Integer, columns: Integer) { (Integer, Integer) -> Style? } -> Table
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # Generated from lib/lipgloss/version.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ VERSION: String
5
+ end
data/sig/lipgloss.rbs ADDED
@@ -0,0 +1,70 @@
1
+ # Generated from lib/lipgloss.rb with RBS::Inline
2
+
3
+ module Lipgloss
4
+ TOP: Float
5
+
6
+ BOTTOM: Float
7
+
8
+ LEFT: Float
9
+
10
+ RIGHT: Float
11
+
12
+ CENTER: Float
13
+
14
+ NORMAL_BORDER: Symbol
15
+
16
+ ROUNDED_BORDER: Symbol
17
+
18
+ THICK_BORDER: Symbol
19
+
20
+ DOUBLE_BORDER: Symbol
21
+
22
+ HIDDEN_BORDER: Symbol
23
+
24
+ BLOCK_BORDER: Symbol
25
+
26
+ ASCII_BORDER: Symbol
27
+
28
+ NO_TAB_CONVERSION: Integer
29
+
30
+ type color_profile = :true_color | :ansi256 | :ansi | :ascii
31
+
32
+ COLOR_PROFILES: Array[color_profile]
33
+
34
+ # @rbs position: Position::position_value
35
+ # @rbs *strings: String
36
+ # @rbs return: String
37
+ def self.join_horizontal: (Position::position_value position, *String strings) -> String
38
+
39
+ # @rbs position: Position::position_value
40
+ # @rbs *strings: String
41
+ # @rbs return: String
42
+ def self.join_vertical: (Position::position_value position, *String strings) -> String
43
+
44
+ # @rbs width: Integer
45
+ # @rbs height: Integer
46
+ # @rbs horizontal: Position::position_value
47
+ # @rbs vertical: Position::position_value
48
+ # @rbs string: String
49
+ # @rbs return: String
50
+ def self.place: (Integer width, Integer height, Position::position_value horizontal, Position::position_value vertical, String string, **untyped opts) -> String
51
+
52
+ # @rbs width: Integer
53
+ # @rbs position: Position::position_value
54
+ # @rbs string: String
55
+ # @rbs return: String
56
+ def self.place_horizontal: (Integer width, Position::position_value position, String string) -> String
57
+
58
+ # @rbs height: Integer
59
+ # @rbs position: Position::position_value
60
+ # @rbs string: String
61
+ # @rbs return: String
62
+ def self.place_vertical: (Integer height, Position::position_value position, String string) -> String
63
+
64
+ # @rbs return: color_profile
65
+ def self.color_profile: () -> color_profile
66
+
67
+ # @rbs profile: color_profile
68
+ # @rbs return: void
69
+ def self.color_profile=: (color_profile profile) -> void
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lipgloss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
@@ -38,6 +38,7 @@ files:
38
38
  - go/list.go
39
39
  - go/style.go
40
40
  - go/style_border.go
41
+ - go/style_hash.go
41
42
  - go/style_spacing.go
42
43
  - go/style_unset.go
43
44
  - go/table.go
@@ -50,6 +51,14 @@ files:
50
51
  - lib/lipgloss/table.rb
51
52
  - lib/lipgloss/version.rb
52
53
  - lipgloss.gemspec
54
+ - sig/lipgloss.rbs
55
+ - sig/lipgloss/border.rbs
56
+ - sig/lipgloss/color.rbs
57
+ - sig/lipgloss/lipgloss.rbs
58
+ - sig/lipgloss/position.rbs
59
+ - sig/lipgloss/style.rbs
60
+ - sig/lipgloss/table.rbs
61
+ - sig/lipgloss/version.rbs
53
62
  homepage: https://github.com/marcoroth/lipgloss-ruby
54
63
  licenses:
55
64
  - MIT
@@ -72,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
81
  - !ruby/object:Gem::Version
73
82
  version: '0'
74
83
  requirements: []
75
- rubygems_version: 4.0.3
84
+ rubygems_version: 4.0.20
76
85
  specification_version: 4
77
86
  summary: Ruby wrapper for Charm's lipgloss. CSS-like terminal styling library.
78
87
  test_files: []