mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 12:05:11 +00:00
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:
parent
ccf8d44058
commit
9f6376a560
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -6,7 +6,7 @@ emoji: [🆒] invalid-utf8-4: [<5B>(<28>(] utf-8: pâté
|
||||
escape: [[31m\u{1b}[0m] [1;34mlinks[0m vertical-tab: [[31m\u{b}[0m]
|
||||
|
||||
/testcases/file-names/links:
|
||||
[36manother: [[31m\n[36m][0m [36mbroken[0m [36msubfile[0m
|
||||
[36manother: [[31m\n[36m][0m [31mbroken[0m [36msubfile[0m
|
||||
|
||||
/testcases/file-names/new-line-dir: [\n]:
|
||||
another: [[31m\n[0m] subfile
|
||||
|
@ -1,2 +1,2 @@
|
||||
[36mbroken[0m [36mforbidden[0m [36mparent_dir[0m some_file [36msome_file_relative[0m
|
||||
[36mcurrent_dir[0m [36mitself[0m [36mroot[0m [36msome_file_absolute[0m [36musr[0m
|
||||
[31mbroken[0m [31mforbidden[0m [36mparent_dir[0m some_file [36msome_file_relative[0m
|
||||
[36mcurrent_dir[0m [31mitself[0m [36mroot[0m [36msome_file_absolute[0m [36musr[0m
|
||||
|
Loading…
Reference in New Issue
Block a user