mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Add option flag for no colors
https://github.com/bootandy/dust/issues/37
This commit is contained in:
+36
-9
@@ -72,7 +72,13 @@ impl DisplayData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_it(permissions: bool, use_full_path: bool, is_reversed: bool, root_node: Node) {
|
pub fn draw_it(
|
||||||
|
permissions: bool,
|
||||||
|
use_full_path: bool,
|
||||||
|
is_reversed: bool,
|
||||||
|
colors_on: bool,
|
||||||
|
root_node: Node,
|
||||||
|
) {
|
||||||
if !permissions {
|
if !permissions {
|
||||||
eprintln!("Did not have permissions for all directories");
|
eprintln!("Did not have permissions for all directories");
|
||||||
}
|
}
|
||||||
@@ -83,11 +89,17 @@ pub fn draw_it(permissions: bool, use_full_path: bool, is_reversed: bool, root_n
|
|||||||
|
|
||||||
for c in display_data.get_children_from_node(root_node) {
|
for c in display_data.get_children_from_node(root_node) {
|
||||||
let first_tree_chars = display_data.get_first_chars();
|
let first_tree_chars = display_data.get_first_chars();
|
||||||
display_node(c, true, first_tree_chars, &display_data)
|
display_node(c, true, colors_on, first_tree_chars, &display_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_node(node: Node, is_biggest: bool, indent: &str, display_data: &DisplayData) {
|
fn display_node(
|
||||||
|
node: Node,
|
||||||
|
is_biggest: bool,
|
||||||
|
colors_on: bool,
|
||||||
|
indent: &str,
|
||||||
|
display_data: &DisplayData,
|
||||||
|
) {
|
||||||
let short = display_data.short_paths;
|
let short = display_data.short_paths;
|
||||||
|
|
||||||
let mut num_siblings = node.children.len() as u64;
|
let mut num_siblings = node.children.len() as u64;
|
||||||
@@ -97,7 +109,7 @@ fn display_node(node: Node, is_biggest: bool, indent: &str, display_data: &Displ
|
|||||||
let size = node.size;
|
let size = node.size;
|
||||||
|
|
||||||
if !display_data.is_reversed {
|
if !display_data.is_reversed {
|
||||||
print_this_node(&*name, size, is_biggest, short, indent);
|
print_this_node(&*name, size, is_biggest, short, colors_on, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in display_data.get_children_from_node(node) {
|
for c in display_data.get_children_from_node(node) {
|
||||||
@@ -105,11 +117,11 @@ fn display_node(node: Node, is_biggest: bool, indent: &str, display_data: &Displ
|
|||||||
let chars = display_data.get_tree_chars(num_siblings, max_sibling, !c.children.is_empty());
|
let chars = display_data.get_tree_chars(num_siblings, max_sibling, !c.children.is_empty());
|
||||||
let is_biggest = display_data.is_biggest(num_siblings, max_sibling);
|
let is_biggest = display_data.is_biggest(num_siblings, max_sibling);
|
||||||
let full_indent = new_indent.clone() + chars;
|
let full_indent = new_indent.clone() + chars;
|
||||||
display_node(c, is_biggest, &*full_indent, display_data)
|
display_node(c, is_biggest, colors_on, &*full_indent, display_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if display_data.is_reversed {
|
if display_data.is_reversed {
|
||||||
print_this_node(&*name, size, is_biggest, short, indent);
|
print_this_node(&*name, size, is_biggest, short, colors_on, indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,11 +142,25 @@ fn clean_indentation_string(s: &str) -> String {
|
|||||||
is
|
is
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_this_node(name: &str, size: u64, is_biggest: bool, short_paths: bool, indentation: &str) {
|
fn print_this_node(
|
||||||
|
name: &str,
|
||||||
|
size: u64,
|
||||||
|
is_biggest: bool,
|
||||||
|
short_paths: bool,
|
||||||
|
colors_on: bool,
|
||||||
|
indentation: &str,
|
||||||
|
) {
|
||||||
let pretty_size = format!("{:>5}", human_readable_number(size),);
|
let pretty_size = format!("{:>5}", human_readable_number(size),);
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
format_string(name, is_biggest, short_paths, &*pretty_size, indentation)
|
format_string(
|
||||||
|
name,
|
||||||
|
is_biggest,
|
||||||
|
short_paths,
|
||||||
|
colors_on,
|
||||||
|
&*pretty_size,
|
||||||
|
indentation
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +168,7 @@ pub fn format_string(
|
|||||||
dir_name: &str,
|
dir_name: &str,
|
||||||
is_biggest: bool,
|
is_biggest: bool,
|
||||||
short_paths: bool,
|
short_paths: bool,
|
||||||
|
colors_on: bool,
|
||||||
size: &str,
|
size: &str,
|
||||||
indentation: &str,
|
indentation: &str,
|
||||||
) -> String {
|
) -> String {
|
||||||
@@ -154,7 +181,7 @@ pub fn format_string(
|
|||||||
};
|
};
|
||||||
format!(
|
format!(
|
||||||
"{} {} {}",
|
"{} {} {}",
|
||||||
if is_biggest {
|
if is_biggest && colors_on {
|
||||||
Fixed(196).paint(size)
|
Fixed(196).paint(size)
|
||||||
} else {
|
} else {
|
||||||
Style::new().paint(size)
|
Style::new().paint(size)
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ fn main() {
|
|||||||
.long("reverse")
|
.long("reverse")
|
||||||
.help("If applied tree will be printed upside down (biggest lowest)"),
|
.help("If applied tree will be printed upside down (biggest lowest)"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("no_colors")
|
||||||
|
.short("c")
|
||||||
|
.long("no_colors")
|
||||||
|
.help("If applied no colors will be printed (normally largest directories are marked in red"),
|
||||||
|
)
|
||||||
.arg(Arg::with_name("inputs").multiple(true))
|
.arg(Arg::with_name("inputs").multiple(true))
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
@@ -112,6 +118,7 @@ fn main() {
|
|||||||
permissions,
|
permissions,
|
||||||
use_full_path,
|
use_full_path,
|
||||||
options.is_present("reverse"),
|
options.is_present("reverse"),
|
||||||
|
!options.is_present("no_colors"),
|
||||||
tree,
|
tree,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user