@@ -491,33 +491,46 @@ String gray(text) {
491491/// that supports that. 
492492/// 
493493/// Use this to highlight something interesting but neither good nor bad. 
494- String  cyan (text) =>  sparkle  ?   "$ text "   :   "$ _cyan $ text $ _noColor " 
494+ String  cyan (text) =>  _addColor ( text,  _cyan) ;
495495
496496/// Wraps [text]  in the ANSI escape codes to color it green when on a platform 
497497/// that supports that. 
498498/// 
499499/// Use this to highlight something successful or otherwise positive. 
500- String  green (text) =>  sparkle  ?   "$ text "   :   "$ _green $ text $ _noColor " 
500+ String  green (text) =>  _addColor ( text,  _green) ;
501501
502502/// Wraps [text]  in the ANSI escape codes to color it magenta when on a 
503503/// platform that supports that. 
504504/// 
505505/// Use this to highlight something risky that the user should be aware of but 
506506/// may intend to do. 
507- String  magenta (text) =>  sparkle  ?   "$ text "   :   "$ _magenta $ text $ _noColor " 
507+ String  magenta (text) =>  _addColor ( text,  _magenta) ;
508508
509509/// Wraps [text]  in the ANSI escape codes to color it red when on a platform 
510510/// that supports that. 
511511/// 
512512/// Use this to highlight unequivocal errors, problems, or failures. 
513- String  red (text) =>  sparkle  ?   "$ text "   :   "$ _red $ text $ _noColor " 
513+ String  red (text) =>  _addColor ( text,  _red) ;
514514
515515/// Wraps [text]  in the ANSI escape codes to color it yellow when on a platform 
516516/// that supports that. 
517517/// 
518518/// Use this to highlight warnings, cautions or other things that are bad but 
519519/// do not prevent the user's goal from being reached. 
520- String  yellow (text) =>  sparkle ?  "$text "  :  "$_yellow $text $_noColor " ;
520+ String  yellow (text) =>  _addColor (text, _yellow);
521+ 
522+ /// Returns [text]  colored using the given [colorCode] . 
523+ /// 
524+ /// This is resilient to the text containing other colors or bold text. 
525+ String  _addColor (Object  text, String  colorCode) {
526+   if  (sparkle) return  text.toString ();
527+   return  colorCode + 
528+       text
529+           .toString ()
530+           .replaceAll (_none, _none +  colorCode)
531+           .replaceAll (_noColor, _none +  colorCode) + 
532+       _noColor;
533+ }
521534
522535/// Log function that prints the message to stdout. 
523536void  _logToStdout (Entry  entry) {
0 commit comments