Make the link target a field

This commit is contained in:
Benjamin Sago 2017-05-07 10:44:09 +01:00
parent 897d6ffa56
commit 88fecb7b26

View File

@ -11,13 +11,17 @@ use output::cell::TextCellContents;
pub struct FileName<'a, 'dir: 'a> { pub struct FileName<'a, 'dir: 'a> {
file: &'a File<'dir>, file: &'a File<'dir>,
colours: &'a Colours, colours: &'a Colours,
target: Option<FileTarget<'dir>>,
} }
impl<'a, 'dir> FileName<'a, 'dir> { impl<'a, 'dir> FileName<'a, 'dir> {
pub fn new(file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> { pub fn new(file: &'a File<'dir>, colours: &'a Colours) -> FileName<'a, 'dir> {
let target = if file.is_link() { Some(file.link_target()) }
else { None };
FileName { FileName {
file: file, file: file,
colours: colours, colours: colours,
target: target,
} }
} }
@ -36,9 +40,9 @@ impl<'a, 'dir> FileName<'a, 'dir> {
} }
} }
if links && self.file.is_link() { if links && self.target.is_some() {
match self.file.link_target() { match self.target.as_ref().unwrap() {
FileTarget::Ok(target) => { &FileTarget::Ok(ref target) => {
bits.push(Style::default().paint(" ")); bits.push(Style::default().paint(" "));
bits.push(self.colours.punctuation.paint("->")); bits.push(self.colours.punctuation.paint("->"));
bits.push(Style::default().paint(" ")); bits.push(Style::default().paint(" "));
@ -55,16 +59,16 @@ impl<'a, 'dir> FileName<'a, 'dir> {
} }
}, },
FileTarget::Broken(broken_path) => { &FileTarget::Broken(ref broken_path) => {
bits.push(Style::default().paint(" ")); bits.push(Style::default().paint(" "));
bits.push(self.colours.broken_arrow.paint("->")); bits.push(self.colours.broken_arrow.paint("->"));
bits.push(Style::default().paint(" ")); bits.push(Style::default().paint(" "));
escape(broken_path.display().to_string(), &mut bits, self.colours.broken_filename, self.colours.control_char.underline()); escape(broken_path.display().to_string(), &mut bits, self.colours.broken_filename, self.colours.control_char.underline());
}, },
FileTarget::Err(_) => { &FileTarget::Err(_) => {
// Do nothing -- the error gets displayed on the next line // Do nothing -- the error gets displayed on the next line
} },
} }
} }
else if classify { else if classify {