sai 0.1.0 → 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.
@@ -4,123 +4,123 @@ module Sai
4
4
  # A decorator for applying ANSI styles and colors to text
5
5
  #
6
6
  # @author {https://aaronmallen.me Aaron Allen}
7
- # @since unreleased
7
+ # @since 0.1.0
8
8
  #
9
9
  # @api public
10
10
  class Decorator
11
11
  # Initialize a new instance of Decorator
12
12
  #
13
13
  # @author {https://aaronmallen.me Aaron Allen}
14
- # @since unreleased
14
+ # @since 0.1.0
15
15
  #
16
16
  # @api private
17
17
  #
18
- # @param color_mode [Integer] the color mode to use
18
+ # @param mode [Integer] the color mode to use
19
19
  #
20
20
  # @return [Decorator] the new instance of Decorator
21
- # @rbs (Integer color_mode) -> void
22
- def initialize: (Integer color_mode) -> void
21
+ # @rbs (?mode: Integer) -> void
22
+ def initialize: (?mode: Integer) -> void
23
23
 
24
- def black: () -> self
24
+ def black: () -> Decorator
25
25
 
26
- def blue: () -> self
26
+ def blue: () -> Decorator
27
27
 
28
- def bright_black: () -> self
28
+ def bright_black: () -> Decorator
29
29
 
30
- def bright_blue: () -> self
30
+ def bright_blue: () -> Decorator
31
31
 
32
- def bright_cyan: () -> self
32
+ def bright_cyan: () -> Decorator
33
33
 
34
- def bright_green: () -> self
34
+ def bright_green: () -> Decorator
35
35
 
36
- def bright_magenta: () -> self
36
+ def bright_magenta: () -> Decorator
37
37
 
38
- def bright_red: () -> self
38
+ def bright_red: () -> Decorator
39
39
 
40
- def bright_white: () -> self
40
+ def bright_white: () -> Decorator
41
41
 
42
- def bright_yellow: () -> self
42
+ def bright_yellow: () -> Decorator
43
43
 
44
- def cyan: () -> self
44
+ def cyan: () -> Decorator
45
45
 
46
- def green: () -> self
46
+ def green: () -> Decorator
47
47
 
48
- def magenta: () -> self
48
+ def magenta: () -> Decorator
49
49
 
50
- def on_black: () -> self
50
+ def on_black: () -> Decorator
51
51
 
52
- def on_blue: () -> self
52
+ def on_blue: () -> Decorator
53
53
 
54
- def on_bright_black: () -> self
54
+ def on_bright_black: () -> Decorator
55
55
 
56
- def on_bright_blue: () -> self
56
+ def on_bright_blue: () -> Decorator
57
57
 
58
- def on_bright_cyan: () -> self
58
+ def on_bright_cyan: () -> Decorator
59
59
 
60
- def on_bright_green: () -> self
60
+ def on_bright_green: () -> Decorator
61
61
 
62
- def on_bright_magenta: () -> self
62
+ def on_bright_magenta: () -> Decorator
63
63
 
64
- def on_bright_red: () -> self
64
+ def on_bright_red: () -> Decorator
65
65
 
66
- def on_bright_white: () -> self
66
+ def on_bright_white: () -> Decorator
67
67
 
68
- def on_bright_yellow: () -> self
68
+ def on_bright_yellow: () -> Decorator
69
69
 
70
- def on_cyan: () -> self
70
+ def on_cyan: () -> Decorator
71
71
 
72
- def on_green: () -> self
72
+ def on_green: () -> Decorator
73
73
 
74
- def on_magenta: () -> self
74
+ def on_magenta: () -> Decorator
75
75
 
76
- def on_red: () -> self
76
+ def on_red: () -> Decorator
77
77
 
78
- def on_white: () -> self
78
+ def on_white: () -> Decorator
79
79
 
80
- def on_yellow: () -> self
80
+ def on_yellow: () -> Decorator
81
81
 
82
- def red: () -> self
82
+ def red: () -> Decorator
83
83
 
