sai 0.3.2 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +25 -4
- data/docs/USAGE.md +9 -16
- data/lib/sai/ansi.rb +40 -0
- data/lib/sai/conversion/rgb/color_space.rb +2 -2
- data/lib/sai/decorator/delegator.rb +79 -0
- data/lib/sai/decorator/named_colors.rb +38 -744
- data/lib/sai/decorator.rb +2 -3
- data/lib/sai/registry.rb +134 -0
- data/lib/sai.rb +28 -765
- data/sig/sai/ansi.rbs +21 -0
- data/sig/sai/decorator/delegator.rbs +95 -0
- data/sig/sai/decorator/named_colors.rbs +30 -1460
- data/sig/sai/decorator.rbs +2 -3
- data/sig/sai/{named_colors.rbs → registry.rbs} +31 -52
- data/sig/sai.rbs +14 -1519
- metadata +8 -8
- data/lib/sai/decorator/delegation.rb +0 -85
- data/lib/sai/named_colors.rb +0 -522
- data/sig/sai/decorator/delegation.rbs +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70b2bd4d6b105fd634f0685c9e7952f061881b6c150abb1193c268bc11daee06
|
4
|
+
data.tar.gz: 7c39b485b0a6217326c7b282d88518114348c8dd1bef3ddfaea7d697f314ccb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 105164ddad126c7996f5f1ebe4e32baf0f881b7672731b922f71025712a6d2ea95a276fe27e4660ad8e3b26e5cbcdbf6f5d4179138846f5b07093cb68e0b929b
|
7
|
+
data.tar.gz: 11763b7688478e3068bf389b15eecea0b63ea768a7d5031c98e3df1b76c96fbb5d9b317a7fcf0f10f0473cc20f1e9a24104a96c03f4f1aa07273359c1fde865d
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ 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
|
+
|
9
16
|
## [0.3.2] - 2025-01-22
|
10
17
|
|
11
18
|
### Added
|
@@ -71,7 +78,8 @@ The format is based on [Keep a Changelog], and this project adheres to [Break Ve
|
|
71
78
|
|
72
79
|
<!-- versions -->
|
73
80
|
|
74
|
-
[Unreleased]: https://github.com/aaronmallen/sai/compare/0.
|
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
|
75
83
|
[0.3.2]: https://github.com/aaronmallen/sai/compare/0.3.1..0.3.2
|
76
84
|
[0.3.1]: https://github.com/aaronmallen/sai/compare/0.3.0..0.3.1
|
77
85
|
[0.3.0]: https://github.com/aaronmallen/sai/compare/0.2.0..0.3.0
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://app.codacy.com/gh/aaronmallen/sai)
|
5
5
|
[](https://app.codacy.com/gh/aaronmallen/sai/coverage)
|
6
6
|
[](./LICENSE)
|
7
|
-
[](https://rubydoc.info/gems/sai/0.
|
7
|
+
[](https://rubydoc.info/gems/sai/0.4.0)
|
8
8
|
[](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
|
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.
|
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.
|
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,29 +84,22 @@ 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
87
|
|
89
|
-
|
88
|
+
Available named colors:
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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:
|
106
|
-
|
107
|
-
* [Online Color Reference](https://github.com/aaronmallen/sai/blob/main/docs/AVAILABLE_NAMED_COLORS.md)
|
108
|
-
* `Sai::NamedColors.names` in your code
|
109
|
-
|
110
103
|
#### Registering Custom Named Colors
|
111
104
|
|
112
105
|
Sai allows you to register custom named colors for easy reuse with `Sai.register`:
|
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/
|
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 =
|
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
|