diff --git a/src/compare/diff.rs b/src/compare/diff.rs index cde5e2d..6faf7e0 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -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>(