84
- def white: () -> self
84
+ def white: () -> Decorator
85
85
 
86
- def yellow: () -> self
86
+ def yellow: () -> Decorator
87
87
 
88
- def blink: () -> self
88
+ def blink: () -> Decorator
89
89
 
90
- def bold: () -> self
90
+ def bold: () -> Decorator
91
91
 
92
- def conceal: () -> self
92
+ def conceal: () -> Decorator
93
93
 
94
- def dim: () -> self
94
+ def dim: () -> Decorator
95
95
 
96
- def italic: () -> self
96
+ def italic: () -> Decorator
97
97
 
98
- def no_blink: () -> self
98
+ def no_blink: () -> Decorator
99
99
 
100
- def no_conceal: () -> self
100
+ def no_conceal: () -> Decorator
101
101
 
102
- def no_italic: () -> self
102
+ def no_italic: () -> Decorator
103
103
 
104
- def no_reverse: () -> self
104
+ def no_reverse: () -> Decorator
105
105
 
106
- def no_strike: () -> self
106
+ def no_strike: () -> Decorator
107
107
 
108
- def no_underline: () -> self
108
+ def no_underline: () -> Decorator
109
109
 
110
- def normal_intensity: () -> self
110
+ def normal_intensity: () -> Decorator
111
111
 
112
- def rapid_blink: () -> self
112
+ def rapid_blink: () -> Decorator
113
113
 
114
- def reverse: () -> self
114
+ def reverse: () -> Decorator
115
115
 
116
- def strike: () -> self
116
+ def strike: () -> Decorator
117
117
 
118
- def underline: () -> self
118
+ def underline: () -> Decorator
119
119
 
120
120
  # Apply the styles and colors to the text
121
121
  #
122
122
  # @author {https://aaronmallen.me Aaron Allen}
123
- # @since unreleased
123
+ # @since 0.1.0
124
124
  #
125
125
  # @api public
126
126
  #
@@ -143,7 +143,7 @@ module Sai
143
143
  # Apply a hexadecimal color to the foreground
144
144
  #
145
145
  # @author {https://aaronmallen.me Aaron Allen}
146
- # @since unreleased
146
+ # @since 0.1.0
147
147
  #
148
148
  # @api public
149
149
  #
@@ -153,14 +153,14 @@ module Sai
153
153
  # @param code [String] the hex color code
154
154
  #
155
155
  # @raise [ArgumentError] if the hex code is invalid
156
- # @return [self] the instance of Decorator for chaining
157
- # @rbs (String code) -> self
158
- def hex: (String code) -> self
156
+ # @return [Decorator] a new instance of Decorator with the hex color applied
157
+ # @rbs (String code) -> Decorator
158
+ def hex: (String code) -> Decorator
159
159
 
160
160
  # Apply a hexadecimal color to the background
161
161
  #
162
162
  # @author {https://aaronmallen.me Aaron Allen}
163
- # @since unreleased
163
+ # @since 0.1.0
164
164
  #
165
165
  # @api public
166
166
  #
@@ -170,14 +170,14 @@ module Sai
170
170
  # @param code [String] the hex color code
171
171
  #
172
172
  # @raise [ArgumentError] if the hex code is invalid
173
- # @return [self] the instance of Decorator for chaining
174
- # @rbs (String code) -> self
175
- def on_hex: (String code) -> self
173
+ # @return [Decorator] a new instance of Decorator with the hex color applied
174
+ # @rbs (String code) -> Decorator
175
+ def on_hex: (String code) -> Decorator
176
176
 
177
177
  # Apply an RGB color to the background
178
178
  #
179
179
  # @author {https://aaronmallen.me Aaron Allen}
180
- # @since unreleased
180
+ # @since 0.1.0
181
181
  #
182
182
  # @api public
183
183
  #
@@ -189,14 +189,14 @@ module Sai
189
189
  # @param blue [Integer] the blue component
190
190
  #
191
191
  # @raise [ArgumentError] if the RGB values are out of range
