sai 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/README.md +11 -3
  4. data/docs/USAGE.md +57 -9
  5. data/lib/sai/ansi/color_parser.rb +109 -0
  6. data/lib/sai/ansi/sequence_processor.rb +15 -126
  7. data/lib/sai/ansi/style_parser.rb +66 -0
  8. data/lib/sai/ansi.rb +0 -27
  9. data/lib/sai/conversion/color_sequence.rb +4 -4
  10. data/lib/sai/conversion/rgb/color_classifier.rb +209 -0
  11. data/lib/sai/conversion/rgb/color_indexer.rb +48 -0
  12. data/lib/sai/conversion/rgb/color_space.rb +192 -0
  13. data/lib/sai/conversion/rgb/color_transformer.rb +140 -0
  14. data/lib/sai/conversion/rgb.rb +23 -269
  15. data/lib/sai/decorator/color_manipulations.rb +157 -0
  16. data/lib/sai/decorator/delegation.rb +84 -0
  17. data/lib/sai/decorator/gradients.rb +363 -0
  18. data/lib/sai/decorator/hex_colors.rb +56 -0
  19. data/lib/sai/decorator/named_colors.rb +780 -0
  20. data/lib/sai/decorator/named_styles.rb +276 -0
  21. data/lib/sai/decorator/rgb_colors.rb +64 -0
  22. data/lib/sai/decorator.rb +29 -775
  23. data/lib/sai/named_colors.rb +437 -0
  24. data/lib/sai.rb +731 -23
  25. data/sig/sai/ansi/color_parser.rbs +77 -0
  26. data/sig/sai/ansi/sequence_processor.rbs +0 -75
  27. data/sig/sai/ansi/style_parser.rbs +59 -0
  28. data/sig/sai/ansi.rbs +0 -10
  29. data/sig/sai/conversion/rgb/color_classifier.rbs +165 -0
  30. data/sig/sai/conversion/rgb/color_indexer.rbs +41 -0
  31. data/sig/sai/conversion/rgb/color_space.rbs +129 -0
  32. data/sig/sai/conversion/rgb/color_transformer.rbs +99 -0
  33. data/sig/sai/conversion/rgb.rbs +15 -198
  34. data/sig/sai/decorator/color_manipulations.rbs +125 -0
  35. data/sig/sai/decorator/delegation.rbs +47 -0
  36. data/sig/sai/decorator/gradients.rbs +267 -0
  37. data/sig/sai/decorator/hex_colors.rbs +48 -0
  38. data/sig/sai/decorator/named_colors.rbs +1491 -0
  39. data/sig/sai/decorator/named_styles.rbs +72 -0
  40. data/sig/sai/decorator/rgb_colors.rbs +52 -0
  41. data/sig/sai/decorator.rbs +21 -195
  42. data/sig/sai/named_colors.rbs +65 -0
  43. data/sig/sai.rbs +1468 -44
  44. metadata +32 -4
