@@ -36,6 +36,7 @@ const {
36
36
ObjectSetPrototypeOf,
37
37
ObjectValues,
38
38
ReflectApply,
39
+ StringPrototypeReplace,
39
40
StringPrototypeToWellFormed,
40
41
} = primordials ;
41
42
@@ -165,31 +166,32 @@ function styleText(format, text, { validateStream = true, stream = process.stdou
165
166
}
166
167
167
168
// Process the text to handle nested styles
168
- const processedText = text . replace ( fontColorEndRegex , ( match , offset ) => {
169
- // Check if there's more content after this reset
170
- if ( offset + match . length < text . length ) {
171
- for ( let i = 0 ; i < codes . length ; i ++ ) {
172
- const open = codes [ i ] [ 0 ] ;
173
- // Check if this is a foreground color (30-37, 90-97)
174
- if ( ( open >= 30 && open <= 37 ) || ( open >= 90 && open <= 97 ) ) {
175
- return escapeStyleCode ( open ) ;
169
+ const processedText = StringPrototypeReplace (
170
+ StringPrototypeReplace ( text , fontColorEndRegex , ( match , offset ) => {
171
+ // Check if there's more content after this reset
172
+ if ( offset + match . length < text . length ) {
173
+ for ( let i = 0 ; i < codes . length ; i ++ ) {
174
+ const open = codes [ i ] [ 0 ] ;
175
+ // Check if this is a foreground color (30-37, 90-97)
176
+ if ( ( open >= 30 && open <= 37 ) || ( open >= 90 && open <= 97 ) ) {
177
+ return escapeStyleCode ( open ) ;
178
+ }
176
179
}
177
180
}
178
- }
179
- return match ;
180
- } ) . replace ( bgColorEndRegex , ( match , offset ) => {
181
- // Check if there's more content after this reset
182
- if ( offset + match . length < text . length ) {
183
- for ( let i = 0 ; i < codes . length ; i ++ ) {
184
- const open = codes [ i ] [ 0 ] ;
185
- // Check if this is a background color (40-47, 100- 107)
186
- if ( ( open >= 40 && open <= 47 ) || ( open >= 100 && open <= 107 ) ) {
187
- return escapeStyleCode ( open ) ;
181
+ return match ;
182
+ } ) , bgColorEndRegex , ( match , offset ) => {
183
+ // Check if there's more content after this reset
184
+ if ( offset + match . length < text . length ) {
185
+ for ( let i = 0 ; i < codes . length ; i ++ ) {
186
+ const open = codes [ i ] [ 0 ] ;
187
+ // Check if this is a background color (40-47, 100-107)
188
+ if ( ( open >= 40 && open <= 47 ) || ( open >= 100 && open <= 107 ) ) {
189
+ return escapeStyleCode ( open ) ;
190
+ }
188
191
}
189
192
}
190
- }
191
- return match ;
192
- } ) ;
193
+ return match ;
194
+ } ) ;
193
195
194
196
// Build closing codes in reverse order
195
197
let closeCodes = '' ;
0 commit comments