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.
This commit is contained in:
Benjamin Sago 2017-05-07 14:45:04 +01:00
parent ccf8d44058
commit 9f6376a560
4 changed files with 23 additions and 4 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -6,7 +6,7 @@ emoji: [🆒] invalid-utf8-4: [<5B>(<28>(] 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

View File

@ -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