sai 0.2.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 +17 -1
- data/README.md +32 -242
- 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/decorator.rb +58 -72
- data/lib/sai/mode_selector.rb +19 -19
- data/lib/sai.rb +22 -0
- 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/decorator.rbs +8 -11
- data/sig/sai/mode_selector.rbs +19 -19
- data/sig/sai.rbs +17 -0
- metadata +9 -3
@@ -0,0 +1,253 @@
|
|
1
|
+
# Generated from lib/sai/ansi/sequence_processor.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module ANSI
|
5
|
+
# Extract ANSI sequence information from a string
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since 0.3.0
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
class SequenceProcessor
|
12
|
+
# The pattern to extract ANSI sequences from a string
|
13
|
+
#
|
14
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
+
# @since 0.3.0
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @return [Regexp] the pattern
|
20
|
+
SEQUENCE_PATTERN: Regexp
|
21
|
+
|
22
|
+
# Matches the code portion of style sequences
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.3.0
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @return [Regexp] the pattern
|
30
|
+
STYLE_CODE_PATTERN: Regexp
|
31
|
+
|
32
|
+
# Initialize a new instance of SequenceProcessor and parse the provided string
|
33
|
+
#
|
34
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
35
|
+
# @since 0.3.0
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
#
|
39
|
+
# @param string [String] the string to parse
|
40
|
+
#
|
41
|
+
# @return [Array<Hash{Symbol => Object}>] the segments
|
42
|
+
# @rbs (String string) -> Array[Hash[Symbol, untyped]]
|
43
|
+
def self.process: (String string) -> Array[Hash[Symbol, untyped]]
|
44
|
+
|
45
|
+
# Initialize a new instance of SequenceProcessor
|
46
|
+
#
|
47
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
48
|
+
# @since 0.3.0
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
#
|
52
|
+
# @param string [String] the string to parse
|
53
|
+
#
|
54
|
+
# @return [SequenceProcessor] the new instance of SequenceProcessor
|
55
|
+
# @rbs (String string) -> void
|
56
|
+
def initialize: (String string) -> void
|
57
|
+
|
58
|
+
# Parse a string and return a hash of segments
|
59
|
+
#
|
60
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
61
|
+
# @since 0.3.0
|
62
|
+
#
|
63
|
+
# @api private
|
64
|
+
#
|
65
|
+
# @return [Array<Hash{Symbol => Object}>] the segments
|
66
|
+
# @rbs () -> Array[Hash[Symbol, untyped]]
|
67
|
+
def process: () -> Array[Hash[Symbol, untyped]]
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# Applies 24-bit truecolor (e.g., 38;2;R;G;B or 48;2;R;G;B)
|
72
|
+
#
|
73
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
74
|
+
# @since 0.3.0
|
75
|
+
#
|
76
|
+
# @api private
|
77
|
+
#
|
78
|
+
# @param codes_array [Array<Integer>]
|
79
|
+
# @param index [Integer]
|
80
|
+
#
|
81
|
+
# @return [Integer] the updated index (consumed 5 codes)
|
82
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
83
|
+
def apply_24bit_color: (Array[Integer] codes_array, Integer index) -> Integer
|
84
|
+
|
85
|
+
# Applies 256-color mode (e.g., 38;5;160 or 48;5;21)
|
86
|
+
#
|
87
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
88
|
+
# @since 0.3.0
|
89
|
+
#
|
90
|
+
# @api private
|
91
|
+
#
|
92
|
+
# @param codes_array [Array<Integer>]
|
93
|
+
# @param index [Integer]
|
94
|
+
#
|
95
|
+
# @return [Integer] the updated index (consumed 3 codes)
|
96
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
97
|
+
def apply_256_color: (Array[Integer] codes_array, Integer index) -> Integer
|
98
|
+
|
99
|
+
# Applies the appropriate action for the provided ANSI sequence
|
100
|
+
#
|
101
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
102
|
+
# @since 0.3.0
|
103
|
+
#
|
104
|
+
# @api private
|
105
|
+
#
|
106
|
+
# @param sequence [String] an ANSI sequence (e.g. "\e[31m", "\e[0m")
|
107
|
+
#
|
108
|
+
# @return [void]
|
109
|
+
# @rbs (String sequence) -> void
|
110
|
+
def apply_ansi_sequence: (String sequence) -> void
|
111
|
+
|
112
|
+
# Applies a basic color (FG or BG) in the range 30..37 (FG) or 40..47 (BG)
|
113
|
+
#
|
114
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
115
|
+
# @since 0.3.0
|
116
|
+
#
|
117
|
+
# @api private
|
118
|
+
#
|
119
|
+
# @param code [Integer] the numeric color code
|
120
|
+
#
|
121
|
+
# @return [void]
|
122
|
+
# @rbs (Integer code) -> void
|
123
|
+
def apply_basic_color: (Integer code) -> void
|
124
|
+
|
125
|
+
# Parse all numeric codes in the provided string, applying them in order (just like a real ANSI terminal)
|
126
|
+
#
|
127
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
128
|
+
# @since 0.3.0
|
129
|
+
#
|
130
|
+
# @api private
|
131
|
+
#
|
132
|
+
# @param codes_string [String] e.g. "38;5;160;48;5;21;1"
|
133
|
+
#
|
134
|
+
# @return [void]
|
135
|
+
# @rbs (String codes_string) -> void
|
136
|
+
def apply_codes: (String codes_string) -> void
|
137
|
+
|
138
|
+
# Applies a single code (or group) from the array. This might be:
|
139
|
+
# - 0 => reset
|
140
|
+
# - 30..37 => basic FG color
|
141
|
+
# - 40..47 => basic BG color
|
142
|
+
# - 38 or 48 => extended color sequence
|
143
|
+
# - otherwise => style code (bold, underline, etc.)
|
144
|
+
#
|
145
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
146
|
+
# @since 0.3.0
|
147
|
+
#
|
148
|
+
# @api private
|
149
|
+
#
|
150
|
+
# @param codes_array [Array<Integer>] the list of numeric codes
|
151
|
+
# @param index [Integer] the current index
|
152
|
+
#
|
153
|
+
# @return [Integer] the updated index after consuming needed codes
|
154
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
155
|
+
def apply_single_code: (Array[Integer] codes_array, Integer index) -> Integer
|
156
|
+
|
157
|
+
# Applies a single style code (e.g. 1=bold, 2=dim, 4=underline, etc.) if it matches
|
158
|
+
#
|
159
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
160
|
+
# @since 0.3.0
|
161
|
+
#
|
162
|
+
# @api private
|
163
|
+
#
|
164
|
+
# @param code [Integer] the numeric code to check
|
165
|
+
#
|
166
|
+
# @return [void]
|
167
|
+
# @rbs (Integer code) -> void
|
168
|
+
def apply_style_code: (Integer code) -> void
|
169
|
+
|
170
|
+
# Creates and returns a fresh, blank segment
|
171
|
+
#
|
172
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
173
|
+
# @since 0.3.0
|
174
|
+
#
|
175
|
+
# @api private
|
176
|
+
#
|
177
|
+
# @return [Hash{Symbol => Object}] a new, empty segment
|
178
|
+
# @rbs () -> Hash[Symbol, untyped]
|
179
|
+
def blank_segment: () -> Hash[Symbol, untyped]
|
180
|
+
|
181
|
+
# Scans the string for ANSI sequences or individual characters
|
182
|
+
#
|
183
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
184
|
+
# @since 0.3.0
|
185
|
+
#
|
186
|
+
# @api private
|
187
|
+
#
|
188
|
+
# @return [void]
|
189
|
+
# @rbs () -> void
|
190
|
+
def consume_tokens: () -> void
|
191
|
+
|
192
|
+
# Finalizes the current segment if any text is present, then resets it
|
193
|
+
#
|
194
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
195
|
+
# @since 0.3.0
|
196
|
+
#
|
197
|
+
# @api private
|
198
|
+
#
|
199
|
+
# @return [void]
|
200
|
+
# @rbs () -> void
|
201
|
+
def finalize_segment_if_text!: () -> void
|
202
|
+
|
203
|
+
# Attempts to capture an ANSI sequence from the scanner If found, finalizes
|
204
|
+
# the current text segment and applies the sequence
|
205
|
+
#
|
206
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
207
|
+
# @since 0.3.0
|
208
|
+
#
|
209
|
+
# @api private
|
210
|
+
#
|
211
|
+
# @return [Boolean] `true` if a sequence was found, `false` if otherwise
|
212
|
+
# @rbs () -> bool
|
213
|
+
def handle_ansi_sequence: () -> bool
|
214
|
+
|
215
|
+
# Reads a single character from the scanner and appends it to the current segment
|
216
|
+
#
|
217
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
218
|
+
# @since 0.3.0
|
219
|
+
#
|
220
|
+
# @api private
|
221
|
+
#
|
222
|
+
# @return [void]
|
223
|
+
# @rbs () -> void
|
224
|
+
def handle_character: () -> void
|
225
|
+
|
226
|
+
# Parse extended color codes from the array, e.g. 38;5;160 (256-color) or 38;2;R;G;B (24-bit),
|
227
|
+
# and apply them to foreground or background
|
228
|
+
#
|
229
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
230
|
+
# @since 0.3.0
|
231
|
+
#
|
232
|
+
# @api private
|
233
|
+
#
|
234
|
+
# @param codes_array [Array<Integer>] the array of codes
|
235
|
+
# @param index [Integer] the current position (where we saw 38 or 48)
|
236
|
+
#
|
237
|
+
# @return [Integer] the updated position in the codes array
|
238
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
239
|
+
def parse_extended_color: (Array[Integer] codes_array, Integer index) -> Integer
|
240
|
+
|
241
|
+
# Resets the current segment to a fresh, blank state
|
242
|
+
#
|
243
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
244
|
+
# @since 0.3.0
|
245
|
+
#
|
246
|
+
# @api private
|
247
|
+
#
|
248
|
+
# @return [void]
|
249
|
+
# @rbs () -> void
|
250
|
+
def reset_segment!: () -> void
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,380 @@
|
|
1
|
+
# Generated from lib/sai/ansi/sequenced_string.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module ANSI
|
5
|
+
# A representation of a ANSI encoded string and its individual {SequencedString::Segment segments}
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since 0.3.0
|
9
|
+
#
|
10
|
+
# @api public
|
11
|
+
class SequencedString
|
12
|
+
include Enumerable[Segment]
|
13
|
+
|
14
|
+
def each: () { (Segment) -> void } -> SequencedString
|
15
|
+
|
16
|
+
def empty?: () -> bool
|
17
|
+
|
18
|
+
def map: () { (Segment) -> untyped } -> Array[untyped]
|
19
|
+
|
20
|
+
def size: () -> Integer
|
21
|
+
|
22
|
+
# Initialize a new instance of SequencedString
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.3.0
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @param string [String] the sequenced string to Segment
|
30
|
+
#
|
31
|
+
# @return [SequencedString] the new instance of SequencedString
|
32
|
+
# @rbs (String string) -> void
|
33
|
+
def initialize: (String string) -> void
|
34
|
+
|
35
|
+
# Fetch a segment by index
|
36
|
+
#
|
37
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
38
|
+
# @since 0.3.0
|
39
|
+
#
|
40
|
+
# @api public
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# string = SequencedString.new("\e[31mred\e[0m")
|
44
|
+
# string[0] #=> #<SequencedString::Segment:0x00007f9b3b8b3e10>
|
45
|
+
#
|
46
|
+
# @param index [Integer] the index of the segment to fetch
|
47
|
+
#
|
48
|
+
# @return [Segment, nil] the segment at the index
|
49
|
+
# @rbs (Integer index) -> Segment?
|
50
|
+
def []: (Integer index) -> Segment?
|
51
|
+
|
52
|
+
# Compare the SequencedString to another object
|
53
|
+
#
|
54
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
55
|
+
# @since 0.3.0
|
56
|
+
#
|
57
|
+
# @api public
|
58
|
+
#
|
59
|
+
# @example
|
60
|
+
# string = "\e[31mred\e[0m"
|
61
|
+
# SequencedString.new(string) == string #=> true
|
62
|
+
#
|
63
|
+
# @param other [Object] the object to compare to
|
64
|
+
#
|
65
|
+
# @return [Boolean] `true` if the SequencedString is equal to the other object, `false` otherwise
|
66
|
+
# @rbs (untyped other) -> bool
|
67
|
+
def ==: (untyped other) -> bool
|
68
|
+
|
69
|
+
# Combine a sequenced string with another object
|
70
|
+
#
|
71
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
72
|
+
# @since 0.3.0
|
73
|
+
#
|
74
|
+
# @api public
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# sequenced_string = SequencedString.new("\e[31mred\e[0m")
|
78
|
+
# sequenced_string + " is a color" #=> "\e[31mred\e[0m is a color"
|
79
|
+
#
|
80
|
+
# @param other [Object] the object to combine with
|
81
|
+
#
|
82
|
+
# @return [SequencedString] the combined string
|
83
|
+
# @rbs (untyped other) -> SequencedString
|
84
|
+
def +: (untyped other) -> SequencedString
|
85
|
+
|
86
|
+
# Return just the raw text content with **no ANSI sequences**
|
87
|
+
#
|
88
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
89
|
+
# @since 0.3.0
|
90
|
+
#
|
91
|
+
# @api public
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# string = SequencedString.new("Normal \e[31mred\e[0m")
|
95
|
+
# string.stripped #=> "Normal red"
|
96
|
+
#
|
97
|
+
# @return [String] the concatenation of all segment text without color or style
|
98
|
+
def stripped: () -> untyped
|
99
|
+
|
100
|
+
# Return the fully reconstructed string with **all ANSI sequences** (foreground, background, style)
|
101
|
+
#
|
102
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
103
|
+
# @since 0.3.0
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
#
|
107
|
+
# @example
|
108
|
+
# string = SequencedString.new("\e[31mred\e[0m")
|
109
|
+
# string.to_s #=> "\e[31mred\e[0m"
|
110
|
+
#
|
111
|
+
# @return [String]
|
112
|
+
def to_s: () -> untyped
|
113
|
+
|
114
|
+
alias to_str to_s
|
115
|
+
|
116
|
+
# Return a string with everything except **background** color sequences removed
|
117
|
+
#
|
118
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
119
|
+
# @since 0.3.0
|
120
|
+
#
|
121
|
+
# @api public
|
122
|
+
#
|
123
|
+
# @example Remove all background colors
|
124
|
+
# string = SequencedString.new("\e[41mBack\e[0m \e[1mBold\e[0m")
|
125
|
+
# string.without_background #=> "\e[1mBold\e[0m"
|
126
|
+
#
|
127
|
+
# @return [SequencedString] new instance with background colors removed
|
128
|
+
# @rbs () -> SequencedString
|
129
|
+
def without_background: () -> SequencedString
|
130
|
+
|
131
|
+
# Return a string containing *style* sequences but **no foreground or background colors**
|
132
|
+
#
|
133
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
134
|
+
# @since 0.3.0
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
#
|
138
|
+
# @example Remove all colors
|
139
|
+
# string = SequencedString.new("\e[31mred\e[0m \e[1mbold\e[0m")
|
140
|
+
# string.without_color #=> "\e[1mbold\e[0m"
|
141
|
+
#
|
142
|
+
# @return [SequencedString] new instance with all colors removed
|
143
|
+
# @rbs () -> SequencedString
|
144
|
+
def without_color: () -> SequencedString
|
145
|
+
|
146
|
+
# Return a string with everything except **foreground** color sequences removed
|
147
|
+
#
|
148
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
149
|
+
# @since 0.3.0
|
150
|
+
#
|
151
|
+
# @api public
|
152
|
+
#
|
153
|
+
# @example Remove all foreground colors
|
154
|
+
# string = SequencedString.new("\e[41mBack\e[0m \e[1mBold\e[0m")
|
155
|
+
# string.without_foreground #=> "\e[41mBack\e[0m \e[1mBold\e[0m"
|
156
|
+
#
|
157
|
+
# @return [SequencedString] new instance with foreground colors removed
|
158
|
+
# @rbs () -> SequencedString
|
159
|
+
def without_foreground: () -> SequencedString
|
160
|
+
|
161
|
+
# Return a string with specified styles removed
|
162
|
+
#
|
163
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
164
|
+
# @since 0.3.0
|
165
|
+
#
|
166
|
+
# @api public
|
167
|
+
#
|
168
|
+
# @example Remove all styles
|
169
|
+
# string = SequencedString.new("\e[31mred\e[0m \e[1mbold\e[0m")
|
170
|
+
# string.without_style #=> "\e[31mred\e[0m"
|
171
|
+
#
|
172
|
+
# @example Remove specific style
|
173
|
+
# string = SequencedString.new("\e[1;4mBold and Underlined\e[0m")
|
174
|
+
# string.without_style(:bold) #=> "\e[4mUnderlined\e[0m"
|
175
|
+
#
|
176
|
+
# @param styles [Array<Symbol>] specific styles to remove (default: all)
|
177
|
+
#
|
178
|
+
# @return [SequencedString] new instance with specified styles removed
|
179
|
+
def without_style: (*untyped styles) -> untyped
|
180
|
+
|
181
|
+
private
|
182
|
+
|
183
|
+
# Build the color sequences for a segment
|
184
|
+
#
|
185
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
186
|
+
# @since 0.3.0
|
187
|
+
#
|
188
|
+
# @api private
|
189
|
+
#
|
190
|
+
# @param segment [Segment] the segment to build color sequences for
|
191
|
+
# @param skip_background [Boolean] whether to skip background colors
|
192
|
+
# @param skip_foreground [Boolean] whether to skip foreground colors
|
193
|
+
#
|
194
|
+
# @return [Array<String>] the color sequences
|
195
|
+
# @rbs (Segment segment, ?skip_background: bool, ?skip_foreground: bool) -> Array[String]
|
196
|
+
def build_color_sequences: (Segment segment, ?skip_background: bool, ?skip_foreground: bool) -> Array[String]
|
197
|
+
|
198
|
+
# Build a string with specified parts skipped
|
199
|
+
#
|
200
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
201
|
+
# @since 0.3.0
|
202
|
+
#
|
203
|
+
# @api private
|
204
|
+
#
|
205
|
+
# @param skip_background [Boolean] whether to skip background colors
|
206
|
+
# @param skip_foreground [Boolean] whether to skip foreground colors
|
207
|
+
# @param skip_styles [Array<Symbol>] styles to skip
|
208
|
+
#
|
209
|
+
# @return [String] the built string
|
210
|
+
# @rbs (?skip_background: bool, ?skip_foreground: bool, ?skip_styles: Array[Symbol]) -> String
|
211
|
+
def build_string: (?skip_background: bool, ?skip_foreground: bool, ?skip_styles: Array[Symbol]) -> String
|
212
|
+
|
213
|
+
# Build the style sequences for a segment
|
214
|
+
#
|
215
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
216
|
+
# @since 0.3.0
|
217
|
+
#
|
218
|
+
# @api private
|
219
|
+
#
|
220
|
+
# @param segment [Segment] the segment to build style sequences for
|
221
|
+
# @param skip_styles [Array<Symbol>] styles to skip
|
222
|
+
#
|
223
|
+
# @return [Array<String>] the style sequences
|
224
|
+
# @rbs (Segment segment, ?skip_styles: Array[Symbol]) -> Array[String]
|
225
|
+
def build_style_sequences: (Segment segment, ?skip_styles: Array[Symbol]) -> Array[String]
|
226
|
+
|
227
|
+
# A segment of an ANSI encoded string
|
228
|
+
#
|
229
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
230
|
+
# @since 0.3.0
|
231
|
+
#
|
232
|
+
# @api public
|
233
|
+
class Segment
|
234
|
+
# The background color sequences for the Segment
|
235
|
+
#
|
236
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
237
|
+
# @since 0.3.0
|
238
|
+
#
|
239
|
+
# @api public
|
240
|
+
#
|
241
|
+
# @return [String, nil] the background color sequences
|
242
|
+
attr_reader background: String?
|
243
|
+
|
244
|
+
# The foreground color sequences for the Segment
|
245
|
+
#
|
246
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
247
|
+
# @since 0.3.0
|
248
|
+
#
|
249
|
+
# @api public
|
250
|
+
#
|
251
|
+
# @return [String, nil] the foreground color sequences
|
252
|
+
attr_reader foreground: String?
|
253
|
+
|
254
|
+
# The {Location} of the encoded string within the {SequencedString}
|
255
|
+
#
|
256
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
257
|
+
# @since 0.3.0
|
258
|
+
#
|
259
|
+
# @api public
|
260
|
+
#
|
261
|
+
# @return [Location] the {Location}
|
262
|
+
attr_reader encoded_location: Location
|
263
|
+
|
264
|
+
alias encoded_loc encoded_location
|
265
|
+
|
266
|
+
# The {Location} of the encoded string without it's encoding within the {SequencedString}
|
267
|
+
#
|
268
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
269
|
+
# @since 0.3.0
|
270
|
+
#
|
271
|
+
# @api public
|
272
|
+
#
|
273
|
+
# @return [Location] the {Location}
|
274
|
+
attr_reader stripped_location: Location
|
275
|
+
|
276
|
+
alias stripped_loc stripped_location
|
277
|
+
|
278
|
+
# The style sequences (bold, underline, etc...) for the segment
|
279
|
+
#
|
280
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
281
|
+
# @since 0.3.0
|
282
|
+
#
|
283
|
+
# @api public
|
284
|
+
#
|
285
|
+
# @return [Array<String>] the style sequences
|
286
|
+
attr_reader styles: Array[String]
|
287
|
+
|
288
|
+
# The raw text of the Segment without any of its ANSI sequences
|
289
|
+
#
|
290
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
291
|
+
# @since 0.3.0
|
292
|
+
#
|
293
|
+
# @api public
|
294
|
+
#
|
295
|
+
# @return [String]
|
296
|
+
attr_reader text: String
|
297
|
+
|
298
|
+
# Initialize a new instance of Segment
|
299
|
+
#
|
300
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
301
|
+
# @since 0.3.0
|
302
|
+
#
|
303
|
+
# @api private
|
304
|
+
#
|
305
|
+
# @param options [Hash{Symbol => Object}] the options to initialize the Segment with
|
306
|
+
# @option options background [String, nil] the Segment {#background}
|
307
|
+
# @option options foreground [String, nil] the Segment {#foreground}
|
308
|
+
# @option options encoded_end [Integer] the {Location#end_position end_position} of the Segment
|
309
|
+
# {#encoded_location}
|
310
|
+
# @option options encoded_start [Integer] the {Location#start_position start_position} of the Segment
|
311
|
+
# {#encoded_location}
|
312
|
+
# @option options stripped_end [Integer] the {Location#end_position end_position} of the Segment
|
313
|
+
# {#stripped_location}
|
314
|
+
# @option options stripped_start [Integer] the {Location#start_position start_position} of the Segment
|
315
|
+
# {#stripped_location}
|
316
|
+
# @option options styles [Array<String>] the Segment {#styles}
|
317
|
+
# @option options text [String] the Segment {#text}
|
318
|
+
#
|
319
|
+
# @return [Segment] the new instance of Segment
|
320
|
+
# @rbs (
|
321
|
+
# ?background: String?,
|
322
|
+
# ?foreground: String?,
|
323
|
+
# encoded_end: Integer,
|
324
|
+
# encoded_start: Integer,
|
325
|
+
# stripped_end: Integer,
|
326
|
+
# stripped_start: Integer,
|
327
|
+
# ?styles: Array[String],
|
328
|
+
# text: String
|
329
|
+
# ) -> void
|
330
|
+
def initialize: (encoded_end: Integer, encoded_start: Integer, stripped_end: Integer, stripped_start: Integer, text: String, ?background: String?, ?foreground: String?, ?styles: Array[String]) -> void
|
331
|
+
|
332
|
+
# The location of the {Segment} within a {SequencedString}
|
333
|
+
#
|
334
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
335
|
+
# @since 0.3.0
|
336
|
+
#
|
337
|
+
# @api public
|
338
|
+
class Location
|
339
|
+
# The ending position of the Location
|
340
|
+
#
|
341
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
342
|
+
# @since 0.3.0
|
343
|
+
#
|
344
|
+
# @api public
|
345
|
+
#
|
346
|
+
# @return [Integer] the end position
|
347
|
+
attr_reader end_position: Integer
|
348
|
+
|
349
|
+
alias end_pos end_position
|
350
|
+
|
351
|
+
# The starting position of the Location
|
352
|
+
#
|
353
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
354
|
+
# @since 0.3.0
|
355
|
+
#
|
356
|
+
# @api public
|
357
|
+
#
|
358
|
+
# @return [Integer] the start position
|
359
|
+
attr_reader start_position: Integer
|
360
|
+
|
361
|
+
alias start_pos start_position
|
362
|
+
|
363
|
+
# Initialize a new instance of Location
|
364
|
+
#
|
365
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
366
|
+
# @since 0.3.0
|
367
|
+
#
|
368
|
+
# @api private
|
369
|
+
#
|
370
|
+
# @param end_position [Integer] the {#end_position} of the location
|
371
|
+
# @param start_position [Integer] the {#start_position} of the location
|
372
|
+
#
|
373
|
+
# @return [Location] the new instance of Location
|
374
|
+
# @rbs (end_position: Integer, start_position: Integer) -> void
|
375
|
+
def initialize: (end_position: Integer, start_position: Integer) -> void
|
376
|
+
end
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
data/sig/sai/decorator.rbs
CHANGED
@@ -125,14 +125,13 @@ module Sai
|
|
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
|
|
@@ -148,7 +147,7 @@ module Sai
|
|
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
|
#
|
@@ -165,7 +164,7 @@ module Sai
|
|
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
|
#
|
@@ -182,7 +181,7 @@ module Sai
|
|
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
|
@@ -201,7 +200,7 @@ module Sai
|
|
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
|
@@ -240,7 +239,6 @@ module Sai
|
|
240
239
|
# @param style_type [Symbol] the style type to apply the color to
|
241
240
|
# @param color [Symbol] the color to apply
|
242
241
|
#
|
243
|
-
# @raise [ArgumentError] if the color is invalid
|
244
242
|
# @return [Decorator] a new instance of Decorator with the color applied
|
245
243
|
# @rbs (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
|
246
244
|
def apply_named_color: (Conversion::ColorSequence::style_type style_type, Symbol color) -> Decorator
|
@@ -254,7 +252,6 @@ module Sai
|
|
254
252
|
#
|
255
253
|
# @param style [String, Symbol] the style to apply
|
256
254
|
#
|
257
|
-
# @raise [ArgumentError] if the style is invalid
|
258
255
|
# @return [Decorator] a new instance of Decorator with the style applied
|
259
256
|
# @rbs (String | Symbol style) -> self
|
260
257
|
def apply_style: (String | Symbol style) -> self
|