mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-09-28 21:29:02 +00:00
Replace hash marks with decent-looking tree
This commit has been brought to you by Unicode Box-Drawing Characters!
This commit is contained in:
parent
5eb9f9e414
commit
e85460998e
@ -4,7 +4,7 @@ use std::iter::{AdditiveIterator, repeat};
|
|||||||
use column::{Column, Cell};
|
use column::{Column, Cell};
|
||||||
use column::Alignment::Left;
|
use column::Alignment::Left;
|
||||||
use dir::Dir;
|
use dir::Dir;
|
||||||
use file::File;
|
use file::{File, GREY};
|
||||||
use options::{Columns, FileFilter};
|
use options::{Columns, FileFilter};
|
||||||
use users::OSUsers;
|
use users::OSUsers;
|
||||||
|
|
||||||
@ -138,7 +138,9 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool, fi
|
|||||||
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()
|
name: Plain.underline().paint("Name").to_string(),
|
||||||
|
last: false,
|
||||||
|
children: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
table.insert(0, row);
|
table.insert(0, row);
|
||||||
@ -148,6 +150,8 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool, fi
|
|||||||
.map(|n| table.iter().map(|row| row.cells[n].length).max().unwrap_or(0))
|
.map(|n| table.iter().map(|row| row.cells[n].length).max().unwrap_or(0))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let mut stack = Vec::new();
|
||||||
|
|
||||||
for row in table.iter() {
|
for row in table.iter() {
|
||||||
for (num, column) in columns.iter().enumerate() {
|
for (num, column) in columns.iter().enumerate() {
|
||||||
let padding = column_widths[num] - row.cells[num].length;
|
let padding = column_widths[num] - row.cells[num].length;
|
||||||
@ -155,24 +159,35 @@ fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool, fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tree {
|
if tree {
|
||||||
for _ in range(0, row.depth) {
|
stack.resize(row.depth + 1, "├──");
|
||||||
print!("#");
|
stack[row.depth ] = if row.last { "└──" } else { "├──" };
|
||||||
|
|
||||||
|
for i in range(1, row.depth + 1) {
|
||||||
|
print!("{}", GREY.paint(stack[i ]));
|
||||||
}
|
}
|
||||||
|
|
||||||
print!(" ");
|
if row.children {
|
||||||
|
stack[row.depth ] = if row.last { " " } else { "│ " };
|
||||||
|
}
|
||||||
|
|
||||||
|
if row.depth != 0 {
|
||||||
|
print!(" ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print!("{}\n", row.name);
|
print!("{}\n", row.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut Vec<Row>, src: &[File], depth: u8, filter: FileFilter) {
|
fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut Vec<Row>, src: &[File], depth: usize, filter: FileFilter) {
|
||||||
for file in src.iter() {
|
for (index, file) in src.iter().enumerate() {
|
||||||
|
|
||||||
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(),
|
name: file.file_name_view(),
|
||||||
|
last: index == src.len() - 1,
|
||||||
|
children: file.this.is_some(),
|
||||||
};
|
};
|
||||||
|
|
||||||
dest.push(row);
|
dest.push(row);
|
||||||
@ -187,7 +202,9 @@ fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Row {
|
struct Row {
|
||||||
pub depth: u8,
|
pub depth: usize,
|
||||||
pub cells: Vec<Cell>,
|
pub cells: Vec<Cell>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub last: bool,
|
||||||
|
pub children: bool,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user