sai-mei 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Sai
6
+ module Mei
7
+ # The base module for color palettes
8
+ #
9
+ # @author {https://aaronmallen.me Aaron Allen}
10
+ # @since unreleased
11
+ #
12
+ # @abstract Include in subclass and define a constant named COLORS
13
+ # @api private
14
+ class Palette
15
+ # The candidates to be installed
16
+ #
17
+ # @author {https://aaronmallen.me Aaron Allen}
18
+ # @since unreleased
19
+ #
20
+ # @api public
21
+ #
22
+ # @return [Hash{Symbol => Array<Integer>}]
23
+ attr_reader :candidates #: Hash[Symbol, Array[Integer]]
24
+
25
+ # Load the Palette from configuration
26
+ #
27
+ # @author {https://aaronmallen.me Aaron Allen}
28
+ # @since unreleased
29
+ #
30
+ # @api private
31
+ #
32
+ # @param config_name [String, Symbol] the name of the configuration to load
33
+ #
34
+ # @return [Palette] the loaded Palette
35
+ # @rbs (String | Symbol config_name) -> Palette
36
+ def self.load(config_name)
37
+ lookup = YAML.load_file(
38
+ File.expand_path("../../../config/#{config_name.to_s.downcase}.yml", File.dirname(__FILE__)),
39
+ symbolize_names: true
40
+ )
41
+
42
+ if Sai::Mei.const_defined?(config_name)
43
+ Sai::Mei.const_get(config_name).new(lookup)
44
+ else
45
+ Sai::Mei.const_set(config_name, Class.new(Palette)).new(lookup)
46
+ end
47
+ end
48
+
49
+ # Initialize a new instance of the Palette
50
+ #
51
+ # @author {https://aaronmallen.me Aaron Allen}
52
+ # @since unreleased
53
+ #
54
+ # @api private
55
+ #
56
+ # @param lookup [Hash{Symbol => Array<Integer>}] the candidates to be installed
57
+ #
58
+ # @return [Palette] a new instance of the Palette
59
+ # @rbs (Hash[Symbol, Array[Integer]] lookup) -> Palette
60
+ def initialize(lookup)
61
+ @candidates = lookup.dup
62
+ @lookup = lookup.freeze
63
+ end
64
+
65
+ # Get all the names of the color names available in the Palette
66
+ #
67
+ # @author {https://aaronmallen.me Aaron Allen}
68
+ # @since unreleased
69
+ #
70
+ # @api public
71
+ #
72
+ # @example
73
+ # Sai::Mei.xterm.all_names #=> [:black, :maroon, :green, ...]
74
+ #
75
+ # @return [Array<Symbol>] the names of the colors in the palette
76
+ def color_names
77
+ @lookup.keys
78
+ end
79
+
80
+ # Exclude colors from the palette
81
+ #
82
+ # @author {https://aaronmallen.me Aaron Allen}
83
+ # @since unreleased
84
+ #
85
+ # @api public
86
+ #
87
+ # @example
88
+ # Sai::Mei.xterm.except(:green, :dodger_blue_2, :spring_green_4).install
89
+ #
90
+ # @param color_names [Array<String, Symbol>] the names of the colors to exclude
91
+ #
92
+ # @return [Palette] the palette with the specified colors excluded
93
+ # @rbs (*String | Symbol color_names) -> Palette
94
+ def excluding(*color_names)
95
+ @candidates = candidates.except(*color_names.map(&:to_sym))
96
+ self
97
+ end
98
+
99
+ # Install the candidates into Sai
100
+ #
101
+ # @author {https://aaronmallen.me Aaron Allen}
102
+ # @since unreleased
103
+ #
104
+ # @api public
105
+ #
106
+ # @example
107
+ # Sai::Mei.xterm.install
108
+ #
109
+ # @return [void]
110
+ # @rbs () -> void
111
+ def install
112
+ candidates.each_pair { |name, color| Sai.register(name, color) }
113
+ end
114
+
115
+ # Limit the color palette to specific named colors
116
+ #
117
+ # @author {https://aaronmallen.me Aaron Allen}
118
+ # @since unreleased
119
+ #
120
+ # @api public
121
+ #
122
+ # @example
123
+ # Sai::Mei.xterm.only(:green, :dodger_blue_2, :spring_green_4).install
124
+ #
125
+ # @param color_names [Array<String, Symbol>] the names of the colors to restrict the palette to
126
+ #
127
+ # @return [self] the palette with the specified colors
128
+ # @rbs (*String | Symbol color_names) -> self
129
+ def only(*color_names)
130
+ @candidates = candidates.slice(*color_names.map(&:to_sym))
131
+ self
132
+ end
133
+
134
+ # Change the name specific colors in the palette
135
+ #
136
+ # @author {https://aaronmallen.me Aaron Allen}
137
+ # @since unreleased
138
+ #
139
+ # @api public
140
+ #
141
+ # @example
142
+ # Sai::Mei.xterm.rename(green: :xterm_green, dodger_blue_3: :xterm_dodger_blue).install
143
+ #
144
+ # @param color_map [Hash{String, Symbol => String, Symbol}] the mapping of color names to new names
145
+ #
146
+ # @return [self] the palette with the specified colors renamed
147
+ # @rbs (**String | Symbol color_map) -> self
148
+ def rename(**color_map)
149
+ color_map = color_map.transform_keys(&:to_sym).transform_values(&:to_sym) #: Hash[Symbol, Symbol]
150
+
151
+ color_map.each_pair do |old_name, new_name|
152
+ next unless candidates.key?(old_name)
153
+
154
+ candidates[new_name] = candidates.delete(old_name) # steep:ignore ArgumentTypeMismatch
155
+ end
156
+ self
157
+ end
158
+
159
+ # Reset the candidates to the original state
160
+ #
161
+ # @author {https://aaronmallen.me Aaron Allen}
162
+ # @since unreleased
163
+ #
164
+ # @api public
165
+ #
166
+ # @example
167
+ # palette = Sai::Mei.xterm.except(:green)
168
+ # palette.candidates.keys.include?(:green) #=> false
169
+ # palette.reset.candidates.keys.include?(:green) #=> true
170
+ #
171
+ # @return [Palette] the Palette with the candidates reset
172
+ # @rbs () -> Palette
173
+ def reset!
174
+ self.class.new(@lookup.dup)
175
+ end
176
+ end
177
+ end
178
+ end
data/lib/sai/mei.rb ADDED
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sai'
4
+ require 'sai/mei/palette'
5
+
6
+ module Sai
7
+ # An elegant color naming system extending Sai with sophisticated color palettes
8
+ #
9
+ # Sai-Mei (彩名) - combining Sai's color management with the on'yomi reading for 'name' - provides a comprehensive
10
+ # collection of named colors extending the Sai color management system. Drawing inspiration from traditional color
11
+ # vocabularies, Sai-Mei brings rich, curated color palettes to terminal interfaces
12
+ #
13
+ # Sai-Mei empowers developers to selectively incorporate sophisticated color collections into
14
+ # their CLI applications. Like its parent gem Sai, it combines precision with flexibility,
15
+ # allowing developers to organize and utilize color palettes with fine-grained control
16
+ #
17
+ # @author {https://aaronmallen.me Aaron Allen}
18
+ # @since 0.1.0
19
+ #
20
+ # @api public
21
+ module Mei
22
+ # The CSS color palette
23
+ #
24
+ # @author {https://aaronmallen.me Aaron Allen}
25
+ # @since unreleased
26
+ #
27
+ # @api public
28
+ #
29
+ # @example Installing the CSS color palette
30
+ # Sai::Mei.css.install
31
+ #
32
+ # @return [Palette] the CSS color palette instance
33
+ # @rbs () -> Palette
34
+ def self.css
35
+ Palette.load(:CSS)
36
+ end
37
+
38
+ # The Tailwind color palette
39
+ #
40
+ # @author {https://aaronmallen.me Aaron Allen}
41
+ # @since unreleased
42
+ #
43
+ # @api public
44
+ #
45
+ # @example Installing the Tailwind color palette
46
+ # Sai::Mei.tailwind.install
47
+ #
48
+ # @return [Palette] the Tailwind color palette instance
49
+ # @rbs () -> Palette
50
+ def self.tailwind
51
+ Palette.load(:Tailwind)
52
+ end
53
+
54
+ # The XTERM color palette
55
+ #
56
+ # @author {https://aaronmallen.me Aaron Allen}
57
+ # @since unreleased
58
+ #
59
+ # @api public
60
+ #
61
+ # @example Installing the XTERM color palette
62
+ # Sai::Mei.xterm.install
63
+ #
64
+ # @return [Palette] the XTERM color palette instance
65
+ # @rbs () -> Palette
66
+ def self.xterm
67
+ Palette.load(:XTERM)
68
+ end
69
+ end
70
+ end
data/lib/sai-mei.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sai/mei'
data/sig/manifest.yaml ADDED
@@ -0,0 +1,2 @@
1
+ dependencies:
2
+ - name: yaml
@@ -0,0 +1,141 @@
1
+ # Generated from lib/sai/mei/palette.rb with RBS::Inline
2
+
3
+ module Sai
4
+ module Mei
5
+ # The base module for color palettes
6
+ #
7
+ # @author {https://aaronmallen.me Aaron Allen}
8
+ # @since unreleased
9
+ #
10
+ # @abstract Include in subclass and define a constant named COLORS
11
+ # @api private
12
+ class Palette
13
+ # The candidates to be installed
14
+ #
15
+ # @author {https://aaronmallen.me Aaron Allen}
16
+ # @since unreleased
17
+ #
18
+ # @api public
19
+ #
20
+ # @return [Hash{Symbol => Array<Integer>}]
21
+ attr_reader candidates: Hash[Symbol, Array[Integer]]
22
+
23
+ # Load the Palette from configuration
24
+ #
25
+ # @author {https://aaronmallen.me Aaron Allen}
26
+ # @since unreleased
27
+ #
28
+ # @api private
29
+ #
30
+ # @param config_name [String, Symbol] the name of the configuration to load
31
+ #
32
+ # @return [Palette] the loaded Palette
33
+ # @rbs (String | Symbol config_name) -> Palette
34
+ def self.load: (String | Symbol config_name) -> Palette
35
+
36
+ # Initialize a new instance of the Palette
37
+ #
38
+ # @author {https://aaronmallen.me Aaron Allen}
39
+ # @since unreleased
40
+ #
41
+ # @api private
42
+ #
43
+ # @param lookup [Hash{Symbol => Array<Integer>}] the candidates to be installed
44
+ #
45
+ # @return [Palette] a new instance of the Palette
46
+ # @rbs (Hash[Symbol, Array[Integer]] lookup) -> Palette
47
+ def initialize: (Hash[Symbol, Array[Integer]] lookup) -> void
48
+
49
+ # Get all the names of the color names available in the Palette
50
+ #
51
+ # @author {https://aaronmallen.me Aaron Allen}
52
+ # @since unreleased
53
+ #
54
+ # @api public
55
+ #
56
+ # @example
57
+ # Sai::Mei.xterm.all_names #=> [:black, :maroon, :green, ...]
58
+ #
59
+ # @return [Array<Symbol>] the names of the colors in the palette
60
+ def color_names: () -> untyped
61
+
62
+ # Exclude colors from the palette
63
+ #
64
+ # @author {https://aaronmallen.me Aaron Allen}
65
+ # @since unreleased
66
+ #
67
+ # @api public
68
+ #
69
+ # @example
70
+ # Sai::Mei.xterm.except(:green, :dodger_blue_2, :spring_green_4).install
71
+ #
72
+ # @param color_names [Array<String, Symbol>] the names of the colors to exclude
73
+ #
74
+ # @return [Palette] the palette with the specified colors excluded
75
+ # @rbs (*String | Symbol color_names) -> Palette
76
+ def excluding: (*String | Symbol color_names) -> Palette
77
+
78
+ # Install the candidates into Sai
79
+ #
80
+ # @author {https://aaronmallen.me Aaron Allen}
81
+ # @since unreleased
82
+ #
83
+ # @api public
84
+ #
85
+ # @example
86
+ # Sai::Mei.xterm.install
87
+ #
88
+ # @return [void]
89
+ # @rbs () -> void
90
+ def install: () -> void
91
+
92
+ # Limit the color palette to specific named colors
93
+ #
94
+ # @author {https://aaronmallen.me Aaron Allen}
95
+ # @since unreleased
96
+ #
97
+ # @api public
98
+ #
99
+ # @example
100
+ # Sai::Mei.xterm.only(:green, :dodger_blue_2, :spring_green_4).install
101
+ #
102
+ # @param color_names [Array<String, Symbol>] the names of the colors to restrict the palette to
103
+ #
104
+ # @return [self] the palette with the specified colors
105
+ # @rbs (*String | Symbol color_names) -> self
106
+ def only: (*String | Symbol color_names) -> self
107
+
108
+ # Change the name specific colors in the palette
109
+ #
110
+ # @author {https://aaronmallen.me Aaron Allen}
111
+ # @since unreleased
112
+ #
113
+ # @api public
114
+ #
115
+ # @example
116
+ # Sai::Mei.xterm.rename(green: :xterm_green, dodger_blue_3: :xterm_dodger_blue).install
117
+ #
118
+ # @param color_map [Hash{String, Symbol => String, Symbol}] the mapping of color names to new names
119
+ #
120
+ # @return [self] the palette with the specified colors renamed
121
+ # @rbs (**String | Symbol color_map) -> self
122
+ def rename: (**String | Symbol color_map) -> self
123
+
124
+ # Reset the candidates to the original state
125
+ #
126
+ # @author {https://aaronmallen.me Aaron Allen}
127
+ # @since unreleased
128
+ #
129
+ # @api public
130
+ #
131
+ # @example
132
+ # palette = Sai::Mei.xterm.except(:green)
133
+ # palette.candidates.keys.include?(:green) #=> false
134
+ # palette.reset.candidates.keys.include?(:green) #=> true
135
+ #
136
+ # @return [Palette] the Palette with the candidates reset
137
+ # @rbs () -> Palette
138
+ def reset!: () -> Palette
139
+ end
140
+ end
141
+ end
data/sig/sai/mei.rbs ADDED
@@ -0,0 +1,61 @@
1
+ # Generated from lib/sai/mei.rb with RBS::Inline
2
+
3
+ module Sai
4
+ # An elegant color naming system extending Sai with sophisticated color palettes
5
+ #
6
+ # Sai-Mei (彩名) - combining Sai's color management with the on'yomi reading for 'name' - provides a comprehensive
7
+ # collection of named colors extending the Sai color management system. Drawing inspiration from traditional color
8
+ # vocabularies, Sai-Mei brings rich, curated color palettes to terminal interfaces
9
+ #
10
+ # Sai-Mei empowers developers to selectively incorporate sophisticated color collections into
11
+ # their CLI applications. Like its parent gem Sai, it combines precision with flexibility,
12
+ # allowing developers to organize and utilize color palettes with fine-grained control
13
+ #
14
+ # @author {https://aaronmallen.me Aaron Allen}
15
+ # @since 0.1.0
16
+ #
17
+ # @api public
18
+ module Mei
19
+ # The CSS color palette
20
+ #
21
+ # @author {https://aaronmallen.me Aaron Allen}
22
+ # @since unreleased
23
+ #
24
+ # @api public
25
+ #
26
+ # @example Installing the CSS color palette
27
+ # Sai::Mei.css.install
28
+ #
29
+ # @return [Palette] the CSS color palette instance
30
+ # @rbs () -> Palette
31
+ def self.css: () -> Palette
32
+
33
+ # The Tailwind color palette
34
+ #
35
+ # @author {https://aaronmallen.me Aaron Allen}
36
+ # @since unreleased
37
+ #
38
+ # @api public
39
+ #
40
+ # @example Installing the Tailwind color palette
41
+ # Sai::Mei.tailwind.install
42
+ #
43
+ # @return [Palette] the Tailwind color palette instance
44
+ # @rbs () -> Palette
45
+ def self.tailwind: () -> Palette
46
+
47
+ # The XTERM color palette
48
+ #
49
+ # @author {https://aaronmallen.me Aaron Allen}
50
+ # @since unreleased
51
+ #
52
+ # @api public
53
+ #
54
+ # @example Installing the XTERM color palette
55
+ # Sai::Mei.xterm.install
56
+ #
57
+ # @return [Palette] the XTERM color palette instance
58
+ # @rbs () -> Palette
59
+ def self.xterm: () -> Palette
60
+ end
61
+ end
data/sig/sai-mei.rbs ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated from lib/sai-mei.rb with RBS::Inline
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sai-mei
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Allen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sai
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ description: |-
28
+ Sai-Mei (彩名) - combining Sai's color management with the on'yomi reading for 'name' - provides a comprehensive collection of named colors extending the Sai color management system. Drawing inspiration from traditional color vocabularies, Sai-Mei brings rich, curated color palettes to terminal interfaces.
29
+ Sai-Mei empowers developers to selectively incorporate sophisticated color collections into their CLI applications. Like its parent gem Sai, it combines precision with flexibility, allowing developers to organize and utilize color palettes with fine-grained control.
30
+ email:
31
+ - hello@aaronmallen.me
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".yardopts"
37
+ - CHANGELOG.md
38
+ - LICENSE
39
+ - README.md
40
+ - config/css.yml
41
+ - config/tailwind.yml
42
+ - config/xterm.yml
43
+ - lib/sai-mei.rb
44
+ - lib/sai/mei.rb
45
+ - lib/sai/mei/palette.rb
46
+ - sig/manifest.yaml
47
+ - sig/sai-mei.rbs
48
+ - sig/sai/mei.rbs
49
+ - sig/sai/mei/palette.rbs
50
+ homepage: https://github.com/aaronmallen/sai-mei
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ bug_tracker_uri: https://github.com/aaronmallen/sai-mei/issues
55
+ changelog_uri: https://github.com/aaronmallen/sai-mei/releases/tag/0.1.0
56
+ homepage_uri: https://github.com/aaronmallen/sai-mei
57
+ rubygems_mfa_required: 'true'
58
+ source_code_uri: https://github.com/aaronmallen/sai-mei/tree/0.1.0
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '3.1'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.3.27
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: An elegant color naming system extending Sai with sophisticated color palettes
78
+ test_files: []