From 9f6376a560df56c40b7f3753bebec8c52410432c Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 7 May 2017 14:45:04 +0100 Subject: [PATCH] Give broken links a different style in grid view Because the link style and status are now both available to the function that picks the colour style, we can have it highlight broken links differently. Fixes #131. --- src/fs/file.rs | 10 ++++++++++ src/output/file_name.rs | 11 ++++++++++- xtests/file_names_R | 2 +- xtests/links | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 2966d96..921e7e1 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -412,6 +412,16 @@ pub enum FileTarget<'dir> { Err(IOError), } +impl<'dir> FileTarget<'dir> { + pub fn is_broken(&self) -> bool { + match self { + &FileTarget::Ok(_) => false, + &FileTarget::Broken(_) => true, + &FileTarget::Err(_) => true, + } + } +} + #[cfg(test)] mod test { diff --git a/src/output/file_name.rs b/src/output/file_name.rs index 007c7ac..c39f166 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -8,6 +8,7 @@ use output::escape; use output::cell::TextCellContents; +#[derive(PartialEq, Debug, Copy, Clone)] pub enum LinkStyle { JustFilenames, FullLinkPaths, @@ -48,7 +49,7 @@ impl<'a, 'dir> FileName<'a, 'dir> { } } - if let (&LinkStyle::FullLinkPaths, Some(ref target)) = (&self.link_style, self.target.as_ref()) { + if let (LinkStyle::FullLinkPaths, Some(ref target)) = (self.link_style, self.target.as_ref()) { match **target { FileTarget::Ok(ref target) => { bits.push(Style::default().paint(" ")); @@ -138,6 +139,14 @@ impl<'a, 'dir> FileName<'a, 'dir> { } pub fn style(&self) -> Style { + if let LinkStyle::JustFilenames = self.link_style { + if let Some(ref target) = self.target { + if target.is_broken() { + return self.colours.broken_arrow; + } + } + } + match self.file { f if f.is_directory() => self.colours.filetypes.directory, f if f.is_executable_file() => self.colours.filetypes.executable, diff --git a/xtests/file_names_R b/xtests/file_names_R index 7b7c9fe..be489cb 100644 --- a/xtests/file_names_R +++ b/xtests/file_names_R @@ -6,7 +6,7 @@ emoji: [🆒] invalid-utf8-4: [�(�(] utf-8: pâté escape: [\u{1b}] links vertical-tab: [\u{b}] /testcases/file-names/links: -another: [\n] broken subfile +another: [\n] broken subfile /testcases/file-names/new-line-dir: [\n]: another: [\n] subfile diff --git a/xtests/links b/xtests/links index 38dfcfc..fa5c79d 100644 --- a/xtests/links +++ b/xtests/links @@ -1,2 +1,2 @@ -broken forbidden parent_dir some_file some_file_relative -current_dir itself root some_file_absolute usr +broken forbidden parent_dir some_file some_file_relative +current_dir itself root some_file_absolute usr