summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Nguyen <benjamin.van.nguyen@gmail.com>2023-11-26 19:17:38 -0800
committerBenjamin Nguyen <benjamin.van.nguyen@gmail.com>2023-11-26 19:17:38 -0800
commit93d80489f7bb6259e5e4da4e8cbb08d562f09249 (patch)
tree791b885cfa9c68ffff55e2c3bf1ab13dde60a7ac
parentee4a9fc32345f5dcb5aca83585735bbc2ca63e9d (diff)
flat
-rw-r--r--src/render/mod.rs30
-rw-r--r--src/render/row/mod.rs8
-rw-r--r--src/user/args.rs3
-rw-r--r--src/user/mod.rs2
4 files changed, 32 insertions, 11 deletions
diff --git a/src/render/mod.rs b/src/render/mod.rs
index 3c50766..43d3c14 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -24,8 +24,7 @@ pub fn output(file_tree: &file::Tree, ctx: &Context) -> Result<String> {
match ctx.layout {
Layout::Regular => tree(file_tree, ctx),
Layout::Inverted => inverted_tree(file_tree, ctx),
- Layout::Flat => todo!(),
- Layout::Iflat => todo!(),
+ Layout::Flat => flat(file_tree, ctx),
}
}
@@ -179,6 +178,33 @@ pub fn inverted_tree(file_tree: &file::Tree, ctx: &Context) -> Result<String> {
Ok(buf)
}
+fn flat(file_tree: &file::Tree, ctx: &Context) -> Result<String> {
+ let arena = file_tree.arena();
+ let root = file_tree.root_id();
+ let max_depth = ctx.level();
+ let mut buf = String::new();
+
+ let mut formatter = row::formatter(&mut buf, ctx);
+
+ for node_edge in root.traverse(arena) {
+ let node_id = match node_edge {
+ NodeEdge::Start(_) => continue,
+ NodeEdge::End(id) => id
+ };
+
+ let node = arena[node_id].get();
+
+ if node.depth() > max_depth {
+ continue;
+ }
+
+ formatter(node, "".to_string()).into_report(ErrorCategory::Warning)?;
+ }
+ drop(formatter);
+
+ Ok(buf)
+}
+
mod utils {
use crate::file::File;
diff --git a/src/render/row/mod.rs b/src/render/row/mod.rs
index ddeac87..6fc417b 100644
--- a/src/render/row/mod.rs
+++ b/src/render/row/mod.rs
@@ -13,10 +13,10 @@ pub fn formatter<'a>(
Box::new(|file, prefix| {
let size = format!("{}", file.size());
let name = file.file_name().to_string_lossy();
- let column::Widths {
- size: size_width, ..
- } = ctx.col_widths();
- writeln!(buf, "{size:>size_width$} {prefix}{name}")
+ let column::Metadata {
+ max_size_width, ..
+ } = ctx.column_metadata;
+ writeln!(buf, "{size:>max_size_width$} {prefix}{name}")
})
}
diff --git a/src/user/args.rs b/src/user/args.rs
index 269d152..4c30fde 100644
--- a/src/user/args.rs
+++ b/src/user/args.rs
@@ -83,7 +83,4 @@ pub enum Layout {
/// Outputs a flat layout using paths rather than an ASCII tree
Flat,
-
- /// Outputs an inverted flat layout with the root at the top of the output
- Iflat,
}
diff --git a/src/user/mod.rs b/src/user/mod.rs
index f1c6785..74fe65b 100644
--- a/src/user/mod.rs
+++ b/src/user/mod.rs
@@ -2,8 +2,6 @@ use crate::error::prelude::*;
use clap::Parser;
use std::{env, fs, path::PathBuf};
-#[cfg(unix)]
-
/// Enum definitions for enumerated command-line arguments.
pub mod args;