sai 0.1.0 → 0.3.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/.yardopts +1 -1
- data/CHANGELOG.md +32 -1
- data/README.md +32 -209
- data/docs/USAGE.md +303 -0
- data/lib/sai/ansi/sequence_processor.rb +380 -0
- data/lib/sai/ansi/sequenced_string.rb +475 -0
- 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 +256 -240
- 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 +128 -77
- data/sig/manifest.yaml +3 -0
- data/sig/sai/ansi/sequence_processor.rbs +253 -0
- data/sig/sai/ansi/sequenced_string.rbs +380 -0
- 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 +111 -87
- 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 +109 -66
- metadata +12 -4
data/sig/sai/decorator.rbs
CHANGED
@@ -4,135 +4,134 @@ module Sai
|
|
4
4
|
# A decorator for applying ANSI styles and colors to text
|
5
5
|
#
|
6
6
|
# @author {https://aaronmallen.me Aaron Allen}
|
7
|
-
# @since
|
7
|
+
# @since 0.1.0
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
class Decorator
|
11
11
|
# Initialize a new instance of Decorator
|
12
12
|
#
|
13
13
|
# @author {https://aaronmallen.me Aaron Allen}
|
14
|
-
# @since
|
14
|
+
# @since 0.1.0
|
15
15
|
#
|
16
16
|
# @api private
|
17
17
|
#
|
18
|
-
# @param
|
18
|
+
# @param mode [Integer] the color mode to use
|
19
19
|
#
|
20
20
|
# @return [Decorator] the new instance of Decorator
|
21
|
-
# @rbs (Integer
|
22
|
-
def initialize: (Integer
|
21
|
+
# @rbs (?mode: Integer) -> void
|
22
|
+
def initialize: (?mode: Integer) -> void
|
23
23
|
|
24
|
-
def black: () ->
|
24
|
+
def black: () -> Decorator
|
25
25
|
|
26
|
-
def blue: () ->
|
26
|
+
def blue: () -> Decorator
|
27
27
|
|
28
|
-
def bright_black: () ->
|
28
|
+
def bright_black: () -> Decorator
|
29
29
|
|
30
|
-
def bright_blue: () ->
|
30
|
+
def bright_blue: () -> Decorator
|
31
31
|
|
32
|
-
def bright_cyan: () ->
|
32
|
+
def bright_cyan: () -> Decorator
|
33
33
|
|
34
|
-
def bright_green: () ->
|
34
|
+
def bright_green: () -> Decorator
|
35
35
|
|
36
|
-
def bright_magenta: () ->
|
36
|
+
def bright_magenta: () -> Decorator
|
37
37
|
|
38
|
-
def bright_red: () ->
|
38
|
+
def bright_red: () -> Decorator
|
39
39
|
|
40
|
-
def bright_white: () ->
|
40
|
+
def bright_white: () -> Decorator
|
41
41
|
|
42
|
-
def bright_yellow: () ->
|
42
|
+
def bright_yellow: () -> Decorator
|
43
43
|
|
44
|
-
def cyan: () ->
|
44
|
+
def cyan: () -> Decorator
|
45
45
|
|
46
|
-
def green: () ->
|
46
|
+
def green: () -> Decorator
|
47
47
|
|
48
|
-
def magenta: () ->
|
48
|
+
def magenta: () -> Decorator
|
49
49
|
|
50
|
-
def on_black: () ->
|
50
|
+
def on_black: () -> Decorator
|
51
51
|
|
52
|
-
def on_blue: () ->
|
52
|
+
def on_blue: () -> Decorator
|
53
53
|
|
54
|
-
def on_bright_black: () ->
|
54
|
+
def on_bright_black: () -> Decorator
|
55
55
|
|
56
|
-
def on_bright_blue: () ->
|
56
|
+
def on_bright_blue: () -> Decorator
|
57
57
|
|
58
|
-
def on_bright_cyan: () ->
|
58
|
+
def on_bright_cyan: () -> Decorator
|
59
59
|
|
60
|
-
def on_bright_green: () ->
|
60
|
+
def on_bright_green: () -> Decorator
|
61
61
|
|
62
|
-
def on_bright_magenta: () ->
|
62
|
+
def on_bright_magenta: () -> Decorator
|
63
63
|
|
64
|
-
def on_bright_red: () ->
|
64
|
+
def on_bright_red: () -> Decorator
|
65
65
|
|
66
|
-
def on_bright_white: () ->
|
66
|
+
def on_bright_white: () -> Decorator
|
67
67
|
|
68
|
-
def on_bright_yellow: () ->
|
68
|
+
def on_bright_yellow: () -> Decorator
|
69
69
|
|
70
|
-
def on_cyan: () ->
|
70
|
+
def on_cyan: () -> Decorator
|
71
71
|
|
72
|
-
def on_green: () ->
|
72
|
+
def on_green: () -> Decorator
|
73
73
|
|
74
|
-
def on_magenta: () ->
|
74
|
+
def on_magenta: () -> Decorator
|
75
75
|
|
76
|
-
def on_red: () ->
|
76
|
+
def on_red: () -> Decorator
|
77
77
|
|
78
|
-
def on_white: () ->
|
78
|
+
def on_white: () -> Decorator
|
79
79
|
|
80
|
-
def on_yellow: () ->
|
80
|
+
def on_yellow: () -> Decorator
|
81
81
|
|
82
|
-
def red: () ->
|
82
|
+
def red: () -> Decorator
|
83
83
|
|
84
|
-
def white: () ->
|
84
|
+
def white: () -> Decorator
|
85
85
|
|
86
|
-
def yellow: () ->
|
86
|
+
def yellow: () -> Decorator
|
87
87
|
|
88
|
-
def blink: () ->
|
88
|
+
def blink: () -> Decorator
|
89
89
|
|
90
|
-
def bold: () ->
|
90
|
+
def bold: () -> Decorator
|
91
91
|
|
92
|
-
def conceal: () ->
|
92
|
+
def conceal: () -> Decorator
|
93
93
|
|
94
|
-
def dim: () ->
|
94
|
+
def dim: () -> Decorator
|
95
95
|
|
96
|
-
def italic: () ->
|
96
|
+
def italic: () -> Decorator
|
97
97
|
|
98
|
-
def no_blink: () ->
|
98
|
+
def no_blink: () -> Decorator
|
99
99
|
|
100
|
-
def no_conceal: () ->
|
100
|
+
def no_conceal: () -> Decorator
|
101
101
|
|
102
|
-
def no_italic: () ->
|
102
|
+
def no_italic: () -> Decorator
|
103
103
|
|
104
|
-
def no_reverse: () ->
|
104
|
+
def no_reverse: () -> Decorator
|
105
105
|
|
106
|
-
def no_strike: () ->
|
106
|
+
def no_strike: () -> Decorator
|
107
107
|
|
108
|
-
def no_underline: () ->
|
108
|
+
def no_underline: () -> Decorator
|
109
109
|
|
110
|
-
def normal_intensity: () ->
|
110
|
+
def normal_intensity: () -> Decorator
|
111
111
|
|
112
|
-
def rapid_blink: () ->
|
112
|
+
def rapid_blink: () -> Decorator
|
113
113
|
|
114
|
-
def reverse: () ->
|
114
|
+
def reverse: () -> Decorator
|
115
115
|
|
116
|
-
def strike: () ->
|
116
|
+
def strike: () -> Decorator
|
117
117
|
|
118
|
-
def underline: () ->
|
118
|
+
def underline: () -> Decorator
|
119
119
|
|
120
120
|
# Apply the styles and colors to the text
|
121
121
|
#
|
122
122
|
# @author {https://aaronmallen.me Aaron Allen}
|
123
|
-
# @since
|
123
|
+
# @since 0.1.0
|
124
124
|
#
|
125
125
|
# @api public
|
126
126
|
#
|
127
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"
|
128
|
+
# decorator.red.on_blue.bold.decorate('Hello, world!').to_s #=> "\e[38;5;160;48;5;21;1mHello, world!\e[0m"
|
130
129
|
#
|
131
130
|
# @param text [String] the text to decorate
|
132
131
|
#
|
133
|
-
# @return [
|
134
|
-
# @rbs (String text) ->
|
135
|
-
def decorate: (String text) ->
|
132
|
+
# @return [ANSI::SequencedString] the decorated text
|
133
|
+
# @rbs (String text) -> ANSI::SequencedString
|
134
|
+
def decorate: (String text) -> ANSI::SequencedString
|
136
135
|
|
137
136
|
alias apply decorate
|
138
137
|
|
@@ -143,104 +142,129 @@ module Sai
|
|
143
142
|
# Apply a hexadecimal color to the foreground
|
144
143
|
#
|
145
144
|
# @author {https://aaronmallen.me Aaron Allen}
|
146
|
-
# @since
|
145
|
+
# @since 0.1.0
|
147
146
|
#
|
148
147
|
# @api public
|
149
148
|
#
|
150
149
|
# @example
|
151
|
-
# decorator.hex("#EB4133").decorate('Hello, world!') #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
150
|
+
# decorator.hex("#EB4133").decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
152
151
|
#
|
153
152
|
# @param code [String] the hex color code
|
154
153
|
#
|
155
154
|
# @raise [ArgumentError] if the hex code is invalid
|
156
|
-
# @return [
|
157
|
-
# @rbs (String code) ->
|
158
|
-
def hex: (String code) ->
|
155
|
+
# @return [Decorator] a new instance of Decorator with the hex color applied
|
156
|
+
# @rbs (String code) -> Decorator
|
157
|
+
def hex: (String code) -> Decorator
|
159
158
|
|
160
159
|
# Apply a hexadecimal color to the background
|
161
160
|
#
|
162
161
|
# @author {https://aaronmallen.me Aaron Allen}
|
163
|
-
# @since
|
162
|
+
# @since 0.1.0
|
164
163
|
#
|
165
164
|
# @api public
|
166
165
|
#
|
167
166
|
# @example
|
168
|
-
# decorator.on_hex("#EB4133").decorate('Hello, world!') #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
167
|
+
# decorator.on_hex("#EB4133").decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
169
168
|
#
|
170
169
|
# @param code [String] the hex color code
|
171
170
|
#
|
172
171
|
# @raise [ArgumentError] if the hex code is invalid
|
173
|
-
# @return [
|
174
|
-
# @rbs (String code) ->
|
175
|
-
def on_hex: (String code) ->
|
172
|
+
# @return [Decorator] a new instance of Decorator with the hex color applied
|
173
|
+
# @rbs (String code) -> Decorator
|
174
|
+
def on_hex: (String code) -> Decorator
|
176
175
|
|
177
176
|
# Apply an RGB color to the background
|
178
177
|
#
|
179
178
|
# @author {https://aaronmallen.me Aaron Allen}
|
180
|
-
# @since
|
179
|
+
# @since 0.1.0
|
181
180
|
#
|
182
181
|
# @api public
|
183
182
|
#
|
184
183
|
# @example
|
185
|
-
# decorator.on_rgb(235, 65, 51).decorate('Hello, world!') #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
184
|
+
# decorator.on_rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[48;2;235;65;51mHello, world!\e[0m"
|
186
185
|
#
|
187
186
|
# @param red [Integer] the red component
|
188
187
|
# @param green [Integer] the green component
|
189
188
|
# @param blue [Integer] the blue component
|
190
189
|
#
|
191
190
|
# @raise [ArgumentError] if the RGB values are out of range
|
192
|
-
# @return [
|
193
|
-
# @rbs (Integer red, Integer green, Integer blue) ->
|
194
|
-
def on_rgb: (Integer red, Integer green, Integer blue) ->
|
191
|
+
# @return [Decorator] a new instance of Decorator with the RGB color applied
|
192
|
+
# @rbs (Integer red, Integer green, Integer blue) -> Decorator
|
193
|
+
def on_rgb: (Integer red, Integer green, Integer blue) -> Decorator
|
195
194
|
|
196
195
|
# Apply an RGB color to the foreground
|
197
196
|
#
|
198
197
|
# @author {https://aaronmallen.me Aaron Allen}
|
199
|
-
# @since
|
198
|
+
# @since 0.1.0
|
200
199
|
#
|
201
200
|
# @api public
|
202
201
|
#
|
203
202
|
# @example
|
204
|
-
# decorator.rgb(235, 65, 51).decorate('Hello, world!') #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
203
|
+
# decorator.rgb(235, 65, 51).decorate('Hello, world!').to_s #=> "\e[38;2;235;65;51mHello, world!\e[0m"
|
205
204
|
#
|
206
205
|
# @param red [Integer] the red component
|
207
206
|
# @param green [Integer] the green component
|
208
207
|
# @param blue [Integer] the blue component
|
209
208
|
#
|
210
209
|
# @raise [ArgumentError] if the RGB values are out of range
|
211
|
-
# @return [
|
212
|
-
# @rbs (Integer red, Integer green, Integer blue) ->
|
213
|
-
def rgb: (Integer red, Integer green, Integer blue) ->
|
210
|
+
# @return [Decorator] a new instance of Decorator with the RGB color applied
|
211
|
+
# @rbs (Integer red, Integer green, Integer blue) -> Decorator
|
212
|
+
def rgb: (Integer red, Integer green, Integer blue) -> Decorator
|
213
|
+
|
214
|
+
# Apply a specific color mode to the decorator
|
215
|
+
#
|
216
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
217
|
+
# @since 0.2.0
|
218
|
+
#
|
219
|
+
# @api public
|
220
|
+
#
|
221
|
+
# @example
|
222
|
+
# decorator.with_mode(Sai.mode.basic_auto) #=> => #<Sai::Decorator:0x123 @mode=1>
|
223
|
+
#
|
224
|
+
# @param mode [Integer] the color mode to use
|
225
|
+
#
|
226
|
+
# @return [Decorator] a new instance of Decorator with the applied color mode
|
227
|
+
# @rbs (Integer mode) -> Decorator
|
228
|
+
def with_mode: (Integer mode) -> Decorator
|
214
229
|
|
215
230
|
private
|
216
231
|
|
217
232
|
# Apply a named color to the specified style type
|
218
233
|
#
|
219
234
|
# @author {https://aaronmallen.me Aaron Allen}
|
220
|
-
# @since
|
235
|
+
# @since 0.1.0
|
221
236
|
#
|
222
237
|
# @api private
|
223
238
|
#
|
224
239
|
# @param style_type [Symbol] the style type to apply the color to
|
225
240
|
# @param color [Symbol] the color to apply
|
226
241
|
#
|
227
|
-
# @
|
228
|
-
# @
|
229
|
-
|
230
|
-
def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> self
|
242
|
+
# @return [Decorator] a new instance of Decorator with the color applied
|
243
|
+
# @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
|
244
|
+
def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
|
231
245
|
|
232
246
|
# Apply a style to the text
|
233
247
|
#
|
234
248
|
# @author {https://aaronmallen.me Aaron Allen}
|
235
|
-
# @since
|
249
|
+
# @since 0.1.0
|
236
250
|
#
|
237
251
|
# @api private
|
238
252
|
#
|
239
253
|
# @param style [String, Symbol] the style to apply
|
240
254
|
#
|
241
|
-
# @
|
242
|
-
# @return [self] the instance of Decorator for chaining
|
255
|
+
# @return [Decorator] a new instance of Decorator with the style applied
|
243
256
|
# @rbs (String | Symbol style) -> self
|
244
257
|
def apply_style: (String | Symbol style) -> self
|
258
|
+
|
259
|
+
# Check if text should be decorated
|
260
|
+
#
|
261
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
262
|
+
# @since 0.2.0
|
263
|
+
#
|
264
|
+
# @api private
|
265
|
+
#
|
266
|
+
# @return [Boolean] `true` if text should be decorated, `false` otherwise
|
267
|
+
# @rbs () -> bool
|
268
|
+
def should_decorate?: () -> bool
|
245
269
|
end
|
246
270
|
end
|
@@ -0,0 +1,319 @@
|
|
1
|
+
# Generated from lib/sai/mode_selector.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
# Color mode selection methods
|
5
|
+
#
|
6
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
7
|
+
# @since 0.2.0
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
module ModeSelector
|
11
|
+
# Set the color mode to 256 color (8-bit) mode
|
12
|
+
#
|
13
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
14
|
+
# @since 0.2.0
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Sai.mode.advanced #=> 3
|
20
|
+
# Sai.mode.eight_bit #=> 3
|
21
|
+
# Sai.mode.color256 #=> 3
|
22
|
+
#
|
23
|
+
# @return [Integer] the color mode
|
24
|
+
# @rbs () -> Integer
|
25
|
+
def self.advanced: () -> Integer
|
26
|
+
|
27
|
+
alias self.color256 self.advanced
|
28
|
+
|
29
|
+
alias self.colour256 self.advanced
|
30
|
+
|
31
|
+
alias self.eight_bit self.advanced
|
32
|
+
|
33
|
+
alias self.two_hundred_fifty_six_color self.advanced
|
34
|
+
|
35
|
+
alias self.two_hundred_fifty_six_colour self.advanced
|
36
|
+
|
37
|
+
# Automatically set the color mode to advanced (8-bit) or lower
|
38
|
+
#
|
39
|
+
# Sets the terminal color mode to advanced (8-bit) support, which provides 256 colors
|
40
|
+
# The mode will automatically downgrade to 4-bit, 3-bit, or NO_COLOR if the terminal doesn't support
|
41
|
+
# advanced colors
|
42
|
+
#
|
43
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
44
|
+
# @since 0.2.0
|
45
|
+
#
|
46
|
+
# @api public
|
47
|
+
#
|
48
|
+
# @example With color support enabled
|
49
|
+
# ENV['COLORTERM'] #=> nil
|
50
|
+
# ENV['TERM'] #=> 'xterm-256color'
|
51
|
+
# Sai.mode.advanced_auto #=> 3
|
52
|
+
# Sai.mode.eight_bit_auto #=> 3
|
53
|
+
# Sai.mode.color256_auto #=> 3
|
54
|
+
#
|
55
|
+
# @example With only 4-bit color support
|
56
|
+
# ENV['NO_COLOR'] #=> nil
|
57
|
+
# ENV['TERM'] #=> 'ansi'
|
58
|
+
# Sai.mode.advanced_auto #=> 2
|
59
|
+
# Sai.mode.eight_bit_auto #=> 2
|
60
|
+
# Sai.mode.color256_auto #=> 2
|
61
|
+
#
|
62
|
+
# @example With only 3-bit color support
|
63
|
+
# ENV['TERM'] #=> nil
|
64
|
+
# ENV['NO_COLOR'] #=> nil
|
65
|
+
# Sai.mode.advanced_auto #=> 1
|
66
|
+
# Sai.mode.eight_bit_auto #=> 1
|
67
|
+
# Sai.mode.color256_auto #=> 1
|
68
|
+
#
|
69
|
+
# @example With color support disabled
|
70
|
+
# ENV['NO_COLOR'] #=> 'true'
|
71
|
+
# Sai.mode.advanced_auto #=> 0
|
72
|
+
# Sai.mode.eight_bit_auto #=> 0
|
73
|
+
# Sai.mode.color256_auto #=> 0
|
74
|
+
#
|
75
|
+
# @return [Integer] the color mode
|
76
|
+
# @rbs () -> Integer
|
77
|
+
def self.advanced_auto: () -> Integer
|
78
|
+
|
79
|
+
alias self.color256_auto self.advanced_auto
|
80
|
+
|
81
|
+
alias self.colour256_auto self.advanced_auto
|
82
|
+
|
83
|
+
alias self.eight_bit_auto self.advanced_auto
|
84
|
+
|
85
|
+
alias self.two_hundred_fifty_six_color_auto self.advanced_auto
|
86
|
+
|
87
|
+
alias self.two_hundred_fifty_six_colour_auto self.advanced_auto
|
88
|
+
|
89
|
+
# Set the color mode to 16 color (4-bit) mode
|
90
|
+
#
|
91
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
92
|
+
# @since 0.2.0
|
93
|
+
#
|
94
|
+
# @api public
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# Sai.mode.ansi #=> 2
|
98
|
+
# Sai.mode.color16 #=> 2
|
99
|
+
# Sai.mode.four_bit #=> 2
|
100
|
+
#
|
101
|
+
# @return [Integer] the color mode
|
102
|
+
# @rbs () -> Integer
|
103
|
+
def self.ansi: () -> Integer
|
104
|
+
|
105
|
+
alias self.color16 self.ansi
|
106
|
+
|
107
|
+
alias self.colour16 self.ansi
|
108
|
+
|
109
|
+
alias self.four_bit self.ansi
|
110
|
+
|
111
|
+
alias self.sixteen_color self.ansi
|
112
|
+
|
113
|
+
alias self.sixteen_colour self.ansi
|
114
|
+
|
115
|
+
# Automatically set the color mode to ansi (4-bit) or lower
|
116
|
+
#
|
117
|
+
# Sets the terminal color mode to ansi (4-bit) support, which provides 8 colors
|
118
|
+
# The mode will automatically downgrade to 3-bit or NO_COLOR if the terminal doesn't support
|
119
|
+
# ansi colors
|
120
|
+
#
|
121
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
122
|
+
# @since 0.2.0
|
123
|
+
#
|
124
|
+
# @api public
|
125
|
+
#
|
126
|
+
# @example With color support enabled
|
127
|
+
# ENV['NO_COLOR'] #=> nil
|
128
|
+
# ENV['TERM'] #=> 'ansi'
|
129
|
+
# Sai.mode.ansi_auto #=> 2
|
130
|
+
# Sai.mode.four_bit_auto #=> 2
|
131
|
+
# Sai.mode.color16_auto #=> 2
|
132
|
+
#
|
133
|
+
# @example With only 3-bit color support
|
134
|
+
# ENV['TERM'] #=> nil
|
135
|
+
# ENV['NO_COLOR'] #=> nil
|
136
|
+
# Sai.mode.ansi_auto #=> 1
|
137
|
+
# Sai.mode.four_bit_auto #=> 1
|
138
|
+
# Sai.mode.color16_auto #=> 1
|
139
|
+
#
|
140
|
+
# @example With color support disabled
|
141
|
+
# ENV['NO_COLOR'] #=> 'true'
|
142
|
+
# Sai.mode.ansi_auto #=> 0
|
143
|
+
# Sai.mode.four_bit_auto #=> 0
|
144
|
+
# Sai.mode.color16_auto #=> 0
|
145
|
+
#
|
146
|
+
# @return [Integer] the color mode
|
147
|
+
# @rbs () -> Integer
|
148
|
+
def self.ansi_auto: () -> Integer
|
149
|
+
|
150
|
+
alias self.color16_auto self.ansi_auto
|
151
|
+
|
152
|
+
alias self.colour16_auto self.ansi_auto
|
153
|
+
|
154
|
+
alias self.four_bit_auto self.ansi_auto
|
155
|
+
|
156
|
+
alias self.sixteen_color_auto self.ansi_auto
|
157
|
+
|
158
|
+
alias self.sixteen_colour_auto self.ansi_auto
|
159
|
+
|
160
|
+
# Set the color mode based on the current Terminal's capabilities
|
161
|
+
#
|
162
|
+
# This is the default color mode for {Sai}
|
163
|
+
#
|
164
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
165
|
+
# @since 0.2.0
|
166
|
+
#
|
167
|
+
# @api public
|
168
|
+
#
|
169
|
+
# @example With 24-bit color support enabled
|
170
|
+
# ENV['COLORTERM'] #=> 'truecolor'
|
171
|
+
# Sai.node.auto #=> 4
|
172
|
+
#
|
173
|
+
# @example With only 8-bit color support enabled
|
174
|
+
# ENV['COLORTERM'] #=> nil
|
175
|
+
# ENV['TERM'] #=> 'xterm-256color'
|
176
|
+
# Sai.mode.auto #=> 3
|
177
|
+
#
|
178
|
+
# @example With only 4-bit color support
|
179
|
+
# ENV['NO_COLOR'] #=> nil
|
180
|
+
# ENV['TERM'] #=> 'ansi'
|
181
|
+
# Sai.mode.auto #=> 2
|
182
|
+
#
|
183
|
+
# @example With only 3-bit color support
|
184
|
+
# ENV['TERM'] #=> nil
|
185
|
+
# ENV['NO_COLOR'] #=> nil
|
186
|
+
# Sai.mode.auto #=> 1
|
187
|
+
#
|
188
|
+
# @example With color support disabled
|
189
|
+
# ENV['NO_COLOR'] #=> 'true'
|
190
|
+
# Sai.mode.auto #=> 0
|
191
|
+
#
|
192
|
+
# @return [Integer] the color mode
|
193
|
+
# @rbs () -> Integer
|
194
|
+
def self.auto: () -> Integer
|
195
|
+
|
196
|
+
alias self.color16m_auto self.auto
|
197
|
+
|
198
|
+
alias self.colour16m_auto self.auto
|
199
|
+
|
200
|
+
alias self.enabled self.auto
|
201
|
+
|
202
|
+
alias self.sixteen_million_color_auto self.auto
|
203
|
+
|
204
|
+
alias self.sixteen_million_colour_auto self.auto
|
205
|
+
|
206
|
+
alias self.twenty_for_bit_auto self.auto
|
207
|
+
|
208
|
+
# Set the color mode to 8 color (3-bit) mode
|
209
|
+
#
|
210
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
211
|
+
# @since 0.2.0
|
212
|
+
#
|
213
|
+
# @api public
|
214
|
+
#
|
215
|
+
# @example
|
216
|
+
# Sai.mode.basic #=> 1
|
217
|
+
# Sai.mode.color8 #=> 1
|
218
|
+
# Sai.mode.three_bit #=> 1
|
219
|
+
#
|
220
|
+
# @return [Integer] the 4 color (3-bit) mode
|
221
|
+
# @rbs () -> Integer
|
222
|
+
def self.basic: () -> Integer
|
223
|
+
|
224
|
+
alias self.color8 self.basic
|
225
|
+
|
226
|
+
alias self.colour8 self.basic
|
227
|
+
|
228
|
+
alias self.eight_color self.basic
|
229
|
+
|
230
|
+
alias self.eight_colour self.basic
|
231
|
+
|
232
|
+
alias self.three_bit self.basic
|
233
|
+
|
234
|
+
# Automatically set the color mode to basic (3-bit) or lower
|
235
|
+
#
|
236
|
+
# Sets the terminal color mode to basic (3-bit) support, which provides 8 colors
|
237
|
+
# The mode will automatically downgrade to NO_COLOR if the terminal doesn't support
|
238
|
+
# basic colors
|
239
|
+
#
|
240
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
241
|
+
# @since 0.2.0
|
242
|
+
#
|
243
|
+
# @api public
|
244
|
+
#
|
245
|
+
# @example With color support enabled
|
246
|
+
# ENV['NO_COLOR'] #=> nil
|
247
|
+
# Sai.mode.basic_auto #=> 1
|
248
|
+
# Sai.mode.three_bit_auto #=> 1
|
249
|
+
# Sai.mode.color8_auto #=> 1
|
250
|
+
#
|
251
|
+
# @example With color support disabled
|
252
|
+
# ENV['NO_COLOR'] #=> 'true'
|
253
|
+
# Sai.mode.basic_auto #=> 0
|
254
|
+
# Sai.mode.three_bit_auto #=> 0
|
255
|
+
# Sai.mode.color8_auto #=> 0
|
256
|
+
#
|
257
|
+
# @return [Integer] the color mode
|
258
|
+
# @rbs () -> Integer
|
259
|
+
def self.basic_auto: () -> Integer
|
260
|
+
|
261
|
+
alias self.color8_auto self.basic_auto
|
262
|
+
|
263
|
+
alias self.colour8_auto self.basic_auto
|
264
|
+
|
265
|
+
alias self.eight_color_auto self.basic_auto
|
266
|
+
|
267
|
+
alias self.eight_colour_auto self.basic_auto
|
268
|
+
|
269
|
+
alias self.three_bit_auto self.basic_auto
|
270
|
+
|
271
|
+
# Set the color mode to disable all color and styling
|
272
|
+
#
|
273
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
274
|
+
# @since 0.2.0
|
275
|
+
#
|
276
|
+
# @api public
|
277
|
+
#
|
278
|
+
# @example
|
279
|
+
# Sai.mode.no_color #=> 0
|
280
|
+
# Sai.mode.disabled #=> 0
|
281
|
+
# Sai.mode.mono #=> 0
|
282
|
+
#
|
283
|
+
# @return [Integer] the color mode
|
284
|
+
# @rbs () -> Integer
|
285
|
+
def self.no_color: () -> Integer
|
286
|
+
|
287
|
+
alias self.disabled self.no_color
|
288
|
+
|
289
|
+
alias self.mono self.no_color
|
290
|
+
|
291
|
+
alias self.no_colour self.no_color
|
292
|
+
|
293
|
+
# Set the color mode to 16-million color (24-bit) mode
|
294
|
+
#
|
295
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
296
|
+
# @since 0.2.0
|
297
|
+
#
|
298
|
+
# @api public
|
299
|
+
#
|
300
|
+
# @example
|
301
|
+
# Sai.mode.true_color #=> 4
|
302
|
+
# Sai.mode.twenty_four_bit #=> 4
|
303
|
+
# Sai.mode.color_16m #=> 4
|
304
|
+
#
|
305
|
+
# @return [Integer] the color mode
|
306
|
+
# @rbs () -> Integer
|
307
|
+
def self.true_color: () -> Integer
|
308
|
+
|
309
|
+
alias self.color16m self.true_color
|
310
|
+
|
311
|
+
alias self.colour16m self.true_color
|
312
|
+
|
313
|
+
alias self.sixteen_million_color self.true_color
|
314
|
+
|
315
|
+
alias self.sixteen_million_colour self.true_color
|
316
|
+
|
317
|
+
alias self.twenty_for_bit self.true_color
|
318
|
+
end
|
319
|
+
end
|