sai 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/README.md +40 -7
- data/lib/sai/ansi.rb +5 -5
- data/lib/sai/conversion/color_sequence.rb +31 -31
- data/lib/sai/conversion/rgb.rb +17 -17
- data/lib/sai/decorator.rb +201 -171
- data/lib/sai/mode_selector.rb +298 -0
- data/lib/sai/support.rb +99 -98
- data/lib/sai/terminal/capabilities.rb +22 -22
- data/lib/sai/terminal/color_mode.rb +7 -7
- data/lib/sai.rb +106 -77
- data/sig/sai/ansi.rbs +5 -5
- data/sig/sai/conversion/color_sequence.rbs +21 -21
- data/sig/sai/conversion/rgb.rbs +17 -17
- data/sig/sai/decorator.rbs +103 -76
- data/sig/sai/mode_selector.rbs +319 -0
- data/sig/sai/support.rbs +50 -37
- data/sig/sai/terminal/capabilities.rbs +16 -16
- data/sig/sai/terminal/color_mode.rbs +7 -7
- data/sig/sai.rbs +92 -66
- metadata +6 -4
@@ -0,0 +1,298 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sai/terminal/capabilities'
|
4
|
+
require 'sai/terminal/color_mode'
|
5
|
+
|
6
|
+
module Sai
|
7
|
+
# Color mode selection methods
|
8
|
+
#
|
9
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
10
|
+
# @since 0.2.0
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
module ModeSelector
|
14
|
+
class << self
|
15
|
+
# Set the color mode to 256 color (8-bit) mode
|
16
|
+
#
|
17
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
18
|
+
# @since 0.2.0
|
19
|
+
#
|
20
|
+
# @api private
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# Sai.mode.advanced #=> 3
|
24
|
+
# Sai.mode.eight_bit #=> 3
|
25
|
+
# Sai.mode.color256 #=> 3
|
26
|
+
#
|
27
|
+
# @return [Integer] the color mode
|
28
|
+
# @rbs () -> Integer
|
29
|
+
def advanced
|
30
|
+
Terminal::ColorMode::ADVANCED
|
31
|
+
end
|
32
|
+
alias color256 advanced
|
33
|
+
alias colour256 advanced
|
34
|
+
alias eight_bit advanced
|
35
|
+
alias two_hundred_fifty_six_color advanced
|
36
|
+
alias two_hundred_fifty_six_colour advanced
|
37
|
+
|
38
|
+
# Automatically set the color mode to advanced (8-bit) or lower
|
39
|
+
#
|
40
|
+
# Sets the terminal color mode to advanced (8-bit) support, which provides 256 colors
|
41
|
+
# The mode will automatically downgrade to 4-bit, 3-bit, or NO_COLOR if the terminal doesn't support
|
42
|
+
# advanced colors
|
43
|
+
#
|
44
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
45
|
+
# @since 0.2.0
|
46
|
+
#
|
47
|
+
# @api public
|
48
|
+
#
|
49
|
+
# @example With color support enabled
|
50
|
+
# ENV['COLORTERM'] #=> nil
|
51
|
+
# ENV['TERM'] #=> 'xterm-256color'
|
52
|
+
# Sai.mode.ansi_auto #=> 3
|
53
|
+
# Sai.mode.four_bit_auto #=> 3
|
54
|
+
# Sai.mode.color_16_auto #=> 3
|
55
|
+
#
|
56
|
+
# @example With only 4-bit color support
|
57
|
+
# ENV['NO_COLOR'] #=> nil
|
58
|
+
# ENV['TERM'] #=> 'ansi'
|
59
|
+
# Sai.mode.ansi_auto #=> 2
|
60
|
+
# Sai.mode.four_bit_auto #=> 2
|
61
|
+
# Sai.mode.color_16_auto #=> 2
|
62
|
+
#
|
63
|
+
# @example With only 3-bit color support
|
64
|
+
# ENV['TERM'] #=> nil
|
65
|
+
# ENV['NO_COLOR'] #=> nil
|
66
|
+
# Sai.mode.ansi_auto #=> 1
|
67
|
+
# Sai.mode.four_bit_auto #=> 1
|
68
|
+
# Sai.mode.color16_auto #=> 1
|
69
|
+
#
|
70
|
+
# @example With color support disabled
|
71
|
+
# ENV['NO_COLOR'] #=> 'true'
|
72
|
+
# Sai.mode.ansi_auto #=> 0
|
73
|
+
# Sai.mode.four_bit_auto #=> 0
|
74
|
+
# Sai.mode.color16_auto #=> 0
|
75
|
+
#
|
76
|
+
# @return [Integer] the color mode
|
77
|
+
# @rbs () -> Integer
|
78
|
+
def advanced_auto
|
79
|
+
[Terminal::Capabilities.detect_color_support, Terminal::ColorMode::ADVANCED].min
|
80
|
+
end
|
81
|
+
alias color256_auto advanced_auto
|
82
|
+
alias colour256_auto advanced_auto
|
83
|
+
alias eight_bit_auto advanced_auto
|
84
|
+
alias two_hundred_fifty_six_color_auto advanced_auto
|
85
|
+
alias two_hundred_fifty_six_colour_auto advanced_auto
|
86
|
+
|
87
|
+
# Set the color mode to 16 color (4-bit) mode
|
88
|
+
#
|
89
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
90
|
+
# @since 0.2.0
|
91
|
+
#
|
92
|
+
# @api public
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# Sai.mode.ansi #=> 2
|
96
|
+
# Sai.mode.color16 #=> 2
|
97
|
+
# Sai.mode.four_bit #=> 2
|
98
|
+
#
|
99
|
+
# @return [Integer] the color mode
|
100
|
+
# @rbs () -> Integer
|
101
|
+
def ansi
|
102
|
+
Terminal::ColorMode::ANSI
|
103
|
+
end
|
104
|
+
alias color16 ansi
|
105
|
+
alias colour16 ansi
|
106
|
+
alias four_bit ansi
|
107
|
+
alias sixteen_color ansi
|
108
|
+
alias sixteen_colour ansi
|
109
|
+
|
110
|
+
# Automatically set the color mode to ansi (4-bit) or lower
|
111
|
+
#
|
112
|
+
# Sets the terminal color mode to ansi (4-bit) support, which provides 8 colors
|
113
|
+
# The mode will automatically downgrade to 3-bit or NO_COLOR if the terminal doesn't support
|
114
|
+
# ansi colors
|
115
|
+
#
|
116
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
117
|
+
# @since 0.2.0
|
118
|
+
#
|
119
|
+
# @api public
|
120
|
+
#
|
121
|
+
# @example With color support enabled
|
122
|
+
# ENV['NO_COLOR'] #=> nil
|
123
|
+
# ENV['TERM'] #=> 'ansi'
|
124
|
+
# Sai.mode.ansi_auto #=> 2
|
125
|
+
# Sai.mode.four_bit_auto #=> 2
|
126
|
+
# Sai.mode.color_16_auto #=> 2
|
127
|
+
#
|
128
|
+
# @example With only 3-bit color support
|
129
|
+
# ENV['TERM'] #=> nil
|
130
|
+
# ENV['NO_COLOR'] #=> nil
|
131
|
+
# Sai.mode.ansi_auto #=> 1
|
132
|
+
# Sai.mode.four_bit_auto #=> 1
|
133
|
+
# Sai.mode.color16_auto #=> 1
|
134
|
+
#
|
135
|
+
# @example With color support disabled
|
136
|
+
# ENV['NO_COLOR'] #=> 'true'
|
137
|
+
# Sai.mode.ansi_auto #=> 0
|
138
|
+
# Sai.mode.four_bit_auto #=> 0
|
139
|
+
# Sai.mode.color16_auto #=> 0
|
140
|
+
#
|
141
|
+
# @return [Integer] the color mode
|
142
|
+
# @rbs () -> Integer
|
143
|
+
def ansi_auto
|
144
|
+
[Terminal::Capabilities.detect_color_support, Terminal::ColorMode::ANSI].min
|
145
|
+
end
|
146
|
+
alias color16_auto ansi_auto
|
147
|
+
alias colour16_auto ansi_auto
|
148
|
+
alias four_bit_auto ansi_auto
|
149
|
+
alias sixteen_color_auto ansi_auto
|
150
|
+
alias sixteen_colour_auto ansi_auto
|
151
|
+
|
152
|
+
# Set the color mode based on the current Terminal's capabilities
|
153
|
+
#
|
154
|
+
# This is the default color mode for {Sai}
|
155
|
+
#
|
156
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
157
|
+
# @since 0.2.0
|
158
|
+
#
|
159
|
+
# @api public
|
160
|
+
#
|
161
|
+
# @example With 24-bit color support enabled
|
162
|
+
# ENV['COLORTERM'] #=> 'truecolor'
|
163
|
+
# Sai.node.auto #=> 4
|
164
|
+
#
|
165
|
+
# @example With only 8-bit color support enabled
|
166
|
+
# ENV['COLORTERM'] #=> nil
|
167
|
+
# ENV['TERM'] #=> 'xterm-256color'
|
168
|
+
# Sai.mode.auto #=> 3
|
169
|
+
#
|
170
|
+
# @example With only 4-bit color support
|
171
|
+
# ENV['NO_COLOR'] #=> nil
|
172
|
+
# ENV['TERM'] #=> 'ansi'
|
173
|
+
# Sai.mode.auto #=> 2
|
174
|
+
#
|
175
|
+
# @example With only 3-bit color support
|
176
|
+
# ENV['TERM'] #=> nil
|
177
|
+
# ENV['NO_COLOR'] #=> nil
|
178
|
+
# Sai.mode.auto #=> 1
|
179
|
+
#
|
180
|
+
# @example With color support disabled
|
181
|
+
# ENV['NO_COLOR'] #=> 'true'
|
182
|
+
# Sai.mode.auto #=> 0
|
183
|
+
#
|
184
|
+
# @return [Integer] the color mode
|
185
|
+
# @rbs () -> Integer
|
186
|
+
def auto
|
187
|
+
Terminal::Capabilities.detect_color_support
|
188
|
+
end
|
189
|
+
alias color16m_auto auto
|
190
|
+
alias colour16m_auto auto
|
191
|
+
alias enabled auto
|
192
|
+
alias sixteen_million_color_auto auto
|
193
|
+
alias sixteen_million_colour_auto auto
|
194
|
+
alias twenty_for_bit_auto auto
|
195
|
+
|
196
|
+
# Set the color mode to 8 color (3-bit) mode
|
197
|
+
#
|
198
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
199
|
+
# @since 0.2.0
|
200
|
+
#
|
201
|
+
# @api public
|
202
|
+
#
|
203
|
+
# @example
|
204
|
+
# Sai.mode.basic #=> 1
|
205
|
+
# Sai.mode.color8 #=> 1
|
206
|
+
# Sai.mode.three_bit #=> 1
|
207
|
+
#
|
208
|
+
# @return [Integer] the 4 color (3-bit) mode
|
209
|
+
# @rbs () -> Integer
|
210
|
+
def basic
|
211
|
+
Terminal::ColorMode::BASIC
|
212
|
+
end
|
213
|
+
alias color8 basic
|
214
|
+
alias colour8 basic
|
215
|
+
alias eight_color basic
|
216
|
+
alias eight_colour basic
|
217
|
+
alias three_bit basic
|
218
|
+
|
219
|
+
# Automatically set the color mode to basic (3-bit) or lower
|
220
|
+
#
|
221
|
+
# Sets the terminal color mode to basic (3-bit) support, which provides 8 colors
|
222
|
+
# The mode will automatically downgrade to NO_COLOR if the terminal doesn't support
|
223
|
+
# basic colors
|
224
|
+
#
|
225
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
226
|
+
# @since 0.2.0
|
227
|
+
#
|
228
|
+
# @api public
|
229
|
+
#
|
230
|
+
# @example With color support enabled
|
231
|
+
# ENV['NO_COLOR'] #=> nil
|
232
|
+
# Sai.mode.basic_auto #=> 1
|
233
|
+
# Sai.mode.three_bit_auto #=> 1
|
234
|
+
# Sai.mode.color8_auto #=> 1
|
235
|
+
#
|
236
|
+
# @example With color support disabled
|
237
|
+
# ENV['NO_COLOR'] #=> 'true'
|
238
|
+
# Sai.mode.basic_auto #=> 0
|
239
|
+
# Sai.mode.three_bit_auto #=> 0
|
240
|
+
# Sai.mode.color8_auto #=> 0
|
241
|
+
#
|
242
|
+
# @return [Integer] the color mode
|
243
|
+
# @rbs () -> Integer
|
244
|
+
def basic_auto
|
245
|
+
[Terminal::Capabilities.detect_color_support, Terminal::ColorMode::BASIC].min
|
246
|
+
end
|
247
|
+
alias color8_auto basic_auto
|
248
|
+
alias colour8_auto basic_auto
|
249
|
+
alias eight_color_auto basic_auto
|
250
|
+
alias eight_colour_auto basic_auto
|
251
|
+
alias three_bit_auto basic_auto
|
252
|
+
|
253
|
+
# Set the color mode to disable all color and styling
|
254
|
+
#
|
255
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
256
|
+
# @since 0.2.0
|
257
|
+
#
|
258
|
+
# @api public
|
259
|
+
#
|
260
|
+
# @example
|
261
|
+
# Sai.mode.no_color #=> 0
|
262
|
+
# Sai.mode.disabled #=> 0
|
263
|
+
# Sai.mode.mono #=> 0
|
264
|
+
#
|
265
|
+
# @return [Integer] the color mode
|
266
|
+
# @rbs () -> Integer
|
267
|
+
def no_color
|
268
|
+
Terminal::ColorMode::NO_COLOR
|
269
|
+
end
|
270
|
+
alias disabled no_color
|
271
|
+
alias mono no_color
|
272
|
+
alias no_colour no_color
|
273
|
+
|
274
|
+
# Set the color mode to 16-million color (24-bit) mode
|
275
|
+
#
|
276
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
277
|
+
# @since 0.2.0
|
278
|
+
#
|
279
|
+
# @api private
|
280
|
+
#
|
281
|
+
# @example
|
282
|
+
# Sai.mode.true_color #=> 4
|
283
|
+
# Sai.mode.twenty_four_bit #=> 4
|
284
|
+
# Sai.mode.color_16m #=> 4
|
285
|
+
#
|
286
|
+
# @return [Integer] the color mode
|
287
|
+
# @rbs () -> Integer
|
288
|
+
def true_color
|
289
|
+
Terminal::ColorMode::TRUE_COLOR
|
290
|
+
end
|
291
|
+
alias color16m true_color
|
292
|
+
alias colour16m true_color
|
293
|
+
alias sixteen_million_color true_color
|
294
|
+
alias sixteen_million_colour true_color
|
295
|
+
alias twenty_for_bit true_color
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
data/lib/sai/support.rb
CHANGED
@@ -1,115 +1,116 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'sai/terminal/capabilities'
|
3
4
|
require 'sai/terminal/color_mode'
|
4
5
|
|
5
6
|
module Sai
|
6
7
|
# Determine the color capabilities of the terminal
|
7
8
|
#
|
8
9
|
# @author {https://aaronmallen.me Aaron Allen}
|
9
|
-
# @since
|
10
|
+
# @since 0.1.0
|
10
11
|
#
|
11
12
|
# @api public
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
#
|
35
|
-
# @example Check if the terminal supports ANSI colors
|
36
|
-
# Sai.ansi? # => true
|
37
|
-
#
|
38
|
-
# @return [Boolean] `true` if the terminal supports ANSI colors (4-bit), otherwise `false`
|
39
|
-
# @rbs () -> bool
|
40
|
-
def ansi?
|
41
|
-
@color_mode >= Terminal::ColorMode::ANSI
|
42
|
-
end
|
43
|
-
alias bit4? ansi?
|
44
|
-
alias four_bit? ansi?
|
13
|
+
module Support
|
14
|
+
class << self
|
15
|
+
# Check if the terminal supports 256 colors (8-bit)
|
16
|
+
#
|
17
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
18
|
+
# @since 0.1.0
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
#
|
22
|
+
# @example Check if the terminal supports 256 colors
|
23
|
+
# Sai.advanced? # => true
|
24
|
+
#
|
25
|
+
# @return [Boolean] `true` if the terminal supports 256 colors (8-bit), otherwise `false`
|
26
|
+
# @rbs () -> bool
|
27
|
+
def advanced?
|
28
|
+
Terminal::Capabilities.detect_color_support >= Terminal::ColorMode::ADVANCED
|
29
|
+
end
|
30
|
+
alias color256? advanced?
|
31
|
+
alias colour256? advanced?
|
32
|
+
alias eight_bit? advanced?
|
33
|
+
alias two_hundred_fifty_six_color? advanced?
|
34
|
+
alias two_hundred_fifty_six_colour? advanced?
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
36
|
+
# Check if the terminal supports ANSI colors (4-bit)
|
37
|
+
#
|
38
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
39
|
+
# @since 0.1.0
|
40
|
+
#
|
41
|
+
# @api public
|
42
|
+
#
|
43
|
+
# @example Check if the terminal supports ANSI colors
|
44
|
+
# Sai.ansi? # => true
|
45
|
+
#
|
46
|
+
# @return [Boolean] `true` if the terminal supports ANSI colors (4-bit), otherwise `false`
|
47
|
+
# @rbs () -> bool
|
48
|
+
def ansi?
|
49
|
+
Terminal::Capabilities.detect_color_support >= Terminal::ColorMode::ANSI
|
50
|
+
end
|
51
|
+
alias color16? ansi?
|
52
|
+
alias colour16? ansi?
|
53
|
+
alias four_bit? ansi?
|
54
|
+
alias sixteen_color? ansi?
|
55
|
+
alias sixteen_colour? ansi?
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
57
|
+
# Check if the terminal supports basic colors (3-bit)
|
58
|
+
#
|
59
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
60
|
+
# @since 0.1.0
|
61
|
+
#
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
# @example Check if the terminal supports basic colors
|
65
|
+
# Sai.basic? # => true
|
66
|
+
#
|
67
|
+
# @return [Boolean] `true` if the terminal supports basic colors (3-bit), otherwise `false`
|
68
|
+
# @rbs () -> bool
|
69
|
+
def basic?
|
70
|
+
Terminal::Capabilities.detect_color_support >= Terminal::ColorMode::BASIC
|
71
|
+
end
|
72
|
+
alias color8? basic?
|
73
|
+
alias colour8? basic?
|
74
|
+
alias eight_color? basic?
|
75
|
+
alias eight_colour? basic?
|
76
|
+
alias three_bit? basic?
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
78
|
+
# Check if the terminal supports color output
|
79
|
+
#
|
80
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
81
|
+
# @since 0.1.0
|
82
|
+
#
|
83
|
+
# @api public
|
84
|
+
#
|
85
|
+
# @example Check if the terminal supports color
|
86
|
+
# Sai.color? # => true
|
87
|
+
#
|
88
|
+
# @return [Boolean] `true` if the terminal supports color output, otherwise `false`
|
89
|
+
# @rbs () -> bool
|
90
|
+
def color?
|
91
|
+
Terminal::Capabilities.detect_color_support > Terminal::ColorMode::NO_COLOR
|
92
|
+
end
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
94
|
+
# Check if the terminal supports true color (24-bit)
|
95
|
+
#
|
96
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
97
|
+
# @since 0.1.0
|
98
|
+
#
|
99
|
+
# @api public
|
100
|
+
#
|
101
|
+
# @example Check if the terminal supports true color
|
102
|
+
# Sai.true_color? # => true
|
103
|
+
#
|
104
|
+
# @return [Boolean] `true` if the terminal supports true color (24-bit), otherwise `false`
|
105
|
+
# @rbs () -> bool
|
106
|
+
def true_color?
|
107
|
+
Terminal::Capabilities.detect_color_support >= Terminal::ColorMode::TRUE_COLOR
|
108
|
+
end
|
109
|
+
alias color16m? true_color?
|
110
|
+
alias colour16m? true_color?
|
111
|
+
alias sixteen_million_color? true_color?
|
112
|
+
alias sixteen_million_colour? true_color?
|
113
|
+
alias twenty_for_bit? true_color?
|
111
114
|
end
|
112
|
-
alias bit24? true_color?
|
113
|
-
alias twenty_four_bit? true_color?
|
114
115
|
end
|
115
116
|
end
|
@@ -7,7 +7,7 @@ module Sai
|
|
7
7
|
# Detect the color capabilities of the terminal
|
8
8
|
#
|
9
9
|
# @author {https://aaronmallen.me Aaron Allen}
|
10
|
-
# @since
|
10
|
+
# @since 0.1.0
|
11
11
|
#
|
12
12
|
# @api private
|
13
13
|
module Capabilities
|
@@ -15,7 +15,7 @@ module Sai
|
|
15
15
|
# Detect the color capabilities of the current terminal
|
16
16
|
#
|
17
17
|
# @author {https://aaronmallen.me Aaron Allen}
|
18
|
-
# @since
|
18
|
+
# @since 0.1.0
|
19
19
|
#
|
20
20
|
# @api private
|
21
21
|
#
|
@@ -24,7 +24,7 @@ module Sai
|
|
24
24
|
def detect_color_support
|
25
25
|
return ColorMode::NO_COLOR if no_color?
|
26
26
|
return ColorMode::TRUE_COLOR if true_color?
|
27
|
-
return ColorMode::
|
27
|
+
return ColorMode::ADVANCED if advanced?
|
28
28
|
return ColorMode::ANSI if ansi?
|
29
29
|
return ColorMode::BASIC if basic?
|
30
30
|
|
@@ -33,10 +33,25 @@ module Sai
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
# Check for 256 color (8-bit) support
|
37
|
+
#
|
38
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
39
|
+
# @since 0.1.0
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
#
|
43
|
+
# @return [Boolean] `true` if the terminal supports 256 colors, otherwise `false`
|
44
|
+
# @rbs () -> bool
|
45
|
+
def advanced?
|
46
|
+
return true if ENV.fetch('TERM', '').end_with?('-256color')
|
47
|
+
|
48
|
+
ENV.fetch('COLORTERM', '0').to_i >= 256
|
49
|
+
end
|
50
|
+
|
36
51
|
# Check for ANSI color support
|
37
52
|
#
|
38
53
|
# @author {https://aaronmallen.me Aaron Allen}
|
39
|
-
# @since
|
54
|
+
# @since 0.1.0
|
40
55
|
#
|
41
56
|
# @api private
|
42
57
|
#
|
@@ -51,7 +66,7 @@ module Sai
|
|
51
66
|
# Check for basic color support
|
52
67
|
#
|
53
68
|
# @author {https://aaronmallen.me Aaron Allen}
|
54
|
-
# @since
|
69
|
+
# @since 0.1.0
|
55
70
|
#
|
56
71
|
# @api private
|
57
72
|
#
|
@@ -61,25 +76,10 @@ module Sai
|
|
61
76
|
!ENV.fetch('TERM', '').empty?
|
62
77
|
end
|
63
78
|
|
64
|
-
# Check for 256 color (8-bit) support
|
65
|
-
#
|
66
|
-
# @author {https://aaronmallen.me Aaron Allen}
|
67
|
-
# @since unreleased
|
68
|
-
#
|
69
|
-
# @api private
|
70
|
-
#
|
71
|
-
# @return [Boolean] `true` if the terminal supports 256 colors, otherwise `false`
|
72
|
-
# @rbs () -> bool
|
73
|
-
def bit8?
|
74
|
-
return true if ENV.fetch('TERM', '').end_with?('-256color')
|
75
|
-
|
76
|
-
ENV.fetch('COLORTERM', '0').to_i >= 256
|
77
|
-
end
|
78
|
-
|
79
79
|
# Check for NO_COLOR environment variable
|
80
80
|
#
|
81
81
|
# @author {https://aaronmallen.me Aaron Allen}
|
82
|
-
# @since
|
82
|
+
# @since 0.1.0
|
83
83
|
#
|
84
84
|
# @api private
|
85
85
|
#
|
@@ -94,7 +94,7 @@ module Sai
|
|
94
94
|
# Check for true color (24-bit) support
|
95
95
|
#
|
96
96
|
# @author {https://aaronmallen.me Aaron Allen}
|
97
|
-
# @since
|
97
|
+
# @since 0.1.0
|
98
98
|
#
|
99
99
|
# @api private
|
100
100
|
#
|
@@ -5,14 +5,14 @@ module Sai
|
|
5
5
|
# Represents different color support levels for terminal interfaces
|
6
6
|
#
|
7
7
|
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
-
# @since
|
8
|
+
# @since 0.1.0
|
9
9
|
#
|
10
10
|
# @api private
|
11
11
|
module ColorMode
|
12
12
|
# The terminal does not support color output
|
13
13
|
#
|
14
14
|
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
-
# @since
|
15
|
+
# @since 0.1.0
|
16
16
|
#
|
17
17
|
# @api private
|
18
18
|
#
|
@@ -22,7 +22,7 @@ module Sai
|
|
22
22
|
# The terminal supports 8 colors (3-bit)
|
23
23
|
#
|
24
24
|
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
-
# @since
|
25
|
+
# @since 0.1.0
|
26
26
|
#
|
27
27
|
# @api private
|
28
28
|
#
|
@@ -32,7 +32,7 @@ module Sai
|
|
32
32
|
# The terminal supports 16 colors (4-bit)
|
33
33
|
#
|
34
34
|
# @author {https://aaronmallen.me Aaron Allen}
|
35
|
-
# @since
|
35
|
+
# @since 0.1.0
|
36
36
|
#
|
37
37
|
# @api private
|
38
38
|
#
|
@@ -42,17 +42,17 @@ module Sai
|
|
42
42
|
# The terminal supports 256 colors (8-bit)
|
43
43
|
#
|
44
44
|
# @author {https://aaronmallen.me Aaron Allen}
|
45
|
-
# @since
|
45
|
+
# @since 0.1.0
|
46
46
|
#
|
47
47
|
# @api private
|
48
48
|
#
|
49
49
|
# @return [Integer] the color mode
|
50
|
-
|
50
|
+
ADVANCED = 3 #: Integer
|
51
51
|
|
52
52
|
# The terminal supports 16 million colors (24-bit)
|
53
53
|
#
|
54
54
|
# @author {https://aaronmallen.me Aaron Allen}
|
55
|
-
# @since
|
55
|
+
# @since 0.1.0
|
56
56
|
#
|
57
57
|
# @api private
|
58
58
|
#
|