@@ -594,35 +594,34 @@ static void replace(std::string& source, const std::unordered_map<std::string, s
594594 }
595595}
596596
597- static void replaceColors (std::string& source, bool enableColors) {
598- if (enableColors) {
599- static const std::unordered_map<std::string, std::string> substitutionMap =
600- {
601- {" {reset}" , ::toString (Color::Reset)},
602- {" {bold}" , ::toString (Color::Bold)},
603- {" {dim}" , ::toString (Color::Dim)},
604- {" {red}" , ::toString (Color::FgRed)},
605- {" {green}" , ::toString (Color::FgGreen)},
606- {" {blue}" , ::toString (Color::FgBlue)},
607- {" {magenta}" , ::toString (Color::FgMagenta)},
608- {" {default}" , ::toString (Color::FgDefault)},
609- };
610- replace (source, substitutionMap);
611- }
612- else {
613- static const std::unordered_map<std::string, std::string> substitutionMap =
614- {
615- {" {reset}" , " " },
616- {" {bold}" , " " },
617- {" {dim}" , " " },
618- {" {red}" , " " },
619- {" {green}" , " " },
620- {" {blue}" , " " },
621- {" {magenta}" , " " },
622- {" {default}" , " " },
623- };
624- replace (source, substitutionMap);
625- }
597+ static void replaceColors (std::string& source, bool erase) {
598+ // TODO: colors are not applied when either stdout or stderr is not a TTY because we resolve them before the stream usage
599+ static const std::unordered_map<std::string, std::string> substitutionMapReplace =
600+ {
601+ {" {reset}" , ::toString (Color::Reset)},
602+ {" {bold}" , ::toString (Color::Bold)},
603+ {" {dim}" , ::toString (Color::Dim)},
604+ {" {red}" , ::toString (Color::FgRed)},
605+ {" {green}" , ::toString (Color::FgGreen)},
606+ {" {blue}" , ::toString (Color::FgBlue)},
607+ {" {magenta}" , ::toString (Color::FgMagenta)},
608+ {" {default}" , ::toString (Color::FgDefault)},
609+ };
610+ static const std::unordered_map<std::string, std::string> substitutionMapErase =
611+ {
612+ {" {reset}" , " " },
613+ {" {bold}" , " " },
614+ {" {dim}" , " " },
615+ {" {red}" , " " },
616+ {" {green}" , " " },
617+ {" {blue}" , " " },
618+ {" {magenta}" , " " },
619+ {" {default}" , " " },
620+ };
621+ if (!erase)
622+ replace (source, substitutionMapReplace);
623+ else
624+ replace (source, substitutionMapErase);
626625}
627626
628627std::string ErrorMessage::toString (bool verbose, const std::string &templateFormat, const std::string &templateLocation) const
@@ -928,16 +927,16 @@ std::string replaceStr(std::string s, const std::string &from, const std::string
928927 return s;
929928}
930929
931- void substituteTemplateFormatStatic (std::string& templateFormat, bool enableColors )
930+ void substituteTemplateFormatStatic (std::string& templateFormat, bool eraseColors )
932931{
933932 replaceSpecialChars (templateFormat);
934- replaceColors (templateFormat, enableColors );
933+ replaceColors (templateFormat, eraseColors );
935934}
936935
937- void substituteTemplateLocationStatic (std::string& templateLocation, bool enableColors )
936+ void substituteTemplateLocationStatic (std::string& templateLocation, bool eraseColors )
938937{
939938 replaceSpecialChars (templateLocation);
940- replaceColors (templateLocation, enableColors );
939+ replaceColors (templateLocation, eraseColors );
941940}
942941
943942std::string getClassification (const std::string &guideline, ReportType reportType) {
0 commit comments