mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 07:40:40 -08:00
hack
This commit is contained in:
@@ -11,6 +11,7 @@ use stfu8::encode_u8;
|
||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||
use std::cmp::max;
|
||||
use std::cmp::min;
|
||||
use std::collections::HashSet;
|
||||
use std::fs;
|
||||
use std::iter::repeat;
|
||||
use std::path::Path;
|
||||
@@ -148,6 +149,8 @@ pub fn draw_it(
|
||||
"Not enough terminal width"
|
||||
);
|
||||
|
||||
// let duplicate_dir_names = find_duplicate_names(root_node, idd.short_paths);
|
||||
|
||||
let allowed_width = terminal_width - num_chars_needed_on_left_most - 2;
|
||||
let num_indent_chars = 3;
|
||||
let longest_string_length =
|
||||
@@ -187,6 +190,33 @@ pub fn draw_it(
|
||||
}
|
||||
}
|
||||
}
|
||||
// fn find_duplicate_names(node: &DisplayNode, short_paths: bool) -> HashSet<DisplayNode> {
|
||||
// if !short_paths {
|
||||
// return HashSet::new()
|
||||
// } else {
|
||||
// get_printable_name(node.dir_name, short_paths)
|
||||
// // or maybe if we find them from diff root nodes we can mark them.
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
pub fn get_printable_name<P: AsRef<Path>>(dir_name: &P, short_paths: bool) -> String {
|
||||
let dir_name = dir_name.as_ref();
|
||||
let printable_name = {
|
||||
if short_paths {
|
||||
match dir_name.parent() {
|
||||
Some(prefix) => match dir_name.strip_prefix(prefix) {
|
||||
Ok(base) => base,
|
||||
Err(_) => dir_name,
|
||||
},
|
||||
None => dir_name,
|
||||
}
|
||||
} else {
|
||||
dir_name
|
||||
}
|
||||
};
|
||||
encode_u8(printable_name.display().to_string().as_bytes())
|
||||
}
|
||||
|
||||
fn find_biggest_size_str(node: &DisplayNode, output_format: &str) -> usize {
|
||||
let mut mx = human_readable_number(node.size, output_format)
|
||||
@@ -273,24 +303,6 @@ fn clean_indentation_string(s: &str) -> String {
|
||||
is
|
||||
}
|
||||
|
||||
fn get_printable_name<P: AsRef<Path>>(dir_name: &P, short_paths: bool) -> String {
|
||||
let dir_name = dir_name.as_ref();
|
||||
let printable_name = {
|
||||
if short_paths {
|
||||
match dir_name.parent() {
|
||||
Some(prefix) => match dir_name.strip_prefix(prefix) {
|
||||
Ok(base) => base,
|
||||
Err(_) => dir_name,
|
||||
},
|
||||
None => dir_name,
|
||||
}
|
||||
} else {
|
||||
dir_name
|
||||
}
|
||||
};
|
||||
encode_u8(printable_name.display().to_string().as_bytes())
|
||||
}
|
||||
|
||||
fn pad_or_trim_filename(node: &DisplayNode, indent: &str, display_data: &DisplayData) -> String {
|
||||
let name = get_printable_name(&node.name, display_data.initial.short_paths);
|
||||
let indent_and_name = format!("{indent} {name}");
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
use stfu8::encode_u8;
|
||||
|
||||
use crate::display::get_printable_name;
|
||||
use crate::display_node::DisplayNode;
|
||||
use crate::node::FileTime;
|
||||
use crate::node::Node;
|
||||
@@ -17,7 +20,7 @@ pub struct AggregateData {
|
||||
}
|
||||
|
||||
pub fn get_biggest(
|
||||
top_level_nodes: Vec<Node>,
|
||||
mut top_level_nodes: Vec<Node>,
|
||||
display_data: AggregateData,
|
||||
by_filetime: &Option<FileTime>,
|
||||
keep_collapsed: HashSet<PathBuf>,
|
||||
@@ -40,6 +43,24 @@ pub fn get_biggest(
|
||||
} else {
|
||||
top_level_nodes.iter().map(|node| node.size).sum()
|
||||
};
|
||||
|
||||
// If top level folders have same name -> change them.
|
||||
let names = top_level_nodes.iter().map(|node| node.name.to_str());
|
||||
// todo pass in short_paths flag
|
||||
let print_nam = top_level_nodes.iter().map(|node| get_printable_name(&node.name, true)).collect::<String>();
|
||||
// if has same name
|
||||
|
||||
for n in top_level_nodes.iter_mut(){
|
||||
let tmp = n.name.parent().unwrap().components().last().unwrap().as_os_str().to_str().unwrap();
|
||||
let orig = n.name.display().to_string();
|
||||
n.name = PathBuf::from(format!("{orig}({tmp})"));
|
||||
println!("{:?}", n.name);
|
||||
}
|
||||
// build up list of dup-names
|
||||
|
||||
// Repeatedly add parent path until all are not dup
|
||||
|
||||
|
||||
root = Node {
|
||||
name: PathBuf::from("(total)"),
|
||||
size,
|
||||
@@ -47,6 +68,7 @@ pub fn get_biggest(
|
||||
inode_device: None,
|
||||
depth: 0,
|
||||
};
|
||||
|
||||
// Always include the base nodes if we add a 'parent' (total) node
|
||||
heap = always_add_children(&display_data, &root, heap);
|
||||
} else {
|
||||
|
||||
0
tests/test_dir_matching/andy/dup_name/hello
Normal file
0
tests/test_dir_matching/andy/dup_name/hello
Normal file
Reference in New Issue
Block a user