@@ -0,0 +1,72 @@
1
+ # Generated from lib/sai/decorator/named_styles.rb with RBS::Inline
2
+
3
+ module Sai
4
+ class Decorator
5
+ # Named style methods for the {Decorator} class
6
+ #
7
+ # @author {https://aaronmallen.me Aaron Allen}
8
+ # @since 0.3.1
9
+ #
10
+ # @abstract This module is meant to be included in the {Decorator} class to provide named style methods
11
+ # @api private
12
+ module NamedStyles
13
+ def blink: () -> Decorator
14
+
15
+ def bold: () -> Decorator
16
+
17
+ def conceal: () -> Decorator
18
+
19
+ def dim: () -> Decorator
20
+
21
+ def italic: () -> Decorator
22
+
23
+ def no_blink: () -> Decorator
24
+
25
+ def no_conceal: () -> Decorator
26
+
27
+ def no_italic: () -> Decorator
28
+
29
+ def no_reverse: () -> Decorator
30
+
31
+ def no_strike: () -> Decorator
32
+
33
+ def no_underline: () -> Decorator
34
+
35
+ def normal_intensity: () -> Decorator
36
+
37
+ def rapid_blink: () -> Decorator
38
+
39
+ def reverse: () -> Decorator
40
+
41
+ def strike: () -> Decorator
42
+
43
+ def underline: () -> Decorator
44
+
45
+ private
46
+
47
+ # Apply a style to the text
48
+ #
49
+ # @author {https://aaronmallen.me Aaron Allen}
50
+ # @since 0.1.0
51
+ #
52
+ # @api private
53
+ #
54
+ # @param style [String, Symbol] the style to apply
55
+ #
56
+ # @return [Decorator] a new instance of Decorator with the style applied
57
+ # @rbs (String | Symbol style) -> Decorator
58
+ def apply_style: (String | Symbol style) -> Decorator
59
+
60
+ # Get style sequences
61
+ #
62
+ # @author {https://aaronmallen.me Aaron Allen}
63
+ # @since 0.3.1
64
+ #
65
+ # @api private
66
+ #
67
+ # @return [Array<String>] ANSI sequences for styles
68
+ # @rbs () -> Array[String]
69
+ def style_sequences: () -> Array[String]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,52 @@
1
+ # Generated from lib/sai/decorator/rgb_colors.rb with RBS::Inline
2
+
3
+ module Sai
4
+ class Decorator
5
+ # RGB color methods for the {Decorator} class
6
+ #
7
+ # @author {https://aaronmallen.me Aaron Allen}
8
+ # @since 0.3.1
9
+ #
10
+ # @abstract This module is meant to be included in the {Decorator} class to provide RGB color methods
11
+ # @api private
12
+ module RGBColors
13
+ # Apply an RGB color to the background
14
+ #
15
+ # @author {https://aaronmallen.me Aaron Allen}
16
+ # @since 0.1.0
17
+ #
18
+ # @api public
19
+ #
20
+ # @example
21
+ # decorator.on_rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"
22
+ #
23
+ # @param red [Integer] the red component
24
+ # @param green [Integer] the green component
25
+ # @param blue [Integer] the blue component
26
+ #
27
+ # @raise [ArgumentError] if the RGB values are out of range
28
+ # @return [Decorator] a new instance of Decorator with the RGB color applied
29
+ # @rbs (Integer red, Integer green, Integer blue) -> Decorator
30
+ def on_rgb: (Integer red, Integer green, Integer blue) -> Decorator
31
+
32
+ # Apply an RGB color to the foreground
33
+ #
34
+ # @author {https://aaronmallen.me Aaron Allen}
35
+ # @since 0.1.0
36
+ #
37
+ # @api public
38
+ #
39
+ # @example
40
+ # decorator.rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"
41
+ #
42
+ # @param red [Integer] the red component
43
+ # @param green [Integer] the green component
44
+ # @param blue [Integer] the blue component
45
+ #
46
+ # @raise [ArgumentError] if the RGB values are out of range
47
+ # @return [Decorator] a new instance of Decorator with the RGB color applied
48
+ # @rbs (Integer red, Integer green, Integer blue) -> Decorator
49
+ def rgb: (Integer red, Integer green, Integer blue) -> Decorator
50
+ end
51
+ end
52
+ end
@@ -7,7 +7,28 @@ module Sai
7
7
  # @since 0.1.0
8
8
  #
9
9
  # @api public
10
+ #
11
+ # @note For each named color, two methods are dynamically generated:
12
+ # * color_name - Applies the color to the foreground
13
+ # * on_color_name - Applies the color to the backgroundAll color methods return {Decorator}
14
+ # @see Sai::NamedColors Sai::NamedColors for available color names
15
+ #
16
+ # @example Using a named color
17
+ # decorator.azure.decorate('Hello') #=> "\e[38;2;0;127;255mHello\e[0m"
18
+ # decorator.on_azure.decorate('Hello') #=> "\e[48;2;0;127;255mHello\e[0m"
10
19
  class Decorator
20
+ include ColorManipulations
21
+
22
+ include Gradients
23
+
24
+ include HexColors
25
+
26
+ include NamedColors
27
+
28
+ include NamedStyles
29
+
30
+ include RGBColors
31
+
11
32
  # Initialize a new instance of Decorator
12
33
  #
13
34
  # @author {https://aaronmallen.me Aaron Allen}
@@ -21,102 +42,6 @@ module Sai
21
42
  # @rbs (?mode: Integer) -> void
22
43
  def initialize: (?mode: Integer) -> void
23
44
 
