mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 23:59:58 -08:00
Compare commits
1 Commits
clean_test
...
depth_refa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17fe56bfd2 |
@@ -143,7 +143,7 @@ fn walk(
|
|||||||
data.is_symlink(),
|
data.is_symlink(),
|
||||||
data.is_file(),
|
data.is_file(),
|
||||||
walk_data.by_filecount,
|
walk_data.by_filecount,
|
||||||
depth,
|
depth + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,13 +84,13 @@ impl DrawData<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: can we test this?
|
// TODO: can we test this?
|
||||||
fn generate_bar(&self, node: &DisplayNode, level: usize) -> String {
|
fn generate_bar(&self, node: &DisplayNode) -> String {
|
||||||
let chars_in_bar = self.percent_bar.chars().count();
|
let chars_in_bar = self.percent_bar.chars().count();
|
||||||
let num_bars = chars_in_bar as f32 * self.display_data.percent_size(node);
|
let num_bars = chars_in_bar as f32 * self.display_data.percent_size(node);
|
||||||
let mut num_not_my_bar = (chars_in_bar as i32) - num_bars as i32;
|
let mut num_not_my_bar = (chars_in_bar as i32) - num_bars as i32;
|
||||||
|
|
||||||
let mut new_bar = "".to_string();
|
let mut new_bar = "".to_string();
|
||||||
let idx = 5 - min(4, max(1, level));
|
let idx = 5 - min(4, max(1, node.depth));
|
||||||
|
|
||||||
for c in self.percent_bar.chars() {
|
for c in self.percent_bar.chars() {
|
||||||
num_not_my_bar -= 1;
|
num_not_my_bar -= 1;
|
||||||
@@ -181,10 +181,8 @@ fn find_longest_dir_name(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn display_node(node: DisplayNode, draw_data: &DrawData, is_biggest: bool, is_last: bool) {
|
fn display_node(node: DisplayNode, draw_data: &DrawData, is_biggest: bool, is_last: bool) {
|
||||||
// hacky way of working out how deep we are in the tree
|
|
||||||
let indent = draw_data.get_new_indent(!node.children.is_empty(), is_last);
|
let indent = draw_data.get_new_indent(!node.children.is_empty(), is_last);
|
||||||
let level = ((indent.chars().count() - 1) / 2) - 1;
|
let bar_text = draw_data.generate_bar(&node);
|
||||||
let bar_text = draw_data.generate_bar(&node, level);
|
|
||||||
|
|
||||||
let to_print = format_string(
|
let to_print = format_string(
|
||||||
&node,
|
&node,
|
||||||
@@ -398,6 +396,7 @@ mod tests {
|
|||||||
let n = DisplayNode {
|
let n = DisplayNode {
|
||||||
name: PathBuf::from("/short"),
|
name: PathBuf::from("/short"),
|
||||||
size: 2_u64.pow(12), // This is 4.0K
|
size: 2_u64.pow(12), // This is 4.0K
|
||||||
|
depth: 1,
|
||||||
children: vec![],
|
children: vec![],
|
||||||
};
|
};
|
||||||
let indent = "┌─┴";
|
let indent = "┌─┴";
|
||||||
@@ -420,6 +419,7 @@ mod tests {
|
|||||||
let n = DisplayNode {
|
let n = DisplayNode {
|
||||||
name: PathBuf::from(name),
|
name: PathBuf::from(name),
|
||||||
size: 2_u64.pow(12), // This is 4.0K
|
size: 2_u64.pow(12), // This is 4.0K
|
||||||
|
depth: 1,
|
||||||
children: vec![],
|
children: vec![],
|
||||||
};
|
};
|
||||||
let indent = "┌─┴";
|
let indent = "┌─┴";
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use std::path::PathBuf;
|
|||||||
pub struct DisplayNode {
|
pub struct DisplayNode {
|
||||||
pub name: PathBuf, //todo: consider moving to a string?
|
pub name: PathBuf, //todo: consider moving to a string?
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
|
pub depth: usize,
|
||||||
pub children: Vec<DisplayNode>,
|
pub children: Vec<DisplayNode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ pub fn get_all_file_types(top_level_nodes: Vec<Node>, n: usize) -> Option<Displa
|
|||||||
let remaining = DisplayNode {
|
let remaining = DisplayNode {
|
||||||
name: PathBuf::from("(others)"),
|
name: PathBuf::from("(others)"),
|
||||||
size: rest.iter().map(|a| a.size).sum(),
|
size: rest.iter().map(|a| a.size).sum(),
|
||||||
|
depth: 1,
|
||||||
children: vec![],
|
children: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ pub fn get_all_file_types(top_level_nodes: Vec<Node>, n: usize) -> Option<Displa
|
|||||||
let result = DisplayNode {
|
let result = DisplayNode {
|
||||||
name: PathBuf::from("(total)"),
|
name: PathBuf::from("(total)"),
|
||||||
size: displayed.iter().map(|a| a.size).sum(),
|
size: displayed.iter().map(|a| a.size).sum(),
|
||||||
|
depth: 0,
|
||||||
children: displayed,
|
children: displayed,
|
||||||
};
|
};
|
||||||
Some(result)
|
Some(result)
|
||||||
@@ -98,6 +100,7 @@ fn build_by_all_file_types(top_level_nodes: Vec<Node>, counter: &mut HashMap<Str
|
|||||||
let mut display_node = counter.entry(key.clone()).or_insert(DisplayNode {
|
let mut display_node = counter.entry(key.clone()).or_insert(DisplayNode {
|
||||||
name: PathBuf::from(key),
|
name: PathBuf::from(key),
|
||||||
size: 0,
|
size: 0,
|
||||||
|
depth: node.depth,
|
||||||
children: vec![],
|
children: vec![],
|
||||||
});
|
});
|
||||||
display_node.size += node.size;
|
display_node.size += node.size;
|
||||||
@@ -141,6 +144,7 @@ fn recursive_rebuilder<'a>(
|
|||||||
let newnode = DisplayNode {
|
let newnode = DisplayNode {
|
||||||
name: current.name.clone(),
|
name: current.name.clone(),
|
||||||
size: current.size,
|
size: current.size,
|
||||||
|
depth: current.depth,
|
||||||
children: new_children,
|
children: new_children,
|
||||||
};
|
};
|
||||||
Some(newnode)
|
Some(newnode)
|
||||||
|
|||||||
Reference in New Issue
Block a user