@@ -106,102 +106,102 @@ impl anstyle_parse::Perform for WinconCapture {
106106
107107 let mut style = self . style ;
108108 // param/value differences are dependent on the escape code
109- let mut state = State :: Normal ;
109+ let mut state = CsiState :: Normal ;
110110 let mut r = None ;
111111 let mut g = None ;
112112 let mut color_target = ColorTarget :: Fg ;
113113 for param in params {
114114 for value in param {
115115 match ( state, * value) {
116- ( State :: Normal , 0 ) => {
116+ ( CsiState :: Normal , 0 ) => {
117117 style = anstyle:: Style :: default ( ) ;
118118 break ;
119119 }
120- ( State :: Normal , 1 ) => {
120+ ( CsiState :: Normal , 1 ) => {
121121 style = style. bold ( ) ;
122122 break ;
123123 }
124- ( State :: Normal , 2 ) => {
124+ ( CsiState :: Normal , 2 ) => {
125125 style = style. dimmed ( ) ;
126126 break ;
127127 }
128- ( State :: Normal , 3 ) => {
128+ ( CsiState :: Normal , 3 ) => {
129129 style = style. italic ( ) ;
130130 break ;
131131 }
132- ( State :: Normal , 4 ) => {
132+ ( CsiState :: Normal , 4 ) => {
133133 style = style. underline ( ) ;
134- state = State :: Underline ;
134+ state = CsiState :: Underline ;
135135 }
136- ( State :: Normal , 21 ) => {
136+ ( CsiState :: Normal , 21 ) => {
137137 style |= anstyle:: Effects :: DOUBLE_UNDERLINE ;
138138 break ;
139139 }
140- ( State :: Normal , 7 ) => {
140+ ( CsiState :: Normal , 7 ) => {
141141 style = style. invert ( ) ;
142142 break ;
143143 }
144- ( State :: Normal , 8 ) => {
144+ ( CsiState :: Normal , 8 ) => {
145145 style = style. hidden ( ) ;
146146 break ;
147147 }
148- ( State :: Normal , 9 ) => {
148+ ( CsiState :: Normal , 9 ) => {
149149 style = style. strikethrough ( ) ;
150150 break ;
151151 }
152- ( State :: Normal , 30 ..=37 ) => {
152+ ( CsiState :: Normal , 30 ..=37 ) => {
153153 let color = to_ansi_color ( value - 30 ) . expect ( "within 4-bit range" ) ;
154154 style = style. fg_color ( Some ( color. into ( ) ) ) ;
155155 break ;
156156 }
157- ( State :: Normal , 38 ) => {
157+ ( CsiState :: Normal , 38 ) => {
158158 color_target = ColorTarget :: Fg ;
159- state = State :: PrepareCustomColor ;
159+ state = CsiState :: PrepareCustomColor ;
160160 }
161- ( State :: Normal , 39 ) => {
161+ ( CsiState :: Normal , 39 ) => {
162162 style = style. fg_color ( None ) ;
163163 break ;
164164 }
165- ( State :: Normal , 40 ..=47 ) => {
165+ ( CsiState :: Normal , 40 ..=47 ) => {
166166 let color = to_ansi_color ( value - 40 ) . expect ( "within 4-bit range" ) ;
167167 style = style. bg_color ( Some ( color. into ( ) ) ) ;
168168 break ;
169169 }
170- ( State :: Normal , 48 ) => {
170+ ( CsiState :: Normal , 48 ) => {
171171 color_target = ColorTarget :: Bg ;
172- state = State :: PrepareCustomColor ;
172+ state = CsiState :: PrepareCustomColor ;
173173 }
174- ( State :: Normal , 49 ) => {
174+ ( CsiState :: Normal , 49 ) => {
175175 style = style. bg_color ( None ) ;
176176 break ;
177177 }
178- ( State :: Normal , 58 ) => {
178+ ( CsiState :: Normal , 58 ) => {
179179 color_target = ColorTarget :: Underline ;
180- state = State :: PrepareCustomColor ;
180+ state = CsiState :: PrepareCustomColor ;
181181 }
182- ( State :: Normal , 90 ..=97 ) => {
182+ ( CsiState :: Normal , 90 ..=97 ) => {
183183 let color = to_ansi_color ( value - 90 )
184184 . expect ( "within 4-bit range" )
185185 . bright ( true ) ;
186186 style = style. fg_color ( Some ( color. into ( ) ) ) ;
187187 break ;
188188 }
189- ( State :: Normal , 100 ..=107 ) => {
189+ ( CsiState :: Normal , 100 ..=107 ) => {
190190 let color = to_ansi_color ( value - 100 )
191191 . expect ( "within 4-bit range" )
192192 . bright ( true ) ;
193193 style = style. bg_color ( Some ( color. into ( ) ) ) ;
194194 break ;
195195 }
196- ( State :: PrepareCustomColor , 5 ) => {
197- state = State :: Ansi256 ;
196+ ( CsiState :: PrepareCustomColor , 5 ) => {
197+ state = CsiState :: Ansi256 ;
198198 }
199- ( State :: PrepareCustomColor , 2 ) => {
200- state = State :: Rgb ;
199+ ( CsiState :: PrepareCustomColor , 2 ) => {
200+ state = CsiState :: Rgb ;
201201 r = None ;
202202 g = None ;
203203 }
204- ( State :: Ansi256 , n) => {
204+ ( CsiState :: Ansi256 , n) => {
205205 let color = anstyle:: Ansi256Color ( n as u8 ) ;
206206 style = match color_target {
207207 ColorTarget :: Fg => style. fg_color ( Some ( color. into ( ) ) ) ,
@@ -210,7 +210,7 @@ impl anstyle_parse::Perform for WinconCapture {
210210 } ;
211211 break ;
212212 }
213- ( State :: Rgb , b) => match ( r, g) {
213+ ( CsiState :: Rgb , b) => match ( r, g) {
214214 ( None , _) => {
215215 r = Some ( b) ;
216216 }
@@ -227,29 +227,29 @@ impl anstyle_parse::Perform for WinconCapture {
227227 break ;
228228 }
229229 } ,
230- ( State :: Underline , 0 ) => {
230+ ( CsiState :: Underline , 0 ) => {
231231 style =
232232 style. effects ( style. get_effects ( ) . remove ( anstyle:: Effects :: UNDERLINE ) ) ;
233233 }
234- ( State :: Underline , 1 ) => {
234+ ( CsiState :: Underline , 1 ) => {
235235 // underline already set
236236 }
237- ( State :: Underline , 2 ) => {
237+ ( CsiState :: Underline , 2 ) => {
238238 style = style
239239 . effects ( style. get_effects ( ) . remove ( anstyle:: Effects :: UNDERLINE ) )
240240 | anstyle:: Effects :: DOUBLE_UNDERLINE ;
241241 }
242- ( State :: Underline , 3 ) => {
242+ ( CsiState :: Underline , 3 ) => {
243243 style = style
244244 . effects ( style. get_effects ( ) . remove ( anstyle:: Effects :: UNDERLINE ) )
245245 | anstyle:: Effects :: CURLY_UNDERLINE ;
246246 }
247- ( State :: Underline , 4 ) => {
247+ ( CsiState :: Underline , 4 ) => {
248248 style = style
249249 . effects ( style. get_effects ( ) . remove ( anstyle:: Effects :: UNDERLINE ) )
250250 | anstyle:: Effects :: DOTTED_UNDERLINE ;
251251 }
252- ( State :: Underline , 5 ) => {
252+ ( CsiState :: Underline , 5 ) => {
253253 style = style
254254 . effects ( style. get_effects ( ) . remove ( anstyle:: Effects :: UNDERLINE ) )
255255 | anstyle:: Effects :: DASHED_UNDERLINE ;
@@ -269,7 +269,7 @@ impl anstyle_parse::Perform for WinconCapture {
269269}
270270
271271#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
272- enum State {
272+ enum CsiState {
273273 Normal ,
274274 PrepareCustomColor ,
275275 Ansi256 ,
@@ -301,7 +301,6 @@ fn to_ansi_color(digit: u16) -> Option<anstyle::AnsiColor> {
301301#[ cfg( test) ]
302302mod test {
303303 use super :: * ;
304- use owo_colors:: OwoColorize as _;
305304 use proptest:: prelude:: * ;
306305
307306 #[ track_caller]
@@ -317,54 +316,46 @@ mod test {
317316
318317 #[ test]
319318 fn start ( ) {
320- let input = format ! ( "{} world!" , "Hello" . green( ) . on_red( ) ) ;
319+ let green_on_red = anstyle:: AnsiColor :: Green . on ( anstyle:: AnsiColor :: Red ) ;
320+ let input = format ! ( "{green_on_red}Hello{green_on_red:#} world!" ) ;
321321 let expected = vec ! [
322- (
323- anstyle:: AnsiColor :: Green . on( anstyle:: AnsiColor :: Red ) ,
324- "Hello" ,
325- ) ,
322+ ( green_on_red, "Hello" ) ,
326323 ( anstyle:: Style :: default ( ) , " world!" ) ,
327324 ] ;
328325 verify ( & input, expected) ;
329326 }
330327
331328 #[ test]
332329 fn middle ( ) {
333- let input = format ! ( "Hello {}!" , "world" . green( ) . on_red( ) ) ;
330+ let green_on_red = anstyle:: AnsiColor :: Green . on ( anstyle:: AnsiColor :: Red ) ;
331+ let input = format ! ( "Hello {green_on_red}world{green_on_red:#}!" ) ;
334332 let expected = vec ! [
335333 ( anstyle:: Style :: default ( ) , "Hello " ) ,
336- (
337- anstyle:: AnsiColor :: Green . on( anstyle:: AnsiColor :: Red ) ,
338- "world" ,
339- ) ,
334+ ( green_on_red, "world" ) ,
340335 ( anstyle:: Style :: default ( ) , "!" ) ,
341336 ] ;
342337 verify ( & input, expected) ;
343338 }
344339
345340 #[ test]
346341 fn end ( ) {
347- let input = format ! ( "Hello {}" , "world!" . green( ) . on_red( ) ) ;
342+ let green_on_red = anstyle:: AnsiColor :: Green . on ( anstyle:: AnsiColor :: Red ) ;
343+ let input = format ! ( "Hello {green_on_red}world!{green_on_red:#}" ) ;
348344 let expected = vec ! [
349345 ( anstyle:: Style :: default ( ) , "Hello " ) ,
350- (
351- anstyle:: AnsiColor :: Green . on( anstyle:: AnsiColor :: Red ) ,
352- "world!" ,
353- ) ,
346+ ( green_on_red, "world!" ) ,
354347 ] ;
355348 verify ( & input, expected) ;
356349 }
357350
358351 #[ test]
359352 fn ansi256_colors ( ) {
353+ let ansi_11 = anstyle:: Ansi256Color ( 11 ) . on_default ( ) ;
360354 // termcolor only supports "brights" via these
361- let input = format ! (
362- "Hello {}!" ,
363- "world" . color( owo_colors:: XtermColors :: UserBrightYellow )
364- ) ;
355+ let input = format ! ( "Hello {ansi_11}world{ansi_11:#}!" ) ;
365356 let expected = vec ! [
366357 ( anstyle:: Style :: default ( ) , "Hello " ) ,
367- ( anstyle :: Ansi256Color ( 11 ) . on_default ( ) , "world" ) ,
358+ ( ansi_11 , "world" ) ,
368359 ( anstyle:: Style :: default ( ) , "!" ) ,
369360 ] ;
370361 verify ( & input, expected) ;
0 commit comments