From 7531b2617cde350f69cb4a2db8609efd12a67a78 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Mon, 1 May 2017 15:39:55 +0100 Subject: [PATCH] Split out function for --classify character --- src/output/file_name.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/output/file_name.rs b/src/output/file_name.rs index e32fad0..9f9080e 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -76,23 +76,32 @@ impl<'a, 'dir> FileName<'a, 'dir> { // Do nothing -- the error gets displayed on the next line } } - } else if classify { - if self.file.is_executable_file() { - bits.push(Style::default().paint("*")); - } else if self.file.is_directory() { - bits.push(Style::default().paint("/")); - } else if self.file.is_pipe() { - bits.push(Style::default().paint("|")); - } else if self.file.is_link() { - bits.push(Style::default().paint("@")); - } else if self.file.is_socket() { - bits.push(Style::default().paint("=")); + } + else if classify { + if let Some(class) = self.classify_char() { + bits.push(Style::default().paint(class)); } } bits.into() } + fn classify_char(&self) -> Option<&'static str> { + if self.file.is_executable_file() { + Some("*") + } else if self.file.is_directory() { + Some("/") + } else if self.file.is_pipe() { + Some("|") + } else if self.file.is_link() { + Some("@") + } else if self.file.is_socket() { + Some("=") + } else { + None + } + } + /// Returns at least one ANSI-highlighted string representing this file’s /// name using the given set of colours. ///