Add color to compare output.
This commit is contained in:
parent
19432d91ab
commit
5134cece7b
@ -84,12 +84,24 @@ impl DiffResult {
|
||||
match self.status {
|
||||
DiffStatus::Good => {
|
||||
if self.has_bad_children() {
|
||||
"BADCHILD"
|
||||
format!(
|
||||
"{color}BADCHILD{reset}",
|
||||
color = DiffResult::foreground_color(255, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
)
|
||||
} else {
|
||||
"GOOD"
|
||||
format!(
|
||||
"{color}GOOD{reset}",
|
||||
color = DiffResult::foreground_color(0, 255, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
)
|
||||
}
|
||||
}
|
||||
DiffStatus::Bad => "BAD",
|
||||
DiffStatus::Bad => format!(
|
||||
"{color}BAD{reset}",
|
||||
color = DiffResult::foreground_color(255, 0, 0),
|
||||
reset = DiffResult::reset_color(),
|
||||
),
|
||||
}
|
||||
};
|
||||
println!(
|
||||
@ -117,6 +129,29 @@ impl DiffResult {
|
||||
DiffStatus::Bad => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn foreground_color(red: u8, green: u8, blue: u8) -> String {
|
||||
format!(
|
||||
"\x1b[38;2;{red};{green};{blue}m",
|
||||
red = red,
|
||||
green = green,
|
||||
blue = blue
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn background_color(red: u8, green: u8, blue: u8) -> String {
|
||||
format!(
|
||||
"\x1b[48;2;{red};{green};{blue}m",
|
||||
red = red,
|
||||
green = green,
|
||||
blue = blue
|
||||
)
|
||||
}
|
||||
|
||||
fn reset_color() -> &'static str {
|
||||
"\x1b[0m"
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_element<'s>(
|
||||
|
Loading…
Reference in New Issue
Block a user