diff --git a/src/column.rs b/src/column.rs index 210e69e..74d449d 100644 --- a/src/column.rs +++ b/src/column.rs @@ -5,7 +5,6 @@ use ansi_term::Style; #[derive(PartialEq, Debug, Copy)] pub enum Column { Permissions, - FileName, FileSize(SizeFormat), Blocks, User, @@ -49,7 +48,6 @@ impl Column { pub fn header(&self) -> &'static str { match *self { Column::Permissions => "Permissions", - Column::FileName => "Name", Column::FileSize(_) => "Size", Column::Blocks => "Blocks", Column::User => "User", diff --git a/src/file.rs b/src/file.rs index 850a066..6d259c0 100644 --- a/src/file.rs +++ b/src/file.rs @@ -94,7 +94,6 @@ impl<'a> File<'a> { pub fn display(&self, column: &Column, users_cache: &mut U) -> Cell { match *column { Permissions => self.permissions_string(), - FileName => self.file_name_view(), FileSize(f) => self.file_size(f), HardLinks => self.hard_links(), Inode => self.inode(), @@ -110,15 +109,12 @@ impl<'a> File<'a> { /// /// It consists of the file name coloured in the appropriate style, /// with special formatting for a symlink. - pub fn file_name_view(&self) -> Cell { + pub fn file_name_view(&self) -> String { if self.stat.kind == io::FileType::Symlink { self.symlink_file_name_view() } else { - Cell { - length: 0, // This length is ignored (rightmost column) - text: self.file_colour().paint(&*self.name).to_string(), - } + self.file_colour().paint(&*self.name).to_string() } } @@ -130,7 +126,7 @@ impl<'a> File<'a> { /// an error, highlight the target and arrow in red. The error would /// be shown out of context, and it's almost always because the /// target doesn't exist. - fn symlink_file_name_view(&self) -> Cell { + fn symlink_file_name_view(&self) -> String { let name = &*self.name; let style = self.file_colour(); @@ -141,26 +137,20 @@ impl<'a> File<'a> { }; match self.target_file(&target_path) { - Ok(file) => Cell { - length: 0, // These lengths are never actually used... - text: format!("{} {} {}{}{}", - style.paint(name), - GREY.paint("=>"), - Cyan.paint(target_path.dirname_str().unwrap()), - Cyan.paint("/"), - file.file_colour().paint(file.name.as_slice())), - }, - Err(filename) => Cell { - length: 0, // ...because the rightmost column lengths are ignored! - text: format!("{} {} {}", - style.paint(name), - Red.paint("=>"), - Red.underline().paint(filename.as_slice())), - }, + Ok(file) => format!("{} {} {}{}{}", + style.paint(name), + GREY.paint("=>"), + Cyan.paint(target_path.dirname_str().unwrap()), + Cyan.paint("/"), + file.file_colour().paint(file.name.as_slice())), + Err(filename) => format!("{} {} {}", + style.paint(name), + Red.paint("=>"), + Red.underline().paint(filename.as_slice())), } } else { - Cell::paint(style, name) + style.paint(name).to_string() } } diff --git a/src/options.rs b/src/options.rs index d9d819e..f18083b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -307,7 +307,6 @@ impl Columns { } } - columns.push(FileName); columns } } diff --git a/src/output.rs b/src/output.rs index 135b0b3..76fb077 100644 --- a/src/output.rs +++ b/src/output.rs @@ -30,7 +30,7 @@ impl View { /// The lines view literally just displays each file, line-by-line. fn lines_view(files: &[File]) { for file in files.iter() { - println!("{}", file.file_name_view().text); + println!("{}", file.file_name_view()); } } @@ -137,7 +137,8 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool) { if header { let row = Row { depth: 0, - cells: columns.iter().map(|c| Cell::paint(Plain.underline(), c.header())).collect() + cells: columns.iter().map(|c| Cell::paint(Plain.underline(), c.header())).collect(), + name: Plain.underline().paint("Name").to_string() }; table.insert(0, row); @@ -148,25 +149,20 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool) { .collect(); for row in table.iter() { - for _ in range(0, row.depth) { - print!("#"); - } - for (num, column) in columns.iter().enumerate() { - if num != 0 { - print!(" "); // Separator + let padding = column_widths[num] - row.cells[num].length; + print!("{} ", column.alignment().pad_string(&row.cells[num].text, padding)); + } + + if tree { + for _ in range(0, row.depth) { + print!("#"); } - if num == columns.len() - 1 { - // The final column doesn't need to have trailing spaces - print!("{}", row.cells[num].text); - } - else { - let padding = column_widths[num] - row.cells[num].length; - print!("{}", column.alignment().pad_string(&row.cells[num].text, padding)); - } + print!(" "); } - print!("\n"); + + print!("{}\n", row.name); } } @@ -176,6 +172,7 @@ fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut let row = Row { depth: depth, cells: columns.iter().map(|c| file.display(c, cache)).collect(), + name: file.file_name_view(), }; dest.push(row); @@ -191,4 +188,5 @@ fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut struct Row { pub depth: u8, pub cells: Vec, + pub name: String, }