sai 0.3.1 → 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 +17 -1
- data/README.md +25 -4
- data/docs/USAGE.md +21 -14
- 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 +44 -738
- data/lib/sai/decorator.rb +2 -3
- data/lib/sai/registry.rb +134 -0
- data/lib/sai.rb +49 -764
- data/sig/sai/ansi.rbs +21 -0
- data/sig/sai/decorator/delegator.rbs +95 -0
- data/sig/sai/decorator/named_colors.rbs +36 -1453
- data/sig/sai/decorator.rbs +2 -3
- data/sig/sai/registry.rbs +106 -0
- data/sig/sai.rbs +34 -1519
- metadata +12 -9
- data/lib/sai/decorator/delegation.rb +0 -84
- data/lib/sai/named_colors.rb +0 -437
- data/sig/sai/decorator/delegation.rbs +0 -47
- data/sig/sai/named_colors.rbs +0 -65
data/sig/sai/decorator.rbs
CHANGED
@@ -11,11 +11,10 @@ module Sai
|
|
11
11
|
# @note For each named color, two methods are dynamically generated:
|
12
12
|
# * color_name - Applies the color to the foreground
|
13
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
14
|
#
|
16
15
|
# @example Using a named color
|
17
|
-
# decorator.
|
18
|
-
# decorator.
|
16
|
+
# decorator.blue.decorate('Hello').to_s #=> "\e[38;2;0;0;238mHello\e[0m"
|
17
|
+
# decorator.on_blue.decorate('Hello').to_s #=> "\e[48;2;0;0;238mHello\e[0m"
|
19
18
|
class Decorator
|
20
19
|
include ColorManipulations
|
21
20
|
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# Generated from lib/sai/registry.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
# The named color registry
|
5
|
+
#
|
6
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
7
|
+
# @since 0.4.0
|
8
|
+
#
|
9
|
+
# @api private
|
10
|
+
module Registry
|
11
|
+
# Look up an RGB value by color name
|
12
|
+
#
|
13
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
14
|
+
# @since 0.3.1
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
# @param name [String, Symbol] the color name
|
19
|
+
#
|
20
|
+
# @return [Array<Integer>] the RGB value
|
21
|
+
# @rbs (String | Symbol name) -> Array[Integer]?
|
22
|
+
def self.[]: (String | Symbol name) -> Array[Integer]?
|
23
|
+
|
24
|
+
# Get a list of all color names
|
25
|
+
#
|
26
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
27
|
+
# @since 0.3.1
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
#
|
31
|
+
# @return [Array<Symbol>] the color names
|
32
|
+
def self.names: () -> untyped
|
33
|
+
|
34
|
+
# Register a named color with an RGB or Hexadecimal value
|
35
|
+
#
|
36
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
37
|
+
# @since 0.4.0
|
38
|
+
#
|
39
|
+
# @api private
|
40
|
+
#
|
41
|
+
# @param name [String, Symbol] the name of the color being registered
|
42
|
+
# @param rgb_or_hex [Array<Integer>, String] the RGB or Hexadecimal value of the color
|
43
|
+
#
|
44
|
+
# @return [Boolean] `true` if the color was registered
|
45
|
+
# @rbs (String | Symbol name, Array[Integer] | String rgb_or_hex) -> void
|
46
|
+
def self.register: (String | Symbol name, Array[Integer] | String rgb_or_hex) -> void
|
47
|
+
|
48
|
+
# Subscribe to registry changes
|
49
|
+
#
|
50
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
51
|
+
# @since 0.4.0
|
52
|
+
#
|
53
|
+
# @api private
|
54
|
+
#
|
55
|
+
# @param subscriber [Object] the subscriber
|
56
|
+
#
|
57
|
+
# @return [void]
|
58
|
+
# @rbs (Object subscriber) -> void
|
59
|
+
def self.subscribe: (Object subscriber) -> void
|
60
|
+
|
61
|
+
# Broadcast a color registration to all subscribers
|
62
|
+
#
|
63
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
64
|
+
# @since 0.4.0
|
65
|
+
#
|
66
|
+
# @api private
|
67
|
+
#
|
68
|
+
# @param color_name [Symbol] the color name
|
69
|
+
#
|
70
|
+
# @return [void]
|
71
|
+
# @rbs (Symbol name) -> void
|
72
|
+
private def self.broadcast_registration: (Symbol name) -> void
|
73
|
+
|
74
|
+
# The Sai named colors lookup
|
75
|
+
#
|
76
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
77
|
+
# @since 0.4.0
|
78
|
+
#
|
79
|
+
# @api private
|
80
|
+
#
|
81
|
+
# @return [Hash{Symbol => Array<Integer>}] the named colors lookup
|
82
|
+
private def self.lookup: () -> untyped
|
83
|
+
|
84
|
+
# The registry subscribers
|
85
|
+
#
|
86
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
87
|
+
# @since 0.4.0
|
88
|
+
#
|
89
|
+
# @api private
|
90
|
+
#
|
91
|
+
# @return [Array<Class, Module, Object>] the subscribers
|
92
|
+
# @rbs () -> Array[Class | Module | Object]
|
93
|
+
private def self.subscribers: () -> Array[Class | Module | Object]
|
94
|
+
|
95
|
+
# A Mutex for thread safety
|
96
|
+
#
|
97
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
98
|
+
# @since 0.4.0
|
99
|
+
#
|
100
|
+
# @api private
|
101
|
+
#
|
102
|
+
# @return [Mutex] the thread lock
|
103
|
+
# @rbs () -> Mutex
|
104
|
+
private def self.thread_lock: () -> Mutex
|
105
|
+
end
|
106
|
+
end
|