192
- # @return [self] the instance of Decorator for chaining
193
- # @rbs (Integer red, Integer green, Integer blue) -> self
194
- def on_rgb: (Integer red, Integer green, Integer blue) -> self
192
+ # @return [Decorator] a new instance of Decorator with the RGB color applied
193
+ # @rbs (Integer red, Integer green, Integer blue) -> Decorator
194
+ def on_rgb: (Integer red, Integer green, Integer blue) -> Decorator
195
195
 
196
196
  # Apply an RGB color to the foreground
197
197
  #
198
198
  # @author {https://aaronmallen.me Aaron Allen}
199
- # @since unreleased
199
+ # @since 0.1.0
200
200
  #
201
201
  # @api public
202
202
  #
@@ -208,16 +208,32 @@ module Sai
208
208
  # @param blue [Integer] the blue component
209
209
  #
210
210
  # @raise [ArgumentError] if the RGB values are out of range
211
- # @return [self] the instance of Decorator for chaining
212
- # @rbs (Integer red, Integer green, Integer blue) -> self
213
- def rgb: (Integer red, Integer green, Integer blue) -> self
211
+ # @return [Decorator] a new instance of Decorator with the RGB color applied
212
+ # @rbs (Integer red, Integer green, Integer blue) -> Decorator
213
+ def rgb: (Integer red, Integer green, Integer blue) -> Decorator
214
+
215
+ # Apply a specific color mode to the decorator
216
+ #
217
+ # @author {https://aaronmallen.me Aaron Allen}
218
+ # @since 0.2.0
219
+ #
220
+ # @api public
221
+ #
222
+ # @example
223
+ # decorator.with_mode(Sai.mode.basic_auto) #=> => #<Sai::Decorator:0x123 @mode=1>
224
+ #
225
+ # @param mode [Integer] the color mode to use
226
+ #
227
+ # @return [Decorator] a new instance of Decorator with the applied color mode
228
+ # @rbs (Integer mode) -> Decorator
229
+ def with_mode: (Integer mode) -> Decorator
214
230
 
215
231
  private
216
232
 
217
233
  # Apply a named color to the specified style type
218
234
  #
219
235
  # @author {https://aaronmallen.me Aaron Allen}
220
- # @since unreleased
236
+ # @since 0.1.0
221
237
  #
222
238
  # @api private
223
239
  #
@@ -225,22 +241,33 @@ module Sai
225
241
  # @param color [Symbol] the color to apply
226
242
  #
227
243
  # @raise [ArgumentError] if the color is invalid
228
- # @return [self] the instance of Decorator for chaining
229
- # @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> self
230
- def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> self
244
+ # @return [Decorator] a new instance of Decorator with the color applied
245
+ # @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
246
+ def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
231
247
 
232
248
  # Apply a style to the text
233
249
  #
234
250
  # @author {https://aaronmallen.me Aaron Allen}
235
- # @since unreleased
251
+ # @since 0.1.0
236
252
  #
237
253
  # @api private
238
254
  #
239
255
  # @param style [String, Symbol] the style to apply
240
256
  #
241
257
  # @raise [ArgumentError] if the style is invalid
242
- # @return [self] the instance of Decorator for chaining
258
+ # @return [Decorator] a new instance of Decorator with the style applied
243
259
  # @rbs (String | Symbol style) -> self
244
260
  def apply_style: (String | Symbol style) -> self
261
+
262
+ # Check if text should be decorated
263
+ #
264
+ # @author {https://aaronmallen.me Aaron Allen}
265
+ # @since 0.2.0
266
+ #
267
+ # @api private
268
+ #
269
+ # @return [Boolean] `true` if text should be decorated, `false` otherwise
270
+ # @rbs () -> bool
271
+ def should_decorate?: () -> bool
245
272
  end
246
273
  end