24
- def black: () -> Decorator
25
-
26
- def blue: () -> Decorator
27
-
28
- def bright_black: () -> Decorator
29
-
30
- def bright_blue: () -> Decorator
31
-
32
- def bright_cyan: () -> Decorator
33
-
34
- def bright_green: () -> Decorator
35
-
36
- def bright_magenta: () -> Decorator
37
-
38
- def bright_red: () -> Decorator
39
-
40
- def bright_white: () -> Decorator
41
-
42
- def bright_yellow: () -> Decorator
43
-
44
- def cyan: () -> Decorator
45
-
46
- def green: () -> Decorator
47
-
48
- def magenta: () -> Decorator
49
-
50
- def on_black: () -> Decorator
51
-
52
- def on_blue: () -> Decorator
53
-
54
- def on_bright_black: () -> Decorator
55
-
56
- def on_bright_blue: () -> Decorator
57
-
58
- def on_bright_cyan: () -> Decorator
59
-
60
- def on_bright_green: () -> Decorator
61
-
62
- def on_bright_magenta: () -> Decorator
63
-
64
- def on_bright_red: () -> Decorator
65
-
66
- def on_bright_white: () -> Decorator
67
-
68
- def on_bright_yellow: () -> Decorator
69
-
70
- def on_cyan: () -> Decorator
71
-
72
- def on_green: () -> Decorator
73
-
74
- def on_magenta: () -> Decorator
75
-
76
- def on_red: () -> Decorator
77
-
78
- def on_white: () -> Decorator
79
-
80
- def on_yellow: () -> Decorator
81
-
82
- def red: () -> Decorator
83
-
84
- def white: () -> Decorator
85
-
86
- def yellow: () -> Decorator
87
-
88
- def blink: () -> Decorator
89
-
90
- def bold: () -> Decorator
91
-
92
- def conceal: () -> Decorator
93
-
94
- def dim: () -> Decorator
95
-
96
- def italic: () -> Decorator
97
-
98
- def no_blink: () -> Decorator
99
-
100
- def no_conceal: () -> Decorator
101
-
102
- def no_italic: () -> Decorator
103
-
104
- def no_reverse: () -> Decorator
105
-
106
- def no_strike: () -> Decorator
107
-
108
- def no_underline: () -> Decorator
109
-
110
- def normal_intensity: () -> Decorator
111
-
112
- def rapid_blink: () -> Decorator
113
-
114
- def reverse: () -> Decorator
115
-
116
- def strike: () -> Decorator
117
-
118
- def underline: () -> Decorator
119
-
120
45
  # Apply the styles and colors to the text
121
46
  #
122
47
  # @author {https://aaronmallen.me Aaron Allen}
@@ -139,78 +64,6 @@ module Sai
139
64
 
140
65
  alias encode decorate
141
66
 
142
- # Apply a hexadecimal color to the foreground
143
- #
144
- # @author {https://aaronmallen.me Aaron Allen}
145
- # @since 0.1.0
146
- #
147
- # @api public
148
- #
149
- # @example
150
- # decorator.hex("#EB4133").decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"
151
- #
152
- # @param code [String] the hex color code
153
- #
154
- # @raise [ArgumentError] if the hex code is invalid
155
- # @return [Decorator] a new instance of Decorator with the hex color applied
156
- # @rbs (String code) -> Decorator
157
- def hex: (String code) -> Decorator
158
-
159
- # Apply a hexadecimal color to the background
160
- #
161
- # @author {https://aaronmallen.me Aaron Allen}
162
- # @since 0.1.0
163
- #
164
- # @api public
165
- #
166
- # @example
167
- # decorator.on_hex("#EB4133").decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"
168
- #
169
- # @param code [String] the hex color code
170
- #
171
- # @raise [ArgumentError] if the hex code is invalid
172
- # @return [Decorator] a new instance of Decorator with the hex color applied
173
- # @rbs (String code) -> Decorator
174
- def on_hex: (String code) -> Decorator
175
-
176
- # Apply an RGB color to the background
177
- #
178
- # @author {https://aaronmallen.me Aaron Allen}
179
- # @since 0.1.0
180
- #
181
- # @api public
182
- #
183
- # @example
184
- # decorator.on_rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"
185
- #
186
- # @param red [Integer] the red component
187
- # @param green [Integer] the green component
188
- # @param blue [Integer] the blue component
189
- #
190
- # @raise [ArgumentError] if the RGB values are out of range
191
- # @return [Decorator] a new instance of Decorator with the RGB color applied
192
- # @rbs (Integer red, Integer green, Integer blue) -> Decorator
193
- def on_rgb: (Integer red, Integer green, Integer blue) -> Decorator
194
-
195
- # Apply an RGB color to the foreground
196
- #
197
- # @author {https://aaronmallen.me Aaron Allen}
198
- # @since 0.1.0
199
- #
200
- # @api public
201
- #
202
- # @example
203
- # decorator.rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"
204
- #
205
- # @param red [Integer] the red component
206
- # @param green [Integer] the green component
207
- # @param blue [Integer] the blue component
208
- #
209
- # @raise [ArgumentError] if the RGB values are out of range
210
- # @return [Decorator] a new instance of Decorator with the RGB color applied
211
- # @rbs (Integer red, Integer green, Integer blue) -> Decorator
212
- def rgb: (Integer red, Integer green, Integer blue) -> Decorator
213
-
214
67
  # Apply a specific color mode to the decorator
