@@ -594,9 +594,9 @@ static void replace(std::string& source, const std::unordered_map<std::string, s
594594 }
595595}
596596
597- static void replaceColors (std::string& source) {
597+ static void replaceColors (std::string& source, bool erase ) {
598598 // 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> substitutionMap =
599+ static const std::unordered_map<std::string, std::string> substitutionMapReplace =
600600 {
601601 {" {reset}" , ::toString (Color::Reset)},
602602 {" {bold}" , ::toString (Color::Bold)},
@@ -607,7 +607,21 @@ static void replaceColors(std::string& source) {
607607 {" {magenta}" , ::toString (Color::FgMagenta)},
608608 {" {default}" , ::toString (Color::FgDefault)},
609609 };
610- replace (source, substitutionMap);
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);
611625}
612626
613627std::string ErrorMessage::toString (bool verbose, const std::string &templateFormat, const std::string &templateLocation) const
@@ -916,16 +930,16 @@ std::string replaceStr(std::string s, const std::string &from, const std::string
916930 return s;
917931}
918932
919- void substituteTemplateFormatStatic (std::string& templateFormat)
933+ void substituteTemplateFormatStatic (std::string& templateFormat, bool eraseColors )
920934{
921935 replaceSpecialChars (templateFormat);
922- replaceColors (templateFormat);
936+ replaceColors (templateFormat, eraseColors );
923937}
924938
925- void substituteTemplateLocationStatic (std::string& templateLocation)
939+ void substituteTemplateLocationStatic (std::string& templateLocation, bool eraseColors )
926940{
927941 replaceSpecialChars (templateLocation);
928- replaceColors (templateLocation);
942+ replaceColors (templateLocation, eraseColors );
929943}
930944
931945std::string getClassification (const std::string &guideline, ReportType reportType) {
0 commit comments