sai 0.2.0 → 0.3.1
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 +38 -1
- data/README.md +39 -241
- data/docs/USAGE.md +351 -0
- data/lib/sai/ansi/color_parser.rb +109 -0
- data/lib/sai/ansi/sequence_processor.rb +269 -0
- data/lib/sai/ansi/sequenced_string.rb +475 -0
- data/lib/sai/ansi/style_parser.rb +66 -0
- data/lib/sai/ansi.rb +0 -27
- data/lib/sai/conversion/color_sequence.rb +4 -4
- data/lib/sai/conversion/rgb/color_classifier.rb +209 -0
- data/lib/sai/conversion/rgb/color_indexer.rb +48 -0
- data/lib/sai/conversion/rgb/color_space.rb +192 -0
- data/lib/sai/conversion/rgb/color_transformer.rb +140 -0
- data/lib/sai/conversion/rgb.rb +23 -269
- data/lib/sai/decorator/color_manipulations.rb +157 -0
- data/lib/sai/decorator/delegation.rb +84 -0
- data/lib/sai/decorator/gradients.rb +363 -0
- data/lib/sai/decorator/hex_colors.rb +56 -0
- data/lib/sai/decorator/named_colors.rb +780 -0
- data/lib/sai/decorator/named_styles.rb +276 -0
- data/lib/sai/decorator/rgb_colors.rb +64 -0
- data/lib/sai/decorator.rb +35 -795
- data/lib/sai/mode_selector.rb +19 -19
- data/lib/sai/named_colors.rb +437 -0
- data/lib/sai.rb +753 -23
- data/sig/manifest.yaml +3 -0
- data/sig/sai/ansi/color_parser.rbs +77 -0
- data/sig/sai/ansi/sequence_processor.rbs +178 -0
- data/sig/sai/ansi/sequenced_string.rbs +380 -0
- data/sig/sai/ansi/style_parser.rbs +59 -0
- data/sig/sai/ansi.rbs +0 -10
- data/sig/sai/conversion/rgb/color_classifier.rbs +165 -0
- data/sig/sai/conversion/rgb/color_indexer.rbs +41 -0
- data/sig/sai/conversion/rgb/color_space.rbs +129 -0
- data/sig/sai/conversion/rgb/color_transformer.rbs +99 -0
- data/sig/sai/conversion/rgb.rbs +15 -198
- data/sig/sai/decorator/color_manipulations.rbs +125 -0
- data/sig/sai/decorator/delegation.rbs +47 -0
- data/sig/sai/decorator/gradients.rbs +267 -0
- data/sig/sai/decorator/hex_colors.rbs +48 -0
- data/sig/sai/decorator/named_colors.rbs +1491 -0
- data/sig/sai/decorator/named_styles.rbs +72 -0
- data/sig/sai/decorator/rgb_colors.rbs +52 -0
- data/sig/sai/decorator.rbs +25 -202
- data/sig/sai/mode_selector.rbs +19 -19
- data/sig/sai/named_colors.rbs +65 -0
- data/sig/sai.rbs +1485 -44
- metadata +38 -4
data/sig/manifest.yaml
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated from lib/sai/ansi/color_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module ANSI
|
5
|
+
# Handles parsing of ANSI color codes
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since 0.3.1
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
class ColorParser
|
12
|
+
# The current segment being processed
|
13
|
+
#
|
14
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
+
# @since 0.3.1
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @return [Hash] the current segment being processed
|
20
|
+
attr_reader segment: Hash[Symbol, untyped]
|
21
|
+
|
22
|
+
# Initialize a new instance of ColorParser
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.3.1
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @param segment [Hash] the segment to update
|
30
|
+
#
|
31
|
+
# @return [ColorParser] the new instance of ColorParser
|
32
|
+
# @rbs (Hash[Symbol, untyped] segment) -> void
|
33
|
+
def initialize: (Hash[Symbol, untyped] segment) -> void
|
34
|
+
|
35
|
+
# Parse a 256-color code
|
36
|
+
#
|
37
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
38
|
+
# @since 0.3.1
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
# @param codes [Array<Integer>] array of color codes
|
43
|
+
# @param index [Integer] current position in array
|
44
|
+
#
|
45
|
+
# @return [Integer] new position in array
|
46
|
+
# @rbs (Array[Integer] codes, Integer index) -> Integer
|
47
|
+
def parse256: (Array[Integer] codes, Integer index) -> Integer
|
48
|
+
|
49
|
+
# Parse a 24-bit color code
|
50
|
+
#
|
51
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
52
|
+
# @since 0.3.1
|
53
|
+
#
|
54
|
+
# @api private
|
55
|
+
#
|
56
|
+
# @param codes [Array<Integer>] array of color codes
|
57
|
+
# @param index [Integer] current position in array
|
58
|
+
#
|
59
|
+
# @return [Integer] new position in array
|
60
|
+
# @rbs (Array[Integer] codes, Integer index) -> Integer
|
61
|
+
def parse_24bit: (Array[Integer] codes, Integer index) -> Integer
|
62
|
+
|
63
|
+
# Parse a basic color code
|
64
|
+
#
|
65
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
66
|
+
# @since 0.3.1
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
#
|
70
|
+
# @param code [Integer] the color code
|
71
|
+
#
|
72
|
+
# @return [void]
|
73
|
+
# @rbs (Integer code) -> void
|
74
|
+
def parse_basic: (Integer code) -> void
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,178 @@
|
|
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
|
+
# Initialize a new instance of SequenceProcessor and parse the provided string
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.3.0
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @param string [String] the string to parse
|
30
|
+
#
|
31
|
+
# @return [Array<Hash{Symbol => Object}>] the segments
|
32
|
+
# @rbs (String string) -> Array[Hash[Symbol, untyped]]
|
33
|
+
def self.process: (String string) -> Array[Hash[Symbol, untyped]]
|
34
|
+
|
35
|
+
# Initialize a new instance of SequenceProcessor
|
36
|
+
#
|
37
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
38
|
+
# @since 0.3.0
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
# @param string [String] the string to parse
|
43
|
+
#
|
44
|
+
# @return [SequenceProcessor] the new instance of SequenceProcessor
|
45
|
+
# @rbs (String string) -> void
|
46
|
+
def initialize: (String string) -> void
|
47
|
+
|
48
|
+
# Parse a string and return a hash of segments
|
49
|
+
#
|
50
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
51
|
+
# @since 0.3.0
|
52
|
+
#
|
53
|
+
# @api private
|
54
|
+
#
|
55
|
+
# @return [Array<Hash{Symbol => Object}>] the segments
|
56
|
+
# @rbs () -> Array[Hash[Symbol, untyped]]
|
57
|
+
def process: () -> Array[Hash[Symbol, untyped]]
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Applies the appropriate action for the provided ANSI sequence
|
62
|
+
#
|
63
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
64
|
+
# @since 0.3.0
|
65
|
+
#
|
66
|
+
# @api private
|
67
|
+
#
|
68
|
+
# @param sequence [String] an ANSI sequence (e.g. "\e[31m", "\e[0m")
|
69
|
+
#
|
70
|
+
# @return [void]
|
71
|
+
# @rbs (String sequence) -> void
|
72
|
+
def apply_ansi_sequence: (String sequence) -> void
|
73
|
+
|
74
|
+
# Parse all numeric codes in the provided string, applying them in order (just like a real ANSI terminal)
|
75
|
+
#
|
76
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
77
|
+
# @since 0.3.0
|
78
|
+
#
|
79
|
+
# @api private
|
80
|
+
#
|
81
|
+
# @param codes_string [String] e.g. "38;5;160;48;5;21;1"
|
82
|
+
#
|
83
|
+
# @return [void]
|
84
|
+
# @rbs (String codes_string) -> void
|
85
|
+
def apply_codes: (String codes_string) -> void
|
86
|
+
|
87
|
+
# Applies a single code (or group) from the array. This might be:
|
88
|
+
# - 0 => reset
|
89
|
+
# - 30..37 => basic FG color
|
90
|
+
# - 40..47 => basic BG color
|
91
|
+
# - 38 or 48 => extended color sequence
|
92
|
+
# - otherwise => style code (bold, underline, etc.)
|
93
|
+
#
|
94
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
95
|
+
# @since 0.3.0
|
96
|
+
#
|
97
|
+
# @api private
|
98
|
+
#
|
99
|
+
# @param codes_array [Array<Integer>] the list of numeric codes
|
100
|
+
# @param index [Integer] the current index
|
101
|
+
#
|
102
|
+
# @return [Integer] the updated index after consuming needed codes
|
103
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
104
|
+
def apply_single_code: (Array[Integer] codes_array, Integer index) -> Integer
|
105
|
+
|
106
|
+
# Scans the string for ANSI sequences or individual characters
|
107
|
+
#
|
108
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
109
|
+
# @since 0.3.0
|
110
|
+
#
|
111
|
+
# @api private
|
112
|
+
#
|
113
|
+
# @return [void]
|
114
|
+
# @rbs () -> void
|
115
|
+
def consume_tokens: () -> void
|
116
|
+
|
117
|
+
# Finalizes the current segment if any text is present, then resets it
|
118
|
+
#
|
119
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
120
|
+
# @since 0.3.0
|
121
|
+
#
|
122
|
+
# @api private
|
123
|
+
#
|
124
|
+
# @return [void]
|
125
|
+
# @rbs () -> void
|
126
|
+
def finalize_segment_if_text!: () -> void
|
127
|
+
|
128
|
+
# Attempts to capture an ANSI sequence from the scanner If found, finalizes
|
129
|
+
# the current text segment and applies the sequence
|
130
|
+
#
|
131
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
132
|
+
# @since 0.3.0
|
133
|
+
#
|
134
|
+
# @api private
|
135
|
+
#
|
136
|
+
# @return [Boolean] `true` if a sequence was found, `false` if otherwise
|
137
|
+
# @rbs () -> bool
|
138
|
+
def handle_ansi_sequence: () -> bool
|
139
|
+
|
140
|
+
# Reads a single character from the scanner and appends it to the current segment
|
141
|
+
#
|
142
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
143
|
+
# @since 0.3.0
|
144
|
+
#
|
145
|
+
# @api private
|
146
|
+
#
|
147
|
+
# @return [void]
|
148
|
+
# @rbs () -> void
|
149
|
+
def handle_character: () -> void
|
150
|
+
|
151
|
+
# Parse extended color codes from the array, e.g. 38;5;160 (256-color) or 38;2;R;G;B (24-bit),
|
152
|
+
# and apply them to foreground or background
|
153
|
+
#
|
154
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
155
|
+
# @since 0.3.0
|
156
|
+
#
|
157
|
+
# @api private
|
158
|
+
#
|
159
|
+
# @param codes_array [Array<Integer>] the array of codes
|
160
|
+
# @param index [Integer] the current position (where we saw 38 or 48)
|
161
|
+
#
|
162
|
+
# @return [Integer] the updated position in the codes array
|
163
|
+
# @rbs (Array[Integer] codes_array, Integer index) -> Integer
|
164
|
+
def parse_extended_color: (Array[Integer] codes_array, Integer index) -> Integer
|
165
|
+
|
166
|
+
# Resets the current segment to a fresh, blank state
|
167
|
+
#
|
168
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
169
|
+
# @since 0.3.0
|
170
|
+
#
|
171
|
+
# @api private
|
172
|
+
#
|
173
|
+
# @return [void]
|
174
|
+
# @rbs () -> void
|
175
|
+
def reset_segment!: () -> void
|
176
|
+
end
|
177
|
+
end
|
178
|
+
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
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated from lib/sai/ansi/style_parser.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Sai
|
4
|
+
module ANSI
|
5
|
+
# Handles parsing of ANSI style codes
|
6
|
+
#
|
7
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
8
|
+
# @since 0.3.1
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
class StyleParser
|
12
|
+
# Matches the code portion of style sequences
|
13
|
+
#
|
14
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
15
|
+
# @since 0.3.1
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
# @return [Regexp] the pattern
|
20
|
+
STYLE_CODE_PATTERN: Regexp
|
21
|
+
|
22
|
+
# The current segment being processed
|
23
|
+
#
|
24
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
25
|
+
# @since 0.3.1
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
#
|
29
|
+
# @return [Hash] the current segment being processed
|
30
|
+
attr_reader segment: Hash[Symbol, untyped]
|
31
|
+
|
32
|
+
# Initialize a new instance of StyleParser
|
33
|
+
#
|
34
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
35
|
+
# @since 0.3.1
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
#
|
39
|
+
# @param segment [Hash] the segment to update
|
40
|
+
#
|
41
|
+
# @return [StyleParser] the new instance of StyleParser
|
42
|
+
# @rbs (Hash[Symbol, untyped] segment) -> void
|
43
|
+
def initialize: (Hash[Symbol, untyped] segment) -> void
|
44
|
+
|
45
|
+
# Parse a style code
|
46
|
+
#
|
47
|
+
# @author {https://aaronmallen.me Aaron Allen}
|
48
|
+
# @since 0.3.1
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
#
|
52
|
+
# @param code [Integer] the style code
|
53
|
+
#
|
54
|
+
# @return [void]
|
55
|
+
# @rbs (Integer code) -> void
|
56
|
+
def parse: (Integer code) -> void
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|