@@ -0,0 +1,319 @@
1
+ # Generated from lib/sai/mode_selector.rb with RBS::Inline
2
+
3
+ module Sai
4
+ # Color mode selection methods
5
+ #
6
+ # @author {https://aaronmallen.me Aaron Allen}
7
+ # @since 0.2.0
8
+ #
9
+ # @api public
10
+ module ModeSelector
11
+ # Set the color mode to 256 color (8-bit) mode
12
+ #
13
+ # @author {https://aaronmallen.me Aaron Allen}
14
+ # @since 0.2.0
15
+ #
16
+ # @api private
17
+ #
18
+ # @example
19
+ # Sai.mode.advanced #=> 3
20
+ # Sai.mode.eight_bit #=> 3
21
+ # Sai.mode.color256 #=> 3
22
+ #
23
+ # @return [Integer] the color mode
24
+ # @rbs () -> Integer
25
+ def self.advanced: () -> Integer
26
+
27
+ alias self.color256 self.advanced
28
+
29
+ alias self.colour256 self.advanced
30
+
31
+ alias self.eight_bit self.advanced
32
+
33
+ alias self.two_hundred_fifty_six_color self.advanced
34
+
35
+ alias self.two_hundred_fifty_six_colour self.advanced
36
+
37
+ # Automatically set the color mode to advanced (8-bit) or lower
38
+ #
39
+ # Sets the terminal color mode to advanced (8-bit) support, which provides 256 colors
40
+ # The mode will automatically downgrade to 4-bit, 3-bit, or NO_COLOR if the terminal doesn't support
41
+ # advanced colors
42
+ #
43
+ # @author {https://aaronmallen.me Aaron Allen}
44
+ # @since 0.2.0
45
+ #
46
+ # @api public
47
+ #
48
+ # @example With color support enabled
49
+ # ENV['COLORTERM'] #=> nil
50
+ # ENV['TERM'] #=> 'xterm-256color'
51
+ # Sai.mode.ansi_auto #=> 3
52
+ # Sai.mode.four_bit_auto #=> 3
53
+ # Sai.mode.color_16_auto #=> 3
54
+ #
55
+ # @example With only 4-bit color support
56
+ # ENV['NO_COLOR'] #=> nil
57
+ # ENV['TERM'] #=> 'ansi'
58
+ # Sai.mode.ansi_auto #=> 2
59
+ # Sai.mode.four_bit_auto #=> 2
60
+ # Sai.mode.color_16_auto #=> 2
61
+ #
62
+ # @example With only 3-bit color support
63
+ # ENV['TERM'] #=> nil
64
+ # ENV['NO_COLOR'] #=> nil
65
+ # Sai.mode.ansi_auto #=> 1
66
+ # Sai.mode.four_bit_auto #=> 1
67
+ # Sai.mode.color16_auto #=> 1
68
+ #
69
+ # @example With color support disabled
70
+ # ENV['NO_COLOR'] #=> 'true'
71
+ # Sai.mode.ansi_auto #=> 0
72
+ # Sai.mode.four_bit_auto #=> 0
73
+ # Sai.mode.color16_auto #=> 0
74
+ #
75
+ # @return [Integer] the color mode
76
+ # @rbs () -> Integer
77
+ def self.advanced_auto: () -> Integer
78
+
79
+ alias self.color256_auto self.advanced_auto
80
+
81
+ alias self.colour256_auto self.advanced_auto
82
+
83
+ alias self.eight_bit_auto self.advanced_auto
84
+
85
+ alias self.two_hundred_fifty_six_color_auto self.advanced_auto
86
+
87
+ alias self.two_hundred_fifty_six_colour_auto self.advanced_auto
88
+
89
+ # Set the color mode to 16 color (4-bit) mode
90
+ #
91
+ # @author {https://aaronmallen.me Aaron Allen}
92
+ # @since 0.2.0
93
+ #
94
+ # @api public
95
+ #
96
+ # @example
97
+ # Sai.mode.ansi #=> 2
98
+ # Sai.mode.color16 #=> 2
99
+ # Sai.mode.four_bit #=> 2
100
+ #
101
+ # @return [Integer] the color mode
102
+ # @rbs () -> Integer
103
+ def self.ansi: () -> Integer
104
+
105
+ alias self.color16 self.ansi
106
+
107
+ alias self.colour16 self.ansi
108
+
109
+ alias self.four_bit self.ansi
110
+
111
+ alias self.sixteen_color self.ansi
112
+
113
+ alias self.sixteen_colour self.ansi
114
+
115
+ # Automatically set the color mode to ansi (4-bit) or lower
116
+ #
117
+ # Sets the terminal color mode to ansi (4-bit) support, which provides 8 colors
118
+ # The mode will automatically downgrade to 3-bit or NO_COLOR if the terminal doesn't support
119
+ # ansi colors
120
+ #
121
+ # @author {https://aaronmallen.me Aaron Allen}
122
+ # @since 0.2.0
123
+ #
124
+ # @api public
125
+ #
126
+ # @example With color support enabled
127
+ # ENV['NO_COLOR'] #=> nil
128
+ # ENV['TERM'] #=> 'ansi'
129
+ # Sai.mode.ansi_auto #=> 2
130
+ # Sai.mode.four_bit_auto #=> 2
131
+ # Sai.mode.color_16_auto #=> 2
132
+ #
133
+ # @example With only 3-bit color support
134
+ # ENV['TERM'] #=> nil
135
+ # ENV['NO_COLOR'] #=> nil
136
+ # Sai.mode.ansi_auto #=> 1
137
+ # Sai.mode.four_bit_auto #=> 1
138
+ # Sai.mode.color16_auto #=> 1
139
+ #
140
+ # @example With color support disabled
141
+ # ENV['NO_COLOR'] #=> 'true'
142
+ # Sai.mode.ansi_auto #=> 0
143
+ # Sai.mode.four_bit_auto #=> 0
144
+ # Sai.mode.color16_auto #=> 0
145
+ #
146
+ # @return [Integer] the color mode
147
+ # @rbs () -> Integer
148
+ def self.ansi_auto: () -> Integer
149
+
150
+ alias self.color16_auto self.ansi_auto
151
+
152
+ alias self.colour16_auto self.ansi_auto
153
+
154
+ alias self.four_bit_auto self.ansi_auto
155
+
156
+ alias self.sixteen_color_auto self.ansi_auto
157
+
158
+ alias self.sixteen_colour_auto self.ansi_auto
159
+
160
+ # Set the color mode based on the current Terminal's capabilities
161
+ #
162
+ # This is the default color mode for {Sai}
163
+ #
164
+ # @author {https://aaronmallen.me Aaron Allen}
165
+ # @since 0.2.0
166
+ #
167
+ # @api public
168
+ #
169
+ # @example With 24-bit color support enabled
170
+ # ENV['COLORTERM'] #=> 'truecolor'
171
+ # Sai.node.auto #=> 4
172
+ #
173
+ # @example With only 8-bit color support enabled
174
+ # ENV['COLORTERM'] #=> nil
175
+ # ENV['TERM'] #=> 'xterm-256color'
176
+ # Sai.mode.auto #=> 3
177
+ #
178
+ # @example With only 4-bit color support
179
+ # ENV['NO_COLOR'] #=> nil
180
+ # ENV['TERM'] #=> 'ansi'
181
+ # Sai.mode.auto #=> 2
182
+ #
183
+ # @example With only 3-bit color support
184
+ # ENV['TERM'] #=> nil
185
+ # ENV['NO_COLOR'] #=> nil
186
+ # Sai.mode.auto #=> 1
187
+ #
188
+ # @example With color support disabled
189
+ # ENV['NO_COLOR'] #=> 'true'
190
+ # Sai.mode.auto #=> 0
191
+ #
192
+ # @return [Integer] the color mode
193
+ # @rbs () -> Integer
194
+ def self.auto: () -> Integer
195
+
196
+ alias self.color16m_auto self.auto
197
+
198
+ alias self.colour16m_auto self.auto
199
+
200
+ alias self.enabled self.auto
201
+
202
+ alias self.sixteen_million_color_auto self.auto
203
+
204
+ alias self.sixteen_million_colour_auto self.auto
205
+
206
+ alias self.twenty_for_bit_auto self.auto
207
+
208
+ # Set the color mode to 8 color (3-bit) mode
209
+ #
210
+ # @author {https://aaronmallen.me Aaron Allen}
211
+ # @since 0.2.0
212
+ #
213
+ # @api public
214
+ #
215
+ # @example
216
+ # Sai.mode.basic #=> 1
217
+ # Sai.mode.color8 #=> 1
218
+ # Sai.mode.three_bit #=> 1
219
+ #
220
+ # @return [Integer] the 4 color (3-bit) mode
221
+ # @rbs () -> Integer
222
+ def self.basic: () -> Integer
223
+
224
+ alias self.color8 self.basic
225
+
226
+ alias self.colour8 self.basic
227
+
228
+ alias self.eight_color self.basic
229
+
230
+ alias self.eight_colour self.basic
231
+
232
+ alias self.three_bit self.basic
233
+
234
+ # Automatically set the color mode to basic (3-bit) or lower
235
+ #
236
+ # Sets the terminal color mode to basic (3-bit) support, which provides 8 colors
237
+ # The mode will automatically downgrade to NO_COLOR if the terminal doesn't support
238
+ # basic colors
239
+ #
240
+ # @author {https://aaronmallen.me Aaron Allen}
241
+ # @since 0.2.0
242
+ #
243
+ # @api public
244
+ #
245
+ # @example With color support enabled
246
+ # ENV['NO_COLOR'] #=> nil
247
+ # Sai.mode.basic_auto #=> 1
248
+ # Sai.mode.three_bit_auto #=> 1
249
+ # Sai.mode.color8_auto #=> 1
250
+ #
251
+ # @example With color support disabled
252
+ # ENV['NO_COLOR'] #=> 'true'
253
+ # Sai.mode.basic_auto #=> 0
254
+ # Sai.mode.three_bit_auto #=> 0
255
+ # Sai.mode.color8_auto #=> 0
256
+ #
257
+ # @return [Integer] the color mode
258
+ # @rbs () -> Integer
259
+ def self.basic_auto: () -> Integer
260
+
261
+ alias self.color8_auto self.basic_auto
262
+
263
+ alias self.colour8_auto self.basic_auto
264
+
265
+ alias self.eight_color_auto self.basic_auto
266
+
267
+ alias self.eight_colour_auto self.basic_auto
268
+
269
+ alias self.three_bit_auto self.basic_auto
270
+
271
+ # Set the color mode to disable all color and styling
272
+ #
273
+ # @author {https://aaronmallen.me Aaron Allen}
274
+ # @since 0.2.0
275
+ #
276
+ # @api public
277
+ #
278
+ # @example
279
+ # Sai.mode.no_color #=> 0
280
+ # Sai.mode.disabled #=> 0
281
+ # Sai.mode.mono #=> 0
282
+ #
283
+ # @return [Integer] the color mode
284
+ # @rbs () -> Integer
285
+ def self.no_color: () -> Integer
286
+
287
+ alias self.disabled self.no_color
288
+
289
+ alias self.mono self.no_color
290
+
291
+ alias self.no_colour self.no_color
292
+
293
+ # Set the color mode to 16-million color (24-bit) mode
294
+ #
295
+ # @author {https://aaronmallen.me Aaron Allen}
296
+ # @since 0.2.0
297
+ #
298
+ # @api private
299
+ #
300
+ # @example
301
+ # Sai.mode.true_color #=> 4
302
+ # Sai.mode.twenty_four_bit #=> 4
303
+ # Sai.mode.color_16m #=> 4
304
+ #
305
+ # @return [Integer] the color mode
306
+ # @rbs () -> Integer
307
+ def self.true_color: () -> Integer
308
+
309
+ alias self.color16m self.true_color
310
+
311
+ alias self.colour16m self.true_color
312
+
313
+ alias self.sixteen_million_color self.true_color
314
+
315
+ alias self.sixteen_million_colour self.true_color
316
+
317
+ alias self.twenty_for_bit self.true_color
318
+ end
319
+ end