Skip to content

Commit 9f6376a

Browse files
committed
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 ogham#131.
1 parent ccf8d44 commit 9f6376a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/fs/file.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ pub enum FileTarget<'dir> {
412412
Err(IOError),
413413
}
414414

415+
impl<'dir> FileTarget<'dir> {
416+
pub fn is_broken(&self) -> bool {
417+
match self {
418+
&FileTarget::Ok(_) => false,
419+
&FileTarget::Broken(_) => true,
420+
&FileTarget::Err(_) => true,
421+
}
422+
}
423+
}
424+
415425

416426
#[cfg(test)]
417427
mod test {

src/output/file_name.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use output::escape;
88
use output::cell::TextCellContents;
99

1010

11+
#[derive(PartialEq, Debug, Copy, Clone)]
1112
pub enum LinkStyle {
1213
JustFilenames,
1314
FullLinkPaths,
@@ -48,7 +49,7 @@ impl<'a, 'dir> FileName<'a, 'dir> {
4849
}
4950
}
5051

51-
if let (&LinkStyle::FullLinkPaths, Some(ref target)) = (&self.link_style, self.target.as_ref()) {
52+
if let (LinkStyle::FullLinkPaths, Some(ref target)) = (self.link_style, self.target.as_ref()) {
5253
match **target {
5354
FileTarget::Ok(ref target) => {
5455
bits.push(Style::default().paint(" "));
@@ -138,6 +139,14 @@ impl<'a, 'dir> FileName<'a, 'dir> {
138139
}
139140

140141
pub fn style(&self) -> Style {
142+
if let LinkStyle::JustFilenames = self.link_style {
143+
if let Some(ref target) = self.target {
144+
if target.is_broken() {
145+
return self.colours.broken_arrow;
146+
}
147+
}
148+
}
149+
141150
match self.file {
142151
f if f.is_directory() => self.colours.filetypes.directory,
143152
f if f.is_executable_file() => self.colours.filetypes.executable,

xtests/file_names_R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ emoji: [🆒] invalid-utf8-4: [�(�(] utf-8: pâté
66
escape: [\u{1b}] links vertical-tab: [\u{b}]
77

88
/testcases/file-names/links:
9-
another: [\n] broken subfile
9+
another: [\n] broken subfile
1010

1111
/testcases/file-names/new-line-dir: [\n]:
1212
another: [\n] subfile

xtests/links

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
broken forbidden parent_dir some_file some_file_relative
2-
current_dir itself root some_file_absolute usr
1+
broken forbidden parent_dir some_file some_file_relative
2+
current_dir itself root some_file_absolute usr

0 commit comments

Comments
 (0)