sai 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c45105e60b5f7a3a93d837080975996e96a340aef0ad3fd86cd4b5a1be17e8f
4
- data.tar.gz: baf93c18ef40221c86c329deeeaabbe7a3619744d3a80a9349314624a4af3995
3
+ metadata.gz: 70b2bd4d6b105fd634f0685c9e7952f061881b6c150abb1193c268bc11daee06
4
+ data.tar.gz: 7c39b485b0a6217326c7b282d88518114348c8dd1bef3ddfaea7d697f314ccb7
5
5
  SHA512:
6
- metadata.gz: c1540fe3fd55f0a338ff04ff6f9794e831b831c040637f4cdd4f0de0ab0a689a55f95d5c1a744f3ae25b0bc7452983044568e83b6e665439672142cd2abd811b
7
- data.tar.gz: 4244b0401b7fd0af26665a0a5b5622dd09bd364e4166bc8d12a6c69f94a52b09511d56afe2cd8eaedf1401c402b3ba63845aa900c147e408312221dcc243e21d
6
+ metadata.gz: 105164ddad126c7996f5f1ebe4e32baf0f881b7672731b922f71025712a6d2ea95a276fe27e4660ad8e3b26e5cbcdbf6f5d4179138846f5b07093cb68e0b929b
7
+ data.tar.gz: 11763b7688478e3068bf389b15eecea0b63ea768a7d5031c98e3df1b76c96fbb5d9b317a7fcf0f10f0473cc20f1e9a24104a96c03f4f1aa07273359c1fde865d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog], and this project adheres to [Break Ve
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.4.0] - 2025-01-23
10
+
11
+ ### Changed
12
+
13
+ * [#17](https://github.com/aaronmallen/sai/pull/17) - Refactor color registration and delegation system by
14
+ [@aaronmallen](https://github.com/aaronmallen)
15
+
16
+ ## [0.3.2] - 2025-01-22
17
+
18
+ ### Added
19
+
20
+ * [#15](https://github.com/aaronmallen/sai/pull/15) - Add support for registering custom named colors by
21
+ [@aaronmallen](https://github.com/aaronmallen)
22
+
9
23
  ## [0.3.1] - 2025-01-22
10
24
 
11
25
  ### Added
@@ -64,7 +78,9 @@ The format is based on [Keep a Changelog], and this project adheres to [Break Ve
64
78
 
65
79
  <!-- versions -->
66
80
 
67
- [Unreleased]: https://github.com/aaronmallen/sai/compare/0.3.1..HEAD
81
+ [Unreleased]: https://github.com/aaronmallen/sai/compare/0.4.0..HEAD
82
+ [0.4.0]: https://github.com/aaronmallen/sai/compare/0.3.2..0.4.0
83
+ [0.3.2]: https://github.com/aaronmallen/sai/compare/0.3.1..0.3.2
68
84
  [0.3.1]: https://github.com/aaronmallen/sai/compare/0.3.0..0.3.1
69
85
  [0.3.0]: https://github.com/aaronmallen/sai/compare/0.2.0..0.3.0
70
86
  [0.2.0]: https://github.com/aaronmallen/sai/compare/0.1.0..0.2.0
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
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
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)
6
6
  [![Sai License](https://img.shields.io/github/license/aaronmallen/sai?style=for-the-badge&logo=opensourceinitiative&logoColor=white&logoSize=auto)](./LICENSE)
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)
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.4.0)
8
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)
9
9
 
10
10
  An elegant color management system for crafting sophisticated CLI applications
@@ -33,12 +33,33 @@ harmony to terminal interfaces through its sophisticated color management.
33
33
 
34
34
  * Rich color support (True Color, 256 colors, ANSI, and basic modes)
35
35
  * Automatic terminal capability detection and color mode adaptation
36
- * RGB, Hex, and named color (**over 360 named colors**) support with bright variants
36
+ * RGB, Hex, and named color support with bright variants
37
37
  * Comprehensive text styling (bold, italic, underline, etc.)
38
38
  * Advanced ANSI sequence parsing and manipulation
39
39
  * Intelligent color downgrading for compatibility
40
40
  * Respects NO_COLOR environment variable
41
41
 
42
+ ## Extended Color Palettes
43
+
44
+ Looking for additional color palettes? Check out [Sai-Mei](https://github.com/aaronmallen/sai-mei), which extends Sai
45
+ with many curated color collections, including:
46
+
47
+ * Web colors from CSS Color Module Level 4
48
+ * Tailwind CSS color system
49
+ * Extended 256-color xterm palette
50
+
51
+ ```ruby
52
+ # Install Sai-Mei alongside Sai
53
+ gem 'sai'
54
+ gem 'sai-mei'
55
+
56
+ # Then use sophisticated color palettes
57
+ require 'sai/mei'
58
+ Sai::Mei.css.install # CSS colors
59
+ Sai::Mei.tailwind.install # Tailwind colors
60
+ Sai::Mei.xterm.install # Terminal 256 colors
61
+ ```
62
+
42
63
  ## Installation
43
64
 
44
65
  Add this line to your application's Gemfile:
@@ -54,7 +75,7 @@ gem install sai
54
75
  ```
55
76
 
56
77
  > [!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
78
+ > If you're upgrading from version 0.3.1, please see our [Migration Guide](docs/migrations/0.3.1-0.4.0.md) for
58
79
  > important changes.
59
80
 
60
81
  ## Quick Start
@@ -88,7 +109,7 @@ puts text.stripped # Get plain text
88
109
  ## Documentation
89
110
 
90
111
  * [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
112
+ * [API Documentation](https://rubydoc.info/gems/sai/0.4.0) - Detailed API reference
92
113
 
93
114
  ## Contributing
94
115
 
data/docs/USAGE.md CHANGED
@@ -84,28 +84,35 @@ Sai.bright_red.decorate('Bright red text')
84
84
  Sai.bright_blue.decorate('Bright blue text')
85
85
  Sai.on_bright_green.decorate('Bright green background')
86
86
  ```
87
- ### Named Colors
88
-
89
- Common ANSI, XTERM, and CSS colors have convenient shortcuts. You can:
90
87
 
91
- ```ruby
92
- # View all available colors programmatically
93
- Sai::NamedColors.names # Returns array of all color names
88
+ Available named colors:
94
89
 
95
- # Use colors in your code
96
- Sai.red.decorate('Red text')
97
- Sai.blue.decorate('Blue text')
98
- Sai.on_green.decorate('Green background')
99
- ```
90
+ * black/bright_black
91
+ * red/bright_red
92
+ * green/bright_green
93
+ * yellow/bright_yellow
94
+ * blue/bright_blue
95
+ * magenta/bright_magenta
96
+ * cyan/bright_cyan
97
+ * white/bright_white
100
98
 
101
99
  > [!TIP]
102
100
  > While named colors provide convenient shortcuts, remember that Sai supports the full RGB color space. Don't feel
103
101
  > limited to just these predefined colors!
104
102
 
105
- For a complete list of available colors, see:
103
+ #### Registering Custom Named Colors
104
+
105
+ Sai allows you to register custom named colors for easy reuse with `Sai.register`:
106
+
107
+ ```ruby
108
+ # Register custom colors
109
+ Sai.register(:my_color, '#CF4C5F')
110
+
111
+ # or alternatively
112
+ Sai.register(:my_color, [207, 76, 95])
106
113
 
107
- * [Online Color Reference](https://github.com/aaronmallen/sai/blob/main/docs/AVAILABLE_NAMED_COLORS.md)
108
- * `Sai::NamedColors.names` in your code
114
+ Sai.my_color.decorate('Hello, world!')
115
+ ```
109
116
 
110
117
  ### Color Manipulation
111
118
 
data/lib/sai/ansi.rb CHANGED
@@ -8,6 +8,33 @@ module Sai
8
8
  #
9
9
  # @api private
10
10
  module ANSI
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
+ COLORS = {
20
+ black: [0, 0, 0],
21
+ red: [205, 0, 0],
22
+ green: [0, 205, 0],
23
+ yellow: [205, 205, 0],
24
+ blue: [0, 0, 238],
25
+ magenta: [205, 0, 205],
26
+ cyan: [0, 205, 205],
27
+ white: [229, 229, 229],
28
+ bright_black: [127, 127, 127],
29
+ bright_red: [255, 0, 0],
30
+ bright_green: [0, 255, 0],
31
+ bright_yellow: [255, 255, 0],
32
+ bright_blue: [92, 92, 255],
33
+ bright_magenta: [255, 0, 255],
34
+ bright_cyan: [0, 255, 255],
35
+ bright_white: [255, 255, 255]
36
+ }.freeze # Hash[Symbol, Array[Integer]]
37
+
11
38
  # ANSI color code mappings
12
39
  #
13
40
  # @author {https://aaronmallen.me Aaron Allen}
@@ -63,5 +90,18 @@ module Sai
63
90
  no_conceal: 28,
64
91
  no_strike: 29
65
92
  }.freeze # Hash[Symbol, Integer]
93
+
94
+ # Install the ANSI colors
95
+ #
96
+ # @author {https://aaronmallen.me Aaron Allen}
97
+ # @since 0.4.0
98
+ #
99
+ # @api private
100
+ #
101
+ # @return [void]
102
+ # @rbs () -> void
103
+ def self.install
104
+ COLORS.each_pair { |name, color| Sai.register(name, color) }
105
+ end
66
106
  end
67
107
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sai/named_colors'
3
+ require 'sai/registry'
4
4
 
5
5
  module Sai
6
6
  module Conversion
@@ -120,7 +120,7 @@ module Sai
120
120
  # @return [Array<Integer>] the RGB components
121
121
  # @rbs (String color_name) -> Array[Integer]
122
122
  def named_to_rgb(color_name)
123
- color = NamedColors[color_name.to_sym]
123
+ color = Registry[color_name.to_sym]
124
124
  raise ArgumentError, "Unknown color name: #{color_name}" unless color
125
125
 
126
126
  color
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sai/decorator/color_manipulations'
4
+ require 'sai/decorator/gradients'
5
+ require 'sai/decorator/hex_colors'
6
+ require 'sai/decorator/named_styles'
7
+ require 'sai/decorator/rgb_colors'
8
+
9
+ module Sai
10
+ class Decorator
11
+ # Provides method delegation to the {Decorator} class for classes or modules that include it
12
+ #
13
+ # @author {https://aaronmallen.me Aaron Allen}
14
+ # @since 0.4.0
15
+ #
16
+ # @abstract Include in a class or module to provide method delegation to the {Decorator} class
17
+ # @api private
18
+ module Delegator
19
+ # @rbs!
20
+ # def blink: () -> Decorator
21
+ # def bold: () -> Decorator
22
+ # def conceal: () -> Decorator
23
+ # def darken_background: () -> Decorator
24
+ # def darken_bg: () -> Decorator
25
+ # def darken_fg: () -> Decorator
26
+ # def darken_foreground: () -> Decorator
27
+ # def darken_text: () -> Decorator
28
+ # def dim: () -> Decorator
29
+ # def gradient: () -> Decorator
30
+ # def hex: () -> Decorator
31
+ # def italic: () -> Decorator
32
+ # def lighten_background: () -> Decorator
33
+ # def lighten_bg: () -> Decorator
34
+ # def lighten_fg: () -> Decorator
35
+ # def lighten_foreground: () -> Decorator
36
+ # def lighten_text: () -> Decorator
37
+ # def no_blink: () -> Decorator
38
+ # def no_conceal: () -> Decorator
39
+ # def no_italic: () -> Decorator
40
+ # def no_reverse: () -> Decorator
41
+ # def no_strike: () -> Decorator
42
+ # def no_underline: () -> Decorator
43
+ # def normal_intensity: () -> Decorator
44
+ # def on_gradient: () -> Decorator
45
+ # def on_hex: () -> Decorator
46
+ # def on_rainbow: () -> Decorator
47
+ # def on_rgb: () -> Decorator
48
+ # def rainbow: () -> Decorator
49
+ # def rapid_blink: () -> Decorator
50
+ # def reverse: () -> Decorator
51
+ # def rgb: () -> Decorator
52
+ # def strike: () -> Decorator
53
+ # def underline: () -> Decorator
54
+
55
+ [ColorManipulations, Gradients, HexColors, NamedStyles, RGBColors].each do |mod|
56
+ mod.instance_methods.each do |method|
57
+ define_method(method) do |*arguments, **keyword_arguments|
58
+ Decorator.new.public_send(method, *arguments, **keyword_arguments)
59
+ end
60
+ end
61
+ end
62
+
63
+ # Apply a specific color mode to the {Decorator} instance
64
+ #
65
+ # @author {https://aaronmallen.me Aaron Allen}
66
+ # @since 0.4.0
67
+ #
68
+ # @api private
69
+ #
70
+ # @param mode [Integer] the color mode to use
71
+ #
72
+ # @return [Decorator] a new instance of Decorator with the applied color mode
73
+ # @rbs (Integer mode) -> Decorator
74
+ def with_mode(mode)
75
+ Decorator.new(mode:)
76
+ end
77
+ end
78
+ end
79
+ end