From 72e94e383ac76e623006cfdccb5eacdcad8c28ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ismael=20Gonz=C3=A1lez?= Date: Sun, 28 Nov 2021 23:00:03 +0100 Subject: [PATCH] fix: remove additional prefix on path printing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ismael González --- src/output.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/output.rs b/src/output.rs index bca0be7..3848e13 100644 --- a/src/output.rs +++ b/src/output.rs @@ -116,11 +116,12 @@ impl Printer { return; } - let source_parent = source.parent().unwrap().to_string_lossy().to_string(); - let source_name = source.file_name().unwrap().to_string_lossy().to_string(); - let target_parent = target.parent().unwrap().to_string_lossy().to_string(); + let mut source_parent = source.parent().unwrap().to_string_lossy().to_string(); + let mut source_name = source.file_name().unwrap().to_string_lossy().to_string(); + let mut target_parent = target.parent().unwrap().to_string_lossy().to_string(); let mut target_name = target.file_name().unwrap().to_string_lossy().to_string(); + // Avoid diffing if not coloring output if self.mode == PrinterMode::Color { target_name = self.string_diff( @@ -131,11 +132,20 @@ impl Printer { ) } + source_name = self.colors.source.paint(&source_name).to_string(); + + if source_parent != "" { + source_parent = self.colors.source.paint(format!("{}/", source_parent)).to_string(); + } + if target_parent != "" { + target_parent = self.colors.target.paint(format!("{}/", target_parent)).to_string(); + } + self.print(&format!( "{}{} -> {}{}", - self.colors.source.paint(format!("{}/", source_parent)), - self.colors.source.paint(&source_name), - self.colors.target.paint(format!("{}/", target_parent)), + source_parent, + source_name, + target_parent, target_name )); }