Use constant ANSI code to reset boldfaced colors in reporting for CHECK and TEST command. Remove unused color_reset constant.

This commit is contained in:
Norman Jäckel 2024-03-06 00:47:34 +01:00
parent d232a843e4
commit cfb068ec94
No known key found for this signature in database
GPG key ID: 85884FB77E7B6E5B
3 changed files with 7 additions and 6 deletions

View file

@ -575,8 +575,10 @@ pub fn test(matches: &ArgMatches, triple: Triple) -> io::Result<i32> {
let passed_color = ANSI_STYLE_CODES.green;
let reset = ANSI_STYLE_CODES.reset;
println!(
"\n{failed_color}{failed_count}\x1B[39m failed and {passed_color}{passed_count}\x1B[39m passed in {} ms.\n",
"\n{failed_color}{failed_count}{reset} failed and {passed_color}{passed_count}{reset} passed in {} ms.\n",
total_time.as_millis(),
);

View file

@ -31,14 +31,16 @@ impl Problems {
pub fn print_error_warning_count(&self, total_time: std::time::Duration) {
const GREEN: &str = ANSI_STYLE_CODES.green;
const YELLOW: &str = ANSI_STYLE_CODES.yellow;
const RESET: &str = ANSI_STYLE_CODES.reset;
println!(
"{}{}\x1B[39m {} and {}{}\x1B[39m {} found in {} ms",
"{}{}{} {} and {}{}{} {} found in {} ms",
match self.errors {
0 => GREEN,
_ => YELLOW,
},
self.errors,
RESET,
match self.errors {
1 => "error",
_ => "errors",
@ -48,6 +50,7 @@ impl Problems {
_ => YELLOW,
},
self.warnings,
RESET,
match self.warnings {
1 => "warning",
_ => "warnings",

View file

@ -254,7 +254,6 @@ pub struct StyleCodes {
pub bold: &'static str,
pub underline: &'static str,
pub reset: &'static str,
pub color_reset: &'static str,
}
pub const ANSI_STYLE_CODES: StyleCodes = StyleCodes {
@ -266,7 +265,6 @@ pub const ANSI_STYLE_CODES: StyleCodes = StyleCodes {
bold: "\u{001b}[1m",
underline: "\u{001b}[4m",
reset: "\u{001b}[0m",
color_reset: "\u{1b}[39m",
};
macro_rules! html_color {
@ -284,7 +282,6 @@ pub const HTML_STYLE_CODES: StyleCodes = StyleCodes {
bold: "<span class='bold'>",
underline: "<span class='underline'>",
reset: "</span>",
color_reset: "</span>",
};
// useful for tests
@ -297,7 +294,6 @@ pub fn strip_colors(str: &str) -> String {
.replace(ANSI_STYLE_CODES.bold, "")
.replace(ANSI_STYLE_CODES.underline, "")
.replace(ANSI_STYLE_CODES.reset, "")
.replace(ANSI_STYLE_CODES.color_reset, "")
}
// define custom allocator struct so we can `impl RocDocAllocator` custom helpers