mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
hack
This commit is contained in:
+30
-18
@@ -11,6 +11,7 @@ use stfu8::encode_u8;
|
|||||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@@ -148,6 +149,8 @@ pub fn draw_it(
|
|||||||
"Not enough terminal width"
|
"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 allowed_width = terminal_width - num_chars_needed_on_left_most - 2;
|
||||||
let num_indent_chars = 3;
|
let num_indent_chars = 3;
|
||||||
let longest_string_length =
|
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 {
|
fn find_biggest_size_str(node: &DisplayNode, output_format: &str) -> usize {
|
||||||
let mut mx = human_readable_number(node.size, output_format)
|
let mut mx = human_readable_number(node.size, output_format)
|
||||||
@@ -273,24 +303,6 @@ fn clean_indentation_string(s: &str) -> String {
|
|||||||
is
|
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 {
|
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 name = get_printable_name(&node.name, display_data.initial.short_paths);
|
||||||
let indent_and_name = format!("{indent} {name}");
|
let indent_and_name = format!("{indent} {name}");
|
||||||
|
|||||||
+23
-1
@@ -1,3 +1,6 @@
|
|||||||
|
use stfu8::encode_u8;
|
||||||
|
|
||||||
|
use crate::display::get_printable_name;
|
||||||
use crate::display_node::DisplayNode;
|
use crate::display_node::DisplayNode;
|
||||||
use crate::node::FileTime;
|
use crate::node::FileTime;
|
||||||
use crate::node::Node;
|
use crate::node::Node;
|
||||||
@@ -17,7 +20,7 @@ pub struct AggregateData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_biggest(
|
pub fn get_biggest(
|
||||||
top_level_nodes: Vec<Node>,
|
mut top_level_nodes: Vec<Node>,
|
||||||
display_data: AggregateData,
|
display_data: AggregateData,
|
||||||
by_filetime: &Option<FileTime>,
|
by_filetime: &Option<FileTime>,
|
||||||
keep_collapsed: HashSet<PathBuf>,
|
keep_collapsed: HashSet<PathBuf>,
|
||||||
@@ -40,6 +43,24 @@ pub fn get_biggest(
|
|||||||
} else {
|
} else {
|
||||||
top_level_nodes.iter().map(|node| node.size).sum()
|
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 {
|
root = Node {
|
||||||
name: PathBuf::from("(total)"),
|
name: PathBuf::from("(total)"),
|
||||||
size,
|
size,
|
||||||
@@ -47,6 +68,7 @@ pub fn get_biggest(
|
|||||||
inode_device: None,
|
inode_device: None,
|
||||||
depth: 0,
|
depth: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Always include the base nodes if we add a 'parent' (total) node
|
// Always include the base nodes if we add a 'parent' (total) node
|
||||||
heap = always_add_children(&display_data, &root, heap);
|
heap = always_add_children(&display_data, &root, heap);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user