sai 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +38 -1
  4. data/README.md +39 -241
  5. data/docs/USAGE.md +351 -0
  6. data/lib/sai/ansi/color_parser.rb +109 -0
  7. data/lib/sai/ansi/sequence_processor.rb +269 -0
  8. data/lib/sai/ansi/sequenced_string.rb +475 -0
  9. data/lib/sai/ansi/style_parser.rb +66 -0
  10. data/lib/sai/ansi.rb +0 -27
  11. data/lib/sai/conversion/color_sequence.rb +4 -4
  12. data/lib/sai/conversion/rgb/color_classifier.rb +209 -0
  13. data/lib/sai/conversion/rgb/color_indexer.rb +48 -0
  14. data/lib/sai/conversion/rgb/color_space.rb +192 -0
  15. data/lib/sai/conversion/rgb/color_transformer.rb +140 -0
  16. data/lib/sai/conversion/rgb.rb +23 -269
  17. data/lib/sai/decorator/color_manipulations.rb +157 -0
  18. data/lib/sai/decorator/delegation.rb +84 -0
  19. data/lib/sai/decorator/gradients.rb +363 -0
  20. data/lib/sai/decorator/hex_colors.rb +56 -0
  21. data/lib/sai/decorator/named_colors.rb +780 -0
  22. data/lib/sai/decorator/named_styles.rb +276 -0
  23. data/lib/sai/decorator/rgb_colors.rb +64 -0
  24. data/lib/sai/decorator.rb +35 -795
  25. data/lib/sai/mode_selector.rb +19 -19
  26. data/lib/sai/named_colors.rb +437 -0
  27. data/lib/sai.rb +753 -23
  28. data/sig/manifest.yaml +3 -0
  29. data/sig/sai/ansi/color_parser.rbs +77 -0
  30. data/sig/sai/ansi/sequence_processor.rbs +178 -0
  31. data/sig/sai/ansi/sequenced_string.rbs +380 -0
  32. data/sig/sai/ansi/style_parser.rbs +59 -0
  33. data/sig/sai/ansi.rbs +0 -10
  34. data/sig/sai/conversion/rgb/color_classifier.rbs +165 -0
  35. data/sig/sai/conversion/rgb/color_indexer.rbs +41 -0
  36. data/sig/sai/conversion/rgb/color_space.rbs +129 -0
  37. data/sig/sai/conversion/rgb/color_transformer.rbs +99 -0
  38. data/sig/sai/conversion/rgb.rbs +15 -198
  39. data/sig/sai/decorator/color_manipulations.rbs +125 -0
  40. data/sig/sai/decorator/delegation.rbs +47 -0
  41. data/sig/sai/decorator/gradients.rbs +267 -0
  42. data/sig/sai/decorator/hex_colors.rbs +48 -0
  43. data/sig/sai/decorator/named_colors.rbs +1491 -0
  44. data/sig/sai/decorator/named_styles.rbs +72 -0
  45. data/sig/sai/decorator/rgb_colors.rbs +52 -0
  46. data/sig/sai/decorator.rbs +25 -202
  47. data/sig/sai/mode_selector.rbs +19 -19
  48. data/sig/sai/named_colors.rbs +65 -0
  49. data/sig/sai.rbs +1485 -44
  50. metadata +38 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d27e2e0d0202e3dc41887be8cfa58f3d862fdee0c9fc3dbd0db792bac1d8f91
4
- data.tar.gz: c1a6cd0918fd89b72fe1bd22479192354293a270803297fe901df818032fbfb5
3
+ metadata.gz: 0c45105e60b5f7a3a93d837080975996e96a340aef0ad3fd86cd4b5a1be17e8f
4
+ data.tar.gz: baf93c18ef40221c86c329deeeaabbe7a3619744d3a80a9349314624a4af3995
5
5
  SHA512:
6
- metadata.gz: 958aae38da9095a09347a97dd5eddca62a2ac2b4f2eddf51ee4e5b11f4ffdeed26918dad6f00bd85129f82de8eafbde5eb1ed6e3c6a8136d6d5ad6cf3b3765fe
7
- data.tar.gz: cce26cf788ae60731b58cf2460cea923bda925db36a75f009ec4846046edf47afbd10a81990c7651a0cde21d1090c725dbc7b5e290f412968b83c0dc5f61e1db
6
+ metadata.gz: c1540fe3fd55f0a338ff04ff6f9794e831b831c040637f4cdd4f0de0ab0a689a55f95d5c1a744f3ae25b0bc7452983044568e83b6e665439672142cd2abd811b
7
+ data.tar.gz: 4244b0401b7fd0af26665a0a5b5622dd09bd364e4166bc8d12a6c69f94a52b09511d56afe2cd8eaedf1401c402b3ba63845aa900c147e408312221dcc243e21d
data/.yardopts CHANGED
@@ -8,4 +8,4 @@ lib/**/*.rb
8
8
  --embed-mixins
