mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-10 14:50:57 +00:00
Make filename not a column
FileName was always a special-cased column, as it was assumed to be the last column in the output. Now, it's explicitly marked as such. This allows the hash marks to be placed before the filename, rather than at the start of the line.
This commit is contained in:
parent
f825397912
commit
827a1e11fd
@ -5,7 +5,6 @@ use ansi_term::Style;
|
|||||||
#[derive(PartialEq, Debug, Copy)]
|
#[derive(PartialEq, Debug, Copy)]
|
||||||
pub enum Column {
|
pub enum Column {
|
||||||
Permissions,
|
Permissions,
|
||||||
FileName,
|
|
||||||
FileSize(SizeFormat),
|
FileSize(SizeFormat),
|
||||||
Blocks,
|
Blocks,
|
||||||
User,
|
User,
|
||||||
@ -49,7 +48,6 @@ impl Column {
|
|||||||
pub fn header(&self) -> &'static str {
|
pub fn header(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
Column::Permissions => "Permissions",
|
Column::Permissions => "Permissions",
|
||||||
Column::FileName => "Name",
|
|
||||||
Column::FileSize(_) => "Size",
|
Column::FileSize(_) => "Size",
|
||||||
Column::Blocks => "Blocks",
|
Column::Blocks => "Blocks",
|
||||||
Column::User => "User",
|
Column::User => "User",
|
||||||
|
38
src/file.rs
38
src/file.rs
@ -94,7 +94,6 @@ impl<'a> File<'a> {
|
|||||||
pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U) -> Cell {
|
pub fn display<U: Users>(&self, column: &Column, users_cache: &mut U) -> Cell {
|
||||||
match *column {
|
match *column {
|
||||||
Permissions => self.permissions_string(),
|
Permissions => self.permissions_string(),
|
||||||
FileName => self.file_name_view(),
|
|
||||||
FileSize(f) => self.file_size(f),
|
FileSize(f) => self.file_size(f),
|
||||||
HardLinks => self.hard_links(),
|
HardLinks => self.hard_links(),
|
||||||
Inode => self.inode(),
|
Inode => self.inode(),
|
||||||
@ -110,15 +109,12 @@ impl<'a> File<'a> {
|
|||||||
///
|
///
|
||||||
/// It consists of the file name coloured in the appropriate style,
|
/// It consists of the file name coloured in the appropriate style,
|
||||||
/// with special formatting for a symlink.
|
/// 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 {
|
if self.stat.kind == io::FileType::Symlink {
|
||||||
self.symlink_file_name_view()
|
self.symlink_file_name_view()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cell {
|
self.file_colour().paint(&*self.name).to_string()
|
||||||
length: 0, // This length is ignored (rightmost column)
|
|
||||||
text: 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
|
/// an error, highlight the target and arrow in red. The error would
|
||||||
/// be shown out of context, and it's almost always because the
|
/// be shown out of context, and it's almost always because the
|
||||||
/// target doesn't exist.
|
/// target doesn't exist.
|
||||||
fn symlink_file_name_view(&self) -> Cell {
|
fn symlink_file_name_view(&self) -> String {
|
||||||
let name = &*self.name;
|
let name = &*self.name;
|
||||||
let style = self.file_colour();
|
let style = self.file_colour();
|
||||||
|
|
||||||
@ -141,26 +137,20 @@ impl<'a> File<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match self.target_file(&target_path) {
|
match self.target_file(&target_path) {
|
||||||
Ok(file) => Cell {
|
Ok(file) => format!("{} {} {}{}{}",
|
||||||
length: 0, // These lengths are never actually used...
|
style.paint(name),
|
||||||
text: format!("{} {} {}{}{}",
|
GREY.paint("=>"),
|
||||||
style.paint(name),
|
Cyan.paint(target_path.dirname_str().unwrap()),
|
||||||
GREY.paint("=>"),
|
Cyan.paint("/"),
|
||||||
Cyan.paint(target_path.dirname_str().unwrap()),
|
file.file_colour().paint(file.name.as_slice())),
|
||||||
Cyan.paint("/"),
|
Err(filename) => format!("{} {} {}",
|
||||||
file.file_colour().paint(file.name.as_slice())),
|
style.paint(name),
|
||||||
},
|
Red.paint("=>"),
|
||||||
Err(filename) => Cell {
|
Red.underline().paint(filename.as_slice())),
|
||||||
length: 0, // ...because the rightmost column lengths are ignored!
|
|
||||||
text: format!("{} {} {}",
|
|
||||||
style.paint(name),
|
|
||||||
Red.paint("=>"),
|
|
||||||
Red.underline().paint(filename.as_slice())),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Cell::paint(style, name)
|
style.paint(name).to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,6 @@ impl Columns {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
columns.push(FileName);
|
|
||||||
columns
|
columns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl View {
|
|||||||
/// The lines view literally just displays each file, line-by-line.
|
/// The lines view literally just displays each file, line-by-line.
|
||||||
fn lines_view(files: &[File]) {
|
fn lines_view(files: &[File]) {
|
||||||
for file in files.iter() {
|
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 {
|
if header {
|
||||||
let row = Row {
|
let row = Row {
|
||||||
depth: 0,
|
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);
|
table.insert(0, row);
|
||||||
@ -148,25 +149,20 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool) {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for row in table.iter() {
|
for row in table.iter() {
|
||||||
for _ in range(0, row.depth) {
|
|
||||||
print!("#");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (num, column) in columns.iter().enumerate() {
|
for (num, column) in columns.iter().enumerate() {
|
||||||
if num != 0 {
|
let padding = column_widths[num] - row.cells[num].length;
|
||||||
print!(" "); // Separator
|
print!("{} ", column.alignment().pad_string(&row.cells[num].text, padding));
|
||||||
|
}
|
||||||
|
|
||||||
|
if tree {
|
||||||
|
for _ in range(0, row.depth) {
|
||||||
|
print!("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
if num == columns.len() - 1 {
|
print!(" ");
|
||||||
// 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!("\n");
|
|
||||||
|
print!("{}\n", row.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,6 +172,7 @@ fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut
|
|||||||
let row = Row {
|
let row = Row {
|
||||||
depth: depth,
|
depth: depth,
|
||||||
cells: columns.iter().map(|c| file.display(c, cache)).collect(),
|
cells: columns.iter().map(|c| file.display(c, cache)).collect(),
|
||||||
|
name: file.file_name_view(),
|
||||||
};
|
};
|
||||||
|
|
||||||
dest.push(row);
|
dest.push(row);
|
||||||
@ -191,4 +188,5 @@ fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut
|
|||||||
struct Row {
|
struct Row {
|
||||||
pub depth: u8,
|
pub depth: u8,
|
||||||
pub cells: Vec<Cell>,
|
pub cells: Vec<Cell>,
|
||||||
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user