소스 검색

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.
Benjamin Sago 8 년 전
부모
커밋
9f6376a560
4개의 변경된 파일23개의 추가작업 그리고 4개의 파일을 삭제
  1. 10 0
      src/fs/file.rs
  2. 10 1
      src/output/file_name.rs
  3. 1 1
      xtests/file_names_R
  4. 2 2
      xtests/links

+ 10 - 0
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 {

+ 10 - 1
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,

+ 1 - 1
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

+ 2 - 2
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