9
9
  --tag rbs
10
10
  --hide-tag rbs
11
- --files LICENSE
11
+ --files LICENSE,docs/USAGE.md
data/CHANGELOG.md CHANGED
@@ -6,6 +6,41 @@ The format is based on [Keep a Changelog], and this project adheres to [Break Ve
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.1] - 2025-01-22
10
+
11
+ ### Added
12
+
13
+ * [#8](https://github.com/aaronmallen/sai/pull/8) - Add color manipulation methods for darkening and lightening colors
14
+ by [@aaronmallen](https://github.com/aaronmallen)
15
+ * [#9](https://github.com/aaronmallen/sai/pull/9) - Add gradient and rainbow color effects for text and backgrounds by
16
+ [@aaronmallen](https://github.com/aaronmallen)
17
+ * [#13](https://github.com/aaronmallen/sai/pull/13) - Add support for over 360 named colors expanding the color palette
18
+ by [@aaronmallen](https://github.com/aaronmallen)
19
+
20
+ ### Changed
21
+
22
+ * [#10](https://github.com/aaronmallen/sai/pull/10) - Refactor `Sai::Decorator` into component modules by
23
+ [@aaronmallen](https://github.com/aaronmallen)
24
+ * [#11](https://github.com/aaronmallen/sai/pull/11) - Refactor `Sai::Conversion::RGB` into component modules by
25
+ [@aaronmallen](https://github.com/aaronmallen)
26
+ * [#12](https://github.com/aaronmallen/sai/pull/12) - Refactor ANSI sequence processing into specialized parser classes
27
+ by [@aaronmallen](https://github.com/aaronmallen)
28
+
29
+ ## [0.3.0] - 2025-01-20
30
+
31
+ ### Added
32
+
33
+ * [#6](https://github.com/aaronmallen/sai/pull/6) - Add `Sai::ANSI::SequencedString` for ANSI string manipulation by
34
+ [@aaronmallen](https://github.com/aaronmallen)
35
+
36
+ ### Changed
37
+
38
+ * [#5](https://github.com/aaronmallen/sai/pull/5) - Remove unnecessary error handling in `Sai::Decorator` by
39
+ [@aaronmallen](https://github.com/aaronmallen)
40
+
41
+ * [#6](https://github.com/aaronmallen/sai/pull/6) - Changed `Sai::Decorator#decorate` now returns a
42
+ `Sai::ANSI::SequencedString` by [@aaronmallen](https://github.com/aaronmallen)
43
+
9
44
  ## [0.2.0] - 2025-01-20
10
45
 
11
46
  ### Added
@@ -29,5 +64,7 @@ The format is based on [Keep a Changelog], and this project adheres to [Break Ve
29
64
 
30
65
  <!-- versions -->
31
66
 
32
- [Unreleased]: https://github.com/aaronmallen/sai/compare/0.2.0..HEAD
67
+ [Unreleased]: https://github.com/aaronmallen/sai/compare/0.3.1..HEAD
68
+ [0.3.1]: https://github.com/aaronmallen/sai/compare/0.3.0..0.3.1
69
+ [0.3.0]: https://github.com/aaronmallen/sai/compare/0.2.0..0.3.0
33
70
  [0.2.0]: https://github.com/aaronmallen/sai/compare/0.1.0..0.2.0
data/README.md CHANGED
@@ -1,36 +1,43 @@
1
1
  # Sai
2
2
 
3
3
  [![Sai Version](https://img.shields.io/gem/v/sai?style=for-the-badge&logo=rubygems&logoColor=white&logoSize=auto&label=Gem%20Version)](https://rubygems.org/gems/sai)
4
+ [![Sai Codacy grade](https://img.shields.io/codacy/grade/0f9a91b573ed4768a773867b95ed4894/main?style=for-the-badge&logo=codacy&logoColor=white&logoSize=auto)](https://app.codacy.com/gh/aaronmallen/sai)
5
+ [![Sai Codacy coverage](https://img.shields.io/codacy/coverage/0f9a91b573ed4768a773867b95ed4894/main?style=for-the-badge&logo=codacy&logoColor=white&logoSize=auto)](https://app.codacy.com/gh/aaronmallen/sai/coverage)
4
6
  [![Sai License](https://img.shields.io/github/license/aaronmallen/sai?style=for-the-badge&logo=opensourceinitiative&logoColor=white&logoSize=auto)](./LICENSE)
5
- [![Sai Docs](https://img.shields.io/badge/rubydoc-blue?style=for-the-badge&logo=readthedocs&logoColor=white&logoSize=auto&label=docs)](https://rubydoc.info/gems/sai/0.2.0)
7
+ [![Sai Docs](https://img.shields.io/badge/rubydoc-blue?style=for-the-badge&logo=readthedocs&logoColor=white&logoSize=auto&label=docs)](https://rubydoc.info/gems/sai/0.3.1)
6
8
  [![Sai Open Issues](https://img.shields.io/github/issues-search/aaronmallen/sai?query=state%3Aopen&style=for-the-badge&logo=github&logoColor=white&logoSize=auto&label=issues&color=red)](https://github.com/aaronmallen/sai/issues?q=state%3Aopen%20)
7
9
 
8
10
  An elegant color management system for crafting sophisticated CLI applications
9
11
 
10
12
  ```ruby
11
- puts Sai.rgb(255, 128, 0).bold.decorate('Create beautiful CLI applications')
12
- puts Sai.hex('#4834d4').italic.decorate('with intuitive color management')
13
- puts Sai.bright_cyan.on_blue.underline.decorate('that adapts to any terminal')
13
+ # Create beautiful CLI applications with intuitive color management
14
+ puts Sai.rgb(255, 128, 0).bold.decorate('Warning: Battery Low')
15
+ puts Sai.hex('#4834d4').italic.decorate('Processing request...')
16
+ puts Sai.bright_cyan.on_blue.underline.decorate('Download Complete!')
17
+
18
+ # Adjust color brightness
19
+ puts Sai.red.darken_text(0.3).decorate('Subtle Error Message')
20
+ puts Sai.blue.lighten_text(0.5).decorate('Highlighted Info')
21
+
22
+ # Analyze and manipulate ANSI-encoded text
23
+ text = Sai.sequence("\e[31mError:\e[0m Connection failed")
24
+ puts text.without_color # Keep formatting, remove colors
25
+ puts text.stripped # Get plain text without any formatting
14
26
  ```
15
27
 
16
28
  Sai (彩) - meaning 'coloring' or 'paint' in Japanese - is a powerful and intuitive system for managing color output in
17
29
  command-line applications. Drawing inspiration from traditional Japanese artistic techniques, Sai brings vibrancy and
18
30
  harmony to terminal interfaces through its sophisticated color management.
19
31
 
20
- Sai empowers developers to create beautiful, colorful CLI applications that maintain visual consistency across different
21
- terminal capabilities. Like its artistic namesake, it combines simplicity and sophistication to bring rich, adaptive
22
- color to your terminal interfaces.
23
-
24
32
  ## Features
25
33
 
26
- * Automatic color mode detection and downgrading
27
- * Support for True Color (24-bit), 256 colors (8-bit), ANSI colors (4-bit), and basic colors (3-bit)
28
- * Rich set of ANSI text styles
29
- * Named color support with bright variants
30
- * RGB and Hex color support
31
- * Foreground and background colors
34
+ * Rich color support (True Color, 256 colors, ANSI, and basic modes)
35
+ * Automatic terminal capability detection and color mode adaptation
36
+ * RGB, Hex, and named color (**over 360 named colors**) support with bright variants
37
+ * Comprehensive text styling (bold, italic, underline, etc.)
38
+ * Advanced ANSI sequence parsing and manipulation
39
+ * Intelligent color downgrading for compatibility
32
40
  * Respects NO_COLOR environment variable
33
- * Can be used directly or included in classes/modules
34
41
 
35
42
  ## Installation
36
43
 
@@ -42,20 +49,20 @@ gem 'sai'
42
49
 
43
50
  Or install it yourself as:
44
51
 
45
- ```bash
52
+ ```ruby
46
53
  gem install sai
47
54
  ```
48
55
 
49
- ## Usage
50
-
51
- Sai can be used directly or included in your own classes and modules.
56
+ > [!IMPORTANT]
57
+ > If you're upgrading from version 0.2.0, please see our [Migration Guide](docs/migrations/0.2.0-0.3.0.md) for
58
+ > important changes.
52
59
 
53
- ### Direct Usage
60
+ ## Quick Start
54
61
 
55
62
  ```ruby
56
63
  require 'sai'
57
64
 
58
- # Using named colors
65
+ # Basic usage
59
66
  puts Sai.red.decorate('Error!')
60
67
  puts Sai.bright_blue.on_white.decorate('Info')
61
68
 
@@ -63,234 +70,25 @@ puts Sai.bright_blue.on_white.decorate('Info')
63
70
  puts Sai.rgb(255, 128, 0).decorate('Custom color')
64
71
  puts Sai.on_rgb(0, 255, 128).decorate('Custom background')
65
72
 
66
- # Using hex colors
67
- puts Sai.hex('#FF8000').decorate('Hex color')
68
- puts Sai.on_hex('#00FF80').decorate('Hex background')
73
+ # Color manipulation
74
+ puts Sai.blue.lighten_text(0.5).decorate('Lightened blue')
75
+ puts Sai.red.darken_text(0.3).decorate('Darkened red')
69
76
 
70
77
  # Applying styles
71
78
  puts Sai.bold.underline.decorate('Important')
72
79
  puts Sai.red.bold.italic.decorate('Error!')
73
80
 
74
- # Complex combinations
75
- puts Sai.bright_cyan
76
- .on_blue
77
- .bold
78
- .italic
79
- .decorate('Styled text')
80
- ```
81
-
82
- ### Module Inclusion
83
-
84
- ```ruby
85
- class CLI
86
- include Sai
87
-
88
- def error(message)
89
- puts decorator.red.bold.decorate(message)
90
- end
91
-
92
- def info(message)
93
- puts decorator.bright_blue.decorate(message)
94
- end
95
-
96
- def success(message)
97
- puts decorator.with_mode(color_mode.ansi_auto).green.decorate(message)
98
- end
99
- end
100
-
101
- cli = CLI.new
102
- cli.error('Something went wrong!')
103
- cli.info('Processing...')
104
- cli.success('Done!')
105
- ```
106
-
107
- ### Defining Reusable Styles
108
-
109
- Sai decorators can be assigned to constants to create reusable styles throughout your application:
110
-
111
- ```ruby
112
- module Style
113
- ERROR = Sai.bold.bright_white.on_red
114
- WARNING = Sai.black.on_yellow
115
- SUCCESS = Sai.bright_green
116
- INFO = Sai.bright_blue
117
- HEADER = Sai.bold.bright_cyan.underline
118
- end
119
-
120
- # Use your defined styles
121
- puts Style::ERROR.decorate('Something went wrong!')
122
- puts Style::SUCCESS.decorate('Operation completed successfully')
123
-
124
- # Styles can be further customized when needed
125
- puts Style::ERROR.italic.decorate('Critical error!')
126
- ```
127
-
128
- > [!TIP]
129
- > This pattern is particularly useful for maintaining consistent styling across your application and creating theme
130
- > systems. You can even build on existing styles:
131
- >
132
- > ```ruby
133
- > module Theme
134
- > PRIMARY = Sai.rgb(63, 81, 181)
135
- > SECONDARY = Sai.rgb(255, 87, 34)
136
- >
137
- > BUTTON = PRIMARY.bold
138
- > LINK = SECONDARY.underline
139
- > HEADER = PRIMARY.bold.underline
140
- > end
141
- > ```
142
-
143
- ## Features
144
-
145
- ### Color Support
146
-
147
- Sai supports up to 16.7 million colors (true color/24-bit) depending on your terminal's capabilities. Colors can be
148
- specified in several ways:
149
-
150
- #### RGB Colors
151
-
152
- ```ruby
153
- # Specify any RGB color (0-255 per channel)
154
- Sai.rgb(255, 128, 0).decorate('Orange text')
155
- Sai.on_rgb(0, 255, 128).decorate('Custom green background')
156
- ```
157
-
158
- #### Hex Colors
159
-
160
- ```ruby
161
- # Use any hex color code
162
- Sai.hex('#FF8000').decorate('Orange text')
163
- Sai.on_hex('#00FF80').decorate('Custom green background')
164
- ```
165
-
166
- #### Named Color Shortcuts
167
-
168
- For convenience, Sai provides shortcuts for common ANSI colors:
169
-
170
- Standard colors:
171
-
172
- ```ruby
173
- Sai.red.decorate('Red text')
174
- Sai.blue.decorate('Blue text')
175
- Sai.on_green.decorate('Green background')
176
- ```
177
-
178
- Bright variants:
179
-
180
- ```ruby
181
- Sai.bright_red.decorate('Bright red text')
182
- Sai.bright_blue.decorate('Bright blue text')
183
- Sai.on_bright_green.decorate('Bright green background')
184
- ```
185
-
186
- Available named colors:
187
-
188
- * black/bright_black
189
- * red/bright_red
190
- * green/bright_green
191
- * yellow/bright_yellow
192
- * blue/bright_blue
193
- * magenta/bright_magenta
194
- * cyan/bright_cyan
195
- * white/bright_white
196
-
197
- > [!TIP]
198
- > While named colors provide convenient shortcuts, remember that Sai supports the full RGB color space. Don't feel
199
- > limited to just these predefined colors!
200
-
201
- ### Text Styles
202
-
203
- Available styles:
204
-
205
- * bold
206
- * dim
207
- * italic
208
- * underline
209
- * blink
210
- * rapid_blink
211
- * reverse
212
- * conceal
213
- * strike
214
-
215
- Style removal:
216
-
217
- * no_blink
218
- * no_italic
219
- * no_underline
220
- * no_reverse
221
- * no_conceal
222
- * no_strike
223
- * normal_intensity
224
-
225
- ### Color Mode Detection & Downgrading
226
-
227
- Sai automatically detects your terminal's color capabilities and adapts the output appropriately:
228
-
229
- * True Color terminals (24-bit): Full access to all 16.7 million colors
230
- * 256-color terminals (8-bit): Colors are mapped to the closest available color in the 256-color palette
231
- * ANSI terminals (4-bit): Colors are mapped to the 16 standard ANSI colors
232
- * Basic terminals (3-bit): Colors are mapped to the 8 basic ANSI colors
233
- * NO_COLOR: All color sequences are stripped when the NO_COLOR environment variable is set
234
-
235
- > [!NOTE]
236
- > This automatic downgrading ensures your application looks great across all terminal types without any extra code!
237
-
238
- ### Color Mode Selection
239
-
240
- Sai provides flexible color mode selection through its `mode` interface:
241
-
242
- ```ruby
243
- # Use automatic mode detection (default)
244
- Sai.with_mode(Sai.mode.auto)
245
-
246
- # Force specific color modes
247
- puts Sai.with_mode(Sai.mode.true_color).red.decorate('24-bit color')
248
- puts Sai.with_mode(Sai.mode.advanced).red.decorate('256 colors')
249
- puts Sai.with_mode(Sai.mode.ansi).red.decorate('16 colors')
250
- puts Sai.with_mode(Sai.mode.basic).red.decorate('8 colors')
251
- puts Sai.with_mode(Sai.mode.no_color).red.decorate('No color')
252
-
253
- # Use automatic downgrading
254
- puts Sai.with_mode(Sai.mode.advanced_auto).red.decorate('256 colors or less')
255
- puts Sai.with_mode(Sai.mode.ansi_auto).red.decorate('16 colors or less')
256
- puts Sai.with_mode(Sai.mode.basic_auto).red.decorate('8 colors or less')
81
+ # Working with ANSI sequences
82
+ text = Sai.sequence("\e[31mError:\e[0m Details here")
83
+ puts text.without_color # Remove colors but keep formatting
84
+ puts text.without_style # Remove formatting but keep colors
85
+ puts text.stripped # Get plain text
257
86
  ```
258
87
 
259
- > [!WARNING]
260
- > When using fixed color modes (like `true_color` or `advanced`), Sai will not automatically downgrade colors for
261
- > terminals with lower color support. For automatic color mode adjustment, use modes ending in `_auto`
262
- > (like `advanced_auto` or `ansi_auto`).
88
+ ## Documentation
263
89
 
264
- This allows you to:
265
-
266
- * Explicitly set specific color modes
267
- * Use automatic mode detection (default)
268
- * Set maximum color modes with automatic downgrading
269
- * Disable colors entirely
270
-
271
- ### Terminal Support Detection
272
-
273
- You can check the terminal's capabilities:
274
-
275
- ```ruby
276
- # Using directly
277
- Sai.support.true_color? # => true/false
278
- Sai.support.advanced? # => true/false
279
- Sai.support.ansi? # => true/false
280
- Sai.support.basic? # => true/false
281
- Sai.support.color? # => true/false
282
-
283
- # Using included module
284
- class CLI
285
- include Sai
286
-
287
- def check_support
288
- if terminal_color_support.true_color?
289
- puts "Terminal supports true color!"
290
- end
291
- end
292
- end
293
- ```
90
+ * [Complete Usage Guide](docs/USAGE.md) - Comprehensive documentation of all features
91
+ * [API Documentation](https://rubydoc.info/gems/sai/0.3.1) - Detailed API reference
294
92
 
295
93
  ## Contributing
296
94