summaryrefslogtreecommitdiffstats
path: root/src/output.rs
diff options
context:
space:
mode:
authorBen S <ogham@bsago.me>2015-02-03 13:27:23 +0000
committerBen S <ogham@bsago.me>2015-02-03 13:27:23 +0000
commit5099b3f119fabde1cfb8db798af67af3589dd9af (patch)
tree0d0d6cd74c0aed07b3441f532515781821cabe19 /src/output.rs
parent7acc1b09d50ba0bdafe9bbc08ec097e3074d8aa2 (diff)
Initial tree implementation
There's still a lot to do, but this is actually *something*. The tree hierarchy is displayed using hashes at the start of a line. I want to have it just before the filename, but this will need some changes to the way that columns are handled.
Diffstat (limited to 'src/output.rs')
-rw-r--r--src/output.rs34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/output.rs b/src/output.rs
index 52251d4..f022fb6 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -12,7 +12,7 @@ use ansi_term::Style::Plain;
#[derive(PartialEq, Copy, Debug)]
pub enum View {
- Details(Columns, bool),
+ Details(Columns, bool, bool),
Lines,
Grid(bool, usize),
}
@@ -21,7 +21,7 @@ impl View {
pub fn view(&self, dir: Option<&Dir>, files: &[File]) {
match *self {
View::Grid(across, width) => grid_view(across, width, files),
- View::Details(ref cols, header) => details_view(&*cols.for_dir(dir), files, header),
+ View::Details(ref cols, header, tree) => details_view(&*cols.for_dir(dir), files, header, tree),
View::Lines => lines_view(files),
}
}
@@ -122,7 +122,7 @@ fn grid_view(across: bool, console_width: usize, files: &[File]) {
}
}
-fn details_view(columns: &[Column], files: &[File], header: bool) {
+fn details_view(columns: &[Column], files: &[File], header: bool, tree: bool) {
// The output gets formatted into columns, which looks nicer. To
// do this, we have to write the results into a table, instead of
// displaying each file immediately, then calculating the maximum
@@ -131,19 +131,22 @@ fn details_view(columns: &[Column], files: &[File], header: bool) {
let mut cache = OSUsers::empty_cache();
- let mut table: Vec<Vec<Cell>> = files.iter()
- .map(|f| columns.iter().map(|c| f.display(c, &mut cache)).collect())
- .collect();
+ let mut table = Vec::new();
+ get_files(columns, &mut cache, tree, &mut table, files, 0);
if header {
- table.insert(0, columns.iter().map(|c| Cell::paint(Plain.underline(), c.header())).collect());
+ table.insert(0, (0, columns.iter().map(|c| Cell::paint(Plain.underline(), c.header())).collect()));
}
let column_widths: Vec<usize> = range(0, columns.len())
- .map(|n| table.iter().map(|row| row[n].length).max().unwrap_or(0))
+ .map(|n| table.iter().map(|row| row.1[n].length).max().unwrap_or(0))
.collect();
- for row in table.iter() {
+ for &(depth, ref row) in table.iter() {
+ for _ in range(0, depth) {
+ print!("#");
+ }
+
for (num, column) in columns.iter().enumerate() {
if num != 0 {
print!(" "); // Separator
@@ -161,3 +164,16 @@ fn details_view(columns: &[Column], files: &[File], header: bool) {
print!("\n");
}
}
+
+fn get_files(columns: &[Column], cache: &mut OSUsers, recurse: bool, dest: &mut Vec<(usize, Vec<Cell>)>, src: &[File], depth: usize) {
+ for file in src.iter() {
+ let cols = columns.iter().map(|c| file.display(c, cache)).collect();
+ dest.push((depth, cols));
+
+ if recurse {
+ if let Some(ref dir) = file.this {
+ get_files(columns, cache, recurse, dest, dir.files(true).as_slice(), depth + 1);
+ }
+ }
+ }
+}