215
68
  #
216
69
  # @author {https://aaronmallen.me Aaron Allen}
@@ -229,33 +82,6 @@ module Sai
229
82
 
230
83
  private
231
84
 
232
- # Apply a named color to the specified style type
233
- #
234
- # @author {https://aaronmallen.me Aaron Allen}
235
- # @since 0.1.0
236
- #
237
- # @api private
238
- #
239
- # @param style_type [Symbol] the style type to apply the color to
240
- # @param color [Symbol] the color to apply
241
- #
242
- # @return [Decorator] a new instance of Decorator with the color applied
243
- # @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
244
- def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
245
-
246
- # Apply a style to the text
247
- #
248
- # @author {https://aaronmallen.me Aaron Allen}
249
- # @since 0.1.0
250
- #
251
- # @api private
252
- #
253
- # @param style [String, Symbol] the style to apply
254
- #
255
- # @return [Decorator] a new instance of Decorator with the style applied
256
- # @rbs (String | Symbol style) -> self
257
- def apply_style: (String | Symbol style) -> self
258
-
259
85
  # Check if text should be decorated
260
86
  #
261
87
  # @author {https://aaronmallen.me Aaron Allen}
@@ -0,0 +1,65 @@
1
+ # Generated from lib/sai/named_colors.rb with RBS::Inline
2
+
3
+ module Sai
4
+ # A collection of named colors and their RGB values
5
+ #
6
+ # @author {https://aaronmallen.me Aaron Allen}
7
+ # @since 0.3.1
8
+ #
9
+ # @api private
10
+ module NamedColors
11
+ # Standard ANSI color names and their RGB values
12
+ #
13
+ # @author {https://aaronmallen.me Aaron Allen}
14
+ # @since 0.3.1
15
+ #
16
+ # @api private
17
+ #
18
+ # @return [Hash{Symbol => Array<Integer>}] the color names and RGB values
19
+ ANSI: untyped
20
+
21
+ # CSS color names and their RGB values
22
+ #
23
+ # @author {https://aaronmallen.me Aaron Allen}
24
+ # @since 0.3.1
25
+ #
26
+ # @api private
27
+ #
28
+ # @return [Hash{Symbol => Array<Integer>}] the color names and RGB values
29
+ CSS: Hash[Symbol, Array[Integer]]
30
+
31
+ # XTERM color names and their RGB values
32
+ #
33
+ # @author {https://aaronmallen.me Aaron Allen}
34
+ # @since 0.3.1
35
+ #
36
+ # @api private
37
+ #
38
+ # @return [Hash{Symbol => Array<Integer>}] the color names and RGB values
39
+ # rubocop:disable Naming/VariableNumber
40
+ XTERM: Hash[Symbol, Array[Integer]]
41
+
42
+ # Look up an RGB value by color name
43
+ #
44
+ # @author {https://aaronmallen.me Aaron Allen}
45
+ # @since 0.3.1
46
+ #
47
+ # @api private
48
+ #
49
+ # @param name [String, Symbol] the color name
50
+ #
51
+ # @return [Array<Integer>] the RGB value
52
+ # @rbs (String | Symbol name) -> Array[Integer]?
53
+ def self.[]: (String | Symbol name) -> Array[Integer]?
54
+
55
+ # Get a list of all color names
56
+ #
57
+ # @author {https://aaronmallen.me Aaron Allen}
58
+ # @since 0.3.1
59
+ #
60
+ # @api private
61
+ #
62
+ # @return [Array<Symbol>] the color names
63
+ def self.names: () -> untyped
64
+ end
65
+ end