@@ -2,10 +2,12 @@ use std::fmt;
22use std:: io:: prelude:: * ;
33use std:: io:: IsTerminal ;
44
5- use termcolor:: Color :: { Cyan , Green , Red , Yellow } ;
6- use termcolor:: { self , Color , ColorSpec , StandardStream , WriteColor } ;
5+ use anstyle:: Style ;
6+ use anstyle_termcolor:: to_termcolor_spec;
7+ use termcolor:: { self , StandardStream , WriteColor } ;
78
89use crate :: util:: errors:: CargoResult ;
10+ use crate :: util:: style:: * ;
911
1012pub enum TtyWidth {
1113 NoTty ,
@@ -130,7 +132,7 @@ impl Shell {
130132 & mut self ,
131133 status : & dyn fmt:: Display ,
132134 message : Option < & dyn fmt:: Display > ,
133- color : Color ,
135+ color : & Style ,
134136 justified : bool ,
135137 ) -> CargoResult < ( ) > {
136138 match self . verbosity {
@@ -203,22 +205,22 @@ impl Shell {
203205 T : fmt:: Display ,
204206 U : fmt:: Display ,
205207 {
206- self . print ( & status, Some ( & message) , Green , true )
208+ self . print ( & status, Some ( & message) , & HEADER , true )
207209 }
208210
209211 pub fn status_header < T > ( & mut self , status : T ) -> CargoResult < ( ) >
210212 where
211213 T : fmt:: Display ,
212214 {
213- self . print ( & status, None , Cyan , true )
215+ self . print ( & status, None , & NOTE , true )
214216 }
215217
216218 /// Shortcut to right-align a status message.
217219 pub fn status_with_color < T , U > (
218220 & mut self ,
219221 status : T ,
220222 message : U ,
221- color : Color ,
223+ color : & Style ,
222224 ) -> CargoResult < ( ) >
223225 where
224226 T : fmt:: Display ,
@@ -255,20 +257,20 @@ impl Shell {
255257 self . err_erase_line ( ) ;
256258 }
257259 self . output
258- . message_stderr ( & "error" , Some ( & message) , Red , false )
260+ . message_stderr ( & "error" , Some ( & message) , & ERROR , false )
259261 }
260262
261263 /// Prints an amber 'warning' message.
262264 pub fn warn < T : fmt:: Display > ( & mut self , message : T ) -> CargoResult < ( ) > {
263265 match self . verbosity {
264266 Verbosity :: Quiet => Ok ( ( ) ) ,
265- _ => self . print ( & "warning" , Some ( & message) , Yellow , false ) ,
267+ _ => self . print ( & "warning" , Some ( & message) , & WARN , false ) ,
266268 }
267269 }
268270
269271 /// Prints a cyan 'note' message.
270272 pub fn note < T : fmt:: Display > ( & mut self , message : T ) -> CargoResult < ( ) > {
271- self . print ( & "note" , Some ( & message) , Cyan , false )
273+ self . print ( & "note" , Some ( & message) , & NOTE , false )
272274 }
273275
274276 /// Updates the verbosity of the shell.
@@ -338,22 +340,14 @@ impl Shell {
338340 /// Write a styled fragment
339341 ///
340342 /// Caller is responsible for deciding whether [`Shell::verbosity`] is affects output.
341- pub fn write_stdout (
342- & mut self ,
343- fragment : impl fmt:: Display ,
344- color : & ColorSpec ,
345- ) -> CargoResult < ( ) > {
343+ pub fn write_stdout ( & mut self , fragment : impl fmt:: Display , color : & Style ) -> CargoResult < ( ) > {
346344 self . output . write_stdout ( fragment, color)
347345 }
348346
349347 /// Write a styled fragment
350348 ///
351349 /// Caller is responsible for deciding whether [`Shell::verbosity`] is affects output.
352- pub fn write_stderr (
353- & mut self ,
354- fragment : impl fmt:: Display ,
355- color : & ColorSpec ,
356- ) -> CargoResult < ( ) > {
350+ pub fn write_stderr ( & mut self , fragment : impl fmt:: Display , color : & Style ) -> CargoResult < ( ) > {
357351 self . output . write_stderr ( fragment, color)
358352 }
359353
@@ -412,18 +406,18 @@ impl ShellOut {
412406 & mut self ,
413407 status : & dyn fmt:: Display ,
414408 message : Option < & dyn fmt:: Display > ,
415- color : Color ,
409+ style : & Style ,
416410 justified : bool ,
417411 ) -> CargoResult < ( ) > {
418412 match * self {
419413 ShellOut :: Stream { ref mut stderr, .. } => {
420414 stderr. reset ( ) ?;
421- stderr. set_color ( ColorSpec :: new ( ) . set_bold ( true ) . set_fg ( Some ( color ) ) ) ?;
415+ stderr. set_color ( & to_termcolor_spec ( * style ) ) ?;
422416 if justified {
423417 write ! ( stderr, "{:>12}" , status) ?;
424418 } else {
425419 write ! ( stderr, "{}" , status) ?;
426- stderr. set_color ( ColorSpec :: new ( ) . set_bold ( true ) ) ?;
420+ stderr. set_color ( termcolor :: ColorSpec :: new ( ) . set_bold ( true ) ) ?;
427421 write ! ( stderr, ":" ) ?;
428422 }
429423 stderr. reset ( ) ?;
@@ -448,11 +442,11 @@ impl ShellOut {
448442 }
449443
450444 /// Write a styled fragment
451- fn write_stdout ( & mut self , fragment : impl fmt:: Display , color : & ColorSpec ) -> CargoResult < ( ) > {
445+ fn write_stdout ( & mut self , fragment : impl fmt:: Display , color : & Style ) -> CargoResult < ( ) > {
452446 match * self {
453447 ShellOut :: Stream { ref mut stdout, .. } => {
454448 stdout. reset ( ) ?;
455- stdout. set_color ( & color) ?;
449+ stdout. set_color ( & to_termcolor_spec ( * color) ) ?;
456450 write ! ( stdout, "{}" , fragment) ?;
457451 stdout. reset ( ) ?;
458452 }
@@ -464,11 +458,11 @@ impl ShellOut {
464458 }
465459
466460 /// Write a styled fragment
467- fn write_stderr ( & mut self , fragment : impl fmt:: Display , color : & ColorSpec ) -> CargoResult < ( ) > {
461+ fn write_stderr ( & mut self , fragment : impl fmt:: Display , color : & Style ) -> CargoResult < ( ) > {
468462 match * self {
469463 ShellOut :: Stream { ref mut stderr, .. } => {
470464 stderr. reset ( ) ?;
471- stderr. set_color ( & color) ?;
465+ stderr. set_color ( & to_termcolor_spec ( * color) ) ?;
472466 write ! ( stderr, "{}" , fragment) ?;
473467 stderr. reset ( ) ?;
474468 }
0 commit comments