sai 0.1.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 +7 -0
- data/.yardopts +11 -0
- data/CHANGELOG.md +18 -0
- data/LICENSE +21 -0
- data/README.md +275 -0
- data/lib/sai/ansi.rb +94 -0
- data/lib/sai/conversion/color_sequence.rb +167 -0
- data/lib/sai/conversion/rgb.rb +322 -0
- data/lib/sai/decorator.rb +856 -0
- data/lib/sai/support.rb +115 -0
- data/lib/sai/terminal/capabilities.rb +121 -0
- data/lib/sai/terminal/color_mode.rb +63 -0
- data/lib/sai.rb +185 -0
- data/sig/sai/ansi.rbs +51 -0
- data/sig/sai/conversion/color_sequence.rbs +114 -0
- data/sig/sai/conversion/rgb.rbs +243 -0
- data/sig/sai/decorator.rbs +246 -0
- data/sig/sai/support.rbs +108 -0
- data/sig/sai/terminal/capabilities.rbs +81 -0
- data/sig/sai/terminal/color_mode.rbs +63 -0
- data/sig/sai.rbs +207 -0
- metadata +67 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
# Generated from lib/sai/conversion/rgb.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module Conversion
|
5
|
+
# RGB color conversion utilities
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since unreleased
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
module RGB
|
12
|
+
# Get closest ANSI color for RGB values
|
13
|
+
#
|
14
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
+
# @since unreleased
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @param red [Float] the red component (0-1)
|
20
|
+
# @param green [Float] the green component (0-1)
|
21
|
+
# @param blue [Float] the blue component (0-1)
|
22
|
+
#
|
23
|
+
# @return [Symbol] the closest ANSI color name
|
24
|
+
# @rbs (Float red, Float green, Float blue) -> Symbol
|
25
|
+
def self.closest_ansi_color: (Float red, Float green, Float blue) -> Symbol
|
26
|
+
|
27
|
+
# Determine if a color is dark
|
28
|
+
#
|
29
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
30
|
+
# @since unreleased
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
#
|
34
|
+
# @param red [Float] the red component (0-1)
|
35
|
+
# @param green [Float] the green component (0-1)
|
36
|
+
# @param blue [Float] the blue component (0-1)
|
37
|
+
#
|
38
|
+
# @return [Boolean] true if color is dark
|
39
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
40
|
+
def self.dark?: (Float red, Float green, Float blue) -> bool
|
41
|
+
|
42
|
+
# Determine if a color is grayscale
|
43
|
+
#
|
44
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
45
|
+
# @since unreleased
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
#
|
49
|
+
# @param red [Float] the red component (0-1)
|
50
|
+
# @param green [Float] the green component (0-1)
|
51
|
+
# @param blue [Float] the blue component (0-1)
|
52
|
+
#
|
53
|
+
# @return [Boolean] true if color is grayscale
|
54
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
55
|
+
def self.grayscale?: (Float red, Float green, Float blue) -> bool
|
56
|
+
|
57
|
+
# Convert a color value to RGB components
|
58
|
+
#
|
59
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
60
|
+
# @since unreleased
|
61
|
+
#
|
62
|
+
# @api private
|
63
|
+
#
|
64
|
+
# @param color [String, Array<Integer>] the color to convert
|
65
|
+
#
|
66
|
+
# @raise [ArgumentError] if the color format is invalid
|
67
|
+
# @return [Array<Integer>] the RGB components
|
68
|
+
# @rbs (Array[Integer] | String | Symbol color) -> Array[Integer]
|
69
|
+
def self.resolve: (Array[Integer] | String | Symbol color) -> Array[Integer]
|
70
|
+
|
71
|
+
# Convert RGB values to 256-color cube index
|
72
|
+
#
|
73
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
74
|
+
# @since unreleased
|
75
|
+
#
|
76
|
+
# @api private
|
77
|
+
#
|
78
|
+
# @param rgb [Array<Integer>] RGB values (0-255)
|
79
|
+
#
|
80
|
+
# @return [Integer] the color cube index
|
81
|
+
# @rbs (Array[Integer] rgb) -> Integer
|
82
|
+
def self.to_color_cube_index: (Array[Integer] rgb) -> Integer
|
83
|
+
|
84
|
+
# Convert RGB values to grayscale index
|
85
|
+
#
|
86
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
87
|
+
# @since unreleased
|
88
|
+
#
|
89
|
+
# @api private
|
90
|
+
#
|
91
|
+
# @param rgb [Array<Integer>] RGB values
|
92
|
+
#
|
93
|
+
# @return [Integer] the grayscale index
|
94
|
+
# @rbs (Array[Integer] rgb) -> Integer
|
95
|
+
def self.to_grayscale_index: (Array[Integer] rgb) -> Integer
|
96
|
+
|
97
|
+
# Check if RGB values represent cyan
|
98
|
+
#
|
99
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
100
|
+
# @since unreleased
|
101
|
+
#
|
102
|
+
# @api private
|
103
|
+
#
|
104
|
+
# @param red [Float] the red component (0-1)
|
105
|
+
# @param green [Float] the green component (0-1)
|
106
|
+
# @param blue [Float] the blue component (0-1)
|
107
|
+
#
|
108
|
+
# @return [Boolean] true if color is cyan
|
109
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
110
|
+
private def self.cyan?: (Float red, Float green, Float blue) -> bool
|
111
|
+
|
112
|
+
# Convert a hex string to RGB values
|
113
|
+
#
|
114
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
115
|
+
# @since unreleased
|
116
|
+
#
|
117
|
+
# @api private
|
118
|
+
#
|
119
|
+
# @param hex [String] the hex color code
|
120
|
+
#
|
121
|
+
# @return [Array<Integer>] the RGB components
|
122
|
+
# @rbs (String hex) -> Array[Integer]
|
123
|
+
private def self.hex_to_rgb: (String hex) -> Array[Integer]
|
124
|
+
|
125
|
+
# Check if RGB values represent magenta
|
126
|
+
#
|
127
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
128
|
+
# @since unreleased
|
129
|
+
#
|
130
|
+
# @api private
|
131
|
+
#
|
132
|
+
# @param red [Float] the red component (0-1)
|
133
|
+
# @param green [Float] the green component (0-1)
|
134
|
+
# @param blue [Float] the blue component (0-1)
|
135
|
+
#
|
136
|
+
# @return [Boolean] true if color is magenta
|
137
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
138
|
+
private def self.magenta?: (Float red, Float green, Float blue) -> bool
|
139
|
+
|
140
|
+
# Convert a named color to RGB values
|
141
|
+
#
|
142
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
143
|
+
# @since unreleased
|
144
|
+
#
|
145
|
+
# @api private
|
146
|
+
#
|
147
|
+
# @param color_name [String] the color name
|
148
|
+
#
|
149
|
+
# @raise [ArgumentError] if the color name is unknown
|
150
|
+
# @return [Array<Integer>] the RGB components
|
151
|
+
# @rbs (String color_name) -> Array[Integer]
|
152
|
+
private def self.named_to_rgb: (String color_name) -> Array[Integer]
|
153
|
+
|
154
|
+
# Determine if RGB values represent a primary color
|
155
|
+
#
|
156
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
157
|
+
# @since unreleased
|
158
|
+
#
|
159
|
+
# @api private
|
160
|
+
#
|
161
|
+
# @param red [Float] the red component (0-1)
|
162
|
+
# @param green [Float] the green component (0-1)
|
163
|
+
# @param blue [Float] the blue component (0-1)
|
164
|
+
#
|
165
|
+
# @return [Boolean] true if color is primary
|
166
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
167
|
+
private def self.primary?: (Float red, Float green, Float blue) -> bool
|
168
|
+
|
169
|
+
# Get the closest primary color
|
170
|
+
#
|
171
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
172
|
+
# @since unreleased
|
173
|
+
#
|
174
|
+
# @api private
|
175
|
+
#
|
176
|
+
# @param red [Float] the red component (0-1)
|
177
|
+
# @param green [Float] the green component (0-1)
|
178
|
+
# @param blue [Float] the blue component (0-1)
|
179
|
+
#
|
180
|
+
# @return [Symbol] the primary color name
|
181
|
+
# @rbs (Float red, Float green, Float blue) -> Symbol
|
182
|
+
private def self.primary_color: (Float red, Float green, Float blue) -> Symbol
|
183
|
+
|
184
|
+
# Determine if RGB values represent a secondary color
|
185
|
+
#
|
186
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
187
|
+
# @since unreleased
|
188
|
+
#
|
189
|
+
# @api private
|
190
|
+
#
|
191
|
+
# @param red [Float] the red component (0-1)
|
192
|
+
# @param green [Float] the green component (0-1)
|
193
|
+
# @param blue [Float] the blue component (0-1)
|
194
|
+
#
|
195
|
+
# @return [Boolean] true if color is secondary
|
196
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
197
|
+
private def self.secondary?: (Float red, Float green, Float blue) -> bool
|
198
|
+
|
199
|
+
# Get the closest secondary color
|
200
|
+
#
|
201
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
202
|
+
# @since unreleased
|
203
|
+
#
|
204
|
+
# @api private
|
205
|
+
#
|
206
|
+
# @param red [Float] the red component (0-1)
|
207
|
+
# @param green [Float] the green component (0-1)
|
208
|
+
# @param blue [Float] the blue component (0-1)
|
209
|
+
#
|
210
|
+
# @return [Symbol] the secondary color name
|
211
|
+
# @rbs (Float red, Float green, Float blue) -> Symbol
|
212
|
+
private def self.secondary_color: (Float red, Float green, Float blue) -> Symbol
|
213
|
+
|
214
|
+
# Validate RGB values
|
215
|
+
#
|
216
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
217
|
+
# @since unreleased
|
218
|
+
#
|
219
|
+
# @api private
|
220
|
+
#
|
221
|
+
# @param color [Array<Integer>] the RGB components to validate
|
222
|
+
# @return [Array<Integer>] the validated RGB components
|
223
|
+
# @raise [ArgumentError] if the RGB values are invalid
|
224
|
+
# @rbs (Array[Integer] color) -> Array[Integer]
|
225
|
+
private def self.validate_rgb: (Array[Integer] color) -> Array[Integer]
|
226
|
+
|
227
|
+
# Check if RGB values represent yellow
|
228
|
+
#
|
229
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
230
|
+
# @since unreleased
|
231
|
+
#
|
232
|
+
# @api private
|
233
|
+
#
|
234
|
+
# @param red [Float] the red component (0-1)
|
235
|
+
# @param green [Float] the green component (0-1)
|
236
|
+
# @param blue [Float] the blue component (0-1)
|
237
|
+
#
|
238
|
+
# @return [Boolean] true if color is yellow
|
239
|
+
# @rbs (Float red, Float green, Float blue) -> bool
|
240
|
+
private def self.yellow?: (Float red, Float green, Float blue) -> bool
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# Generated from lib/sai/decorator.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
# A decorator for applying ANSI styles and colors to text
|
5
|
+
#
|
6
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
7
|
+
# @since unreleased
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class Decorator
|
11
|
+
# Initialize a new instance of Decorator
|
12
|
+
#
|
13
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
14
|
+
# @since unreleased
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
# @param color_mode [Integer] the color mode to use
|
19
|
+
#
|
20
|
+
# @return [Decorator] the new instance of Decorator
|
21
|
+
# @rbs (Integer color_mode) -> void
|
22
|
+
def initialize: (Integer color_mode) -> void
|
23
|
+
|
24
|
+
def black: () -> self
|
25
|
+
|
26
|
+
def blue: () -> self
|
27
|
+
|
28
|
+
def bright_black: () -> self
|
29
|
+
|
30
|
+
def bright_blue: () -> self
|
31
|
+
|
32
|
+
def bright_cyan: () -> self
|
33
|
+
|
34
|
+
def bright_green: () -> self
|
35
|
+
|
36
|
+
def bright_magenta: () -> self
|
37
|
+
|
38
|
+
def bright_red: () -> self
|
39
|
+
|
40
|
+
def bright_white: () -> self
|
41
|
+
|
42
|
+
def bright_yellow: () -> self
|
43
|
+
|
44
|
+
def cyan: () -> self
|
45
|
+
|
46
|
+
def green: () -> self
|
47
|
+
|
48
|
+
def magenta: () -> self
|
49
|
+
|
50
|
+
def on_black: () -> self
|
51
|
+
|
52
|
+
def on_blue: () -> self
|
53
|
+
|
54
|
+
def on_bright_black: () -> self
|
55
|
+
|
56
|
+
def on_bright_blue: () -> self
|
57
|
+
|
58
|
+
def on_bright_cyan: () -> self
|
59
|
+
|
60
|
+
def on_bright_green: () -> self
|
61
|
+
|
62
|
+
def on_bright_magenta: () -> self
|
63
|
+
|
64
|
+
def on_bright_red: () -> self
|
65
|
+
|
66
|
+
def on_bright_white: () -> self
|
67
|
+
|
68
|
+
def on_bright_yellow: () -> self
|
69
|
+
|
70
|
+
def on_cyan: () -> self
|
71
|
+
|
72
|
+
def on_green: () -> self
|
73
|
+
|
74
|
+
def on_magenta: () -> self
|
75
|
+
|
76
|
+
def on_red: () -> self
|
77
|
+
|
78
|
+
def on_white: () -> self
|
79
|
+
|
80
|
+
def on_yellow: () -> self
|
81
|
+
|
82
|
+
def red: () -> self
|
83
|
+
|
84
|
+
def white: () -> self
|
85
|
+
|
86
|
+
def yellow: () -> self
|
87
|
+
|
88
|
+
def blink: () -> self
|
89
|
+
|
90
|
+
def bold: () -> self
|
91
|
+
|
92
|
+
def conceal: () -> self
|
93
|
+
|
94
|
+
def dim: () -> self
|
95
|
+
|
96
|
+
def italic: () -> self
|
97
|
+
|
98
|
+
def no_blink: () -> self
|
99
|
+
|
100
|
+
def no_conceal: () -> self
|
101
|
+
|
102
|
+
def no_italic: () -> self
|
103
|
+
|
104
|
+
def no_reverse: () -> self
|
105
|
+
|
106
|
+
def no_strike: () -> self
|
107
|
+
|
108
|
+
def no_underline: () -> self
|
109
|
+
|
110
|
+
def normal_intensity: () -> self
|
111
|
+
|
112
|
+
def rapid_blink: () -> self
|
113
|
+
|
114
|
+
def reverse: () -> self
|
115
|
+
|
116
|
+
def strike: () -> self
|
117
|
+
|
118
|
+
def underline: () -> self
|
119
|
+
|
120
|
+
# Apply the styles and colors to the text
|
121
|
+
#
|
122
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
123
|
+
# @since unreleased
|
124
|
+
#
|
125
|
+
# @api public
|
126
|
+
#
|
127
|
+
# @example
|
128
|
+
# decorator.red.on_blue.bold.decorate('Hello, world!')
|
129
|
+
# #=> "\e[38;2;205;0;0m\e[48;2;0;0;238m\e[1mHello, world!\e[0m"
|
130
|
+
#
|
131
|
+
# @param text [String] the text to decorate
|
132
|
+
#
|
133
|
+
# @return [String] the decorated text
|
134
|
+
# @rbs (String text) -> String
|
135
|
+
def decorate: (String text) -> String
|
136
|
+
|
137
|
+
alias apply decorate
|
138
|
+
|
139
|
+
alias call decorate
|
140
|
+
|
141
|
+
alias encode decorate
|
142
|
+
|
143
|
+
# Apply a hexadecimal color to the foreground
|
144
|
+
#
|
145
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
146
|
+
# @since unreleased
|
147
|
+
#
|
148
|
+
# @api public
|
149
|
+
#
|
150
|
+
# @example
|
151
|
+
# decorator.hex("#EB4133").decorate('Hello, world!') #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
152
|
+
#
|
153
|
+
# @param code [String] the hex color code
|
154
|
+
#
|
155
|
+
# @raise [ArgumentError] if the hex code is invalid
|
156
|
+
# @return [self] the instance of Decorator for chaining
|
157
|
+
# @rbs (String code) -> self
|
158
|
+
def hex: (String code) -> self
|
159
|
+
|
160
|
+
# Apply a hexadecimal color to the background
|
161
|
+
#
|
162
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
163
|
+
# @since unreleased
|
164
|
+
#
|
165
|
+
# @api public
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# decorator.on_hex("#EB4133").decorate('Hello, world!') #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
169
|
+
#
|
170
|
+
# @param code [String] the hex color code
|
171
|
+
#
|
172
|
+
# @raise [ArgumentError] if the hex code is invalid
|
173
|
+
# @return [self] the instance of Decorator for chaining
|
174
|
+
# @rbs (String code) -> self
|
175
|
+
def on_hex: (String code) -> self
|
176
|
+
|
177
|
+
# Apply an RGB color to the background
|
178
|
+
#
|
179
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
180
|
+
# @since unreleased
|
181
|
+
#
|
182
|
+
# @api public
|
183
|
+
#
|
184
|
+
# @example
|
185
|
+
# decorator.on_rgb(235, 65, 51).decorate('Hello, world!') #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
186
|
+
#
|
187
|
+
# @param red [Integer] the red component
|
188
|
+
# @param green [Integer] the green component
|
189
|
+
# @param blue [Integer] the blue component
|
190
|
+
#
|
191
|
+
# @raise [ArgumentError] if the RGB values are out of range
|
192
|
+
# @return [self] the instance of Decorator for chaining
|
193
|
+
# @rbs (Integer red, Integer green, Integer blue) -> self
|
194
|
+
def on_rgb: (Integer red, Integer green, Integer blue) -> self
|
195
|
+
|
196
|
+
# Apply an RGB color to the foreground
|
197
|
+
#
|
198
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
199
|
+
# @since unreleased
|
200
|
+
#
|
201
|
+
# @api public
|
202
|
+
#
|
203
|
+
# @example
|
204
|
+
# decorator.rgb(235, 65, 51).decorate('Hello, world!') #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
205
|
+
#
|
206
|
+
# @param red [Integer] the red component
|
207
|
+
# @param green [Integer] the green component
|
208
|
+
# @param blue [Integer] the blue component
|
209
|
+
#
|
210
|
+
# @raise [ArgumentError] if the RGB values are out of range
|
211
|
+
# @return [self] the instance of Decorator for chaining
|
212
|
+
# @rbs (Integer red, Integer green, Integer blue) -> self
|
213
|
+
def rgb: (Integer red, Integer green, Integer blue) -> self
|
214
|
+
|
215
|
+
private
|
216
|
+
|
217
|
+
# Apply a named color to the specified style type
|
218
|
+
#
|
219
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
220
|
+
# @since unreleased
|
221
|
+
#
|
222
|
+
# @api private
|
223
|
+
#
|
224
|
+
# @param style_type [Symbol] the style type to apply the color to
|
225
|
+
# @param color [Symbol] the color to apply
|
226
|
+
#
|
227
|
+
# @raise [ArgumentError] if the color is invalid
|
228
|
+
# @return [self] the instance of Decorator for chaining
|
229
|
+
# @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> self
|
230
|
+
def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> self
|
231
|
+
|
232
|
+
# Apply a style to the text
|
233
|
+
#
|
234
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
235
|
+
# @since unreleased
|
236
|
+
#
|
237
|
+
# @api private
|
238
|
+
#
|
239
|
+
# @param style [String, Symbol] the style to apply
|
240
|
+
#
|
241
|
+
# @raise [ArgumentError] if the style is invalid
|
242
|
+
# @return [self] the instance of Decorator for chaining
|
243
|
+
# @rbs (String | Symbol style) -> self
|
244
|
+
def apply_style: (String | Symbol style) -> self
|
245
|
+
end
|
246
|
+
end
|
data/sig/sai/support.rbs
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Generated from lib/sai/support.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
# Determine the color capabilities of the terminal
|
5
|
+
#
|
6
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
7
|
+
# @since unreleased
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class Support
|
11
|
+
# Initialize a new instance of Support
|
12
|
+
#
|
13
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
14
|
+
# @since unreleased
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
# @param color_mode [Integer] the color mode
|
19
|
+
#
|
20
|
+
# @return [Support] the new instance of support
|
21
|
+
# @rbs (Integer color_mode) -> void
|
22
|
+
def initialize: (Integer color_mode) -> void
|
23
|
+
|
24
|
+
# Check if the terminal supports ANSI colors (4-bit)
|
25
|
+
#
|
26
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
27
|
+
# @since unreleased
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
#
|
31
|
+
# @example Check if the terminal supports ANSI colors
|
32
|
+
# Sai.ansi? # => true
|
33
|
+
#
|
34
|
+
# @return [Boolean] `true` if the terminal supports ANSI colors (4-bit), otherwise `false`
|
35
|
+
# @rbs () -> bool
|
36
|
+
def ansi?: () -> bool
|
37
|
+
|
38
|
+
alias bit4? ansi?
|
39
|
+
|
40
|
+
alias four_bit? ansi?
|
41
|
+
|
42
|
+
# Check if the terminal supports basic colors (3-bit)
|
43
|
+
#
|
44
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
45
|
+
# @since unreleased
|
46
|
+
#
|
47
|
+
# @api public
|
48
|
+
#
|
49
|
+
# @example Check if the terminal supports basic colors
|
50
|
+
# Sai.basic? # => true
|
51
|
+
#
|
52
|
+
# @return [Boolean] `true` if the terminal supports basic colors (3-bit), otherwise `false`
|
53
|
+
# @rbs () -> bool
|
54
|
+
def basic?: () -> bool
|
55
|
+
|
56
|
+
alias bit3? basic?
|
57
|
+
|
58
|
+
alias three_bit? basic?
|
59
|
+
|
60
|
+
# Check if the terminal supports 256 colors (8-bit)
|
61
|
+
#
|
62
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
63
|
+
# @since unreleased
|
64
|
+
#
|
65
|
+
# @api public
|
66
|
+
#
|
67
|
+
# @example Check if the terminal supports 256 colors
|
68
|
+
# Sai.bit_8? # => true
|
69
|
+
#
|
70
|
+
# @return [Boolean] `true` if the terminal supports 256 colors (8-bit), otherwise `false`
|
71
|
+
# @rbs () -> bool
|
72
|
+
def bit8?: () -> bool
|
73
|
+
|
74
|
+
alias eight_bit? bit8?
|
75
|
+
|
76
|
+
# Check if the terminal supports color output
|
77
|
+
#
|
78
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
79
|
+
# @since unreleased
|
80
|
+
#
|
81
|
+
# @api public
|
82
|
+
#
|
83
|
+
# @example Check if the terminal supports color
|
84
|
+
# Sai.color? # => true
|
85
|
+
#
|
86
|
+
# @return [Boolean] `true` if the terminal supports color output, otherwise `false`
|
87
|
+
# @rbs () -> bool
|
88
|
+
def color?: () -> bool
|
89
|
+
|
90
|
+
# Check if the terminal supports true color (24-bit)
|
91
|
+
#
|
92
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
93
|
+
# @since unreleased
|
94
|
+
#
|
95
|
+
# @api public
|
96
|
+
#
|
97
|
+
# @example Check if the terminal supports true color
|
98
|
+
# Sai.true_color? # => true
|
99
|
+
#
|
100
|
+
# @return [Boolean] `true` if the terminal supports true color (24-bit), otherwise `false`
|
101
|
+
# @rbs () -> bool
|
102
|
+
def true_color?: () -> bool
|
103
|
+
|
104
|
+
alias bit24? true_color?
|
105
|
+
|
106
|
+
alias twenty_four_bit? true_color?
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated from lib/sai/terminal/capabilities.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module Terminal
|
5
|
+
# Detect the color capabilities of the terminal
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since unreleased
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
module Capabilities
|
12
|
+
# Detect the color capabilities of the current terminal
|
13
|
+
#
|
14
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
+
# @since unreleased
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @return [Integer] the {ColorMode} of the terminal
|
20
|
+
# @rbs () -> Integer
|
21
|
+
def self.detect_color_support: () -> Integer
|
22
|
+
|
23
|
+
# Check for ANSI color support
|
24
|
+
#
|
25
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
26
|
+
# @since unreleased
|
27
|
+
#
|
28
|
+
# @api private
|
29
|
+
#
|
30
|
+
# @return [Boolean] `true` if the terminal supports basic ANSI colors, otherwise `false`
|
31
|
+
# @rbs () -> bool
|
32
|
+
private def self.ansi?: () -> bool
|
33
|
+
|
34
|
+
# Check for basic color support
|
35
|
+
#
|
36
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
37
|
+
# @since unreleased
|
38
|
+
#
|
39
|
+
# @api private
|
40
|
+
#
|
41
|
+
# @return [Boolean] `true` if the terminal supports basic colors, otherwise `false`
|
42
|
+
# @rbs () -> bool
|
43
|
+
private def self.basic?: () -> bool
|
44
|
+
|
45
|
+
# Check for 256 color (8-bit) support
|
46
|
+
#
|
47
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
48
|
+
# @since unreleased
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
#
|
52
|
+
# @return [Boolean] `true` if the terminal supports 256 colors, otherwise `false`
|
53
|
+
# @rbs () -> bool
|
54
|
+
private def self.bit8?: () -> bool
|
55
|
+
|
56
|
+
# Check for NO_COLOR environment variable
|
57
|
+
#
|
58
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
59
|
+
# @since unreleased
|
60
|
+
#
|
61
|
+
# @api private
|
62
|
+
#
|
63
|
+
# @see https://no-color.org
|
64
|
+
#
|
65
|
+
# @return [Boolean] `true` if the NO_COLOR environment variable is set, otherwise `false`
|
66
|
+
# @rbs () -> bool
|
67
|
+
private def self.no_color?: () -> bool
|
68
|
+
|
69
|
+
# Check for true color (24-bit) support
|
70
|
+
#
|
71
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
72
|
+
# @since unreleased
|
73
|
+
#
|
74
|
+
# @api private
|
75
|
+
#
|
76
|
+
# @return [Boolean] `true` if the terminal supports true color, otherwise `false`
|
77
|
+
# @rbs () -> bool
|
78
|
+
private def self.true_color?: () -> bool
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|