From 342164d3576edcc55e815ff31c3bf84c864c92b9 Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Sat, 28 Mar 2020 18:32:40 +0000 Subject: [PATCH 1/3] Tests: Add Missing copy command should have been added with previous commit, would occastionaly have caused tests to fail if tests run in random order --- tests/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index 7adb63f..28f245a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -138,6 +138,8 @@ fn main_output_long_paths() -> String { #[cfg_attr(target_os = "windows", ignore)] #[test] pub fn test_apparent_size() { + copy_test_data("src/test_dir"); + let mut cmd = Command::cargo_bin("dust").unwrap(); let assert = cmd.arg("-c").arg("-s").arg("src/test_dir").unwrap().stdout; let output = str::from_utf8(&assert).unwrap(); From 34be81c21688359618f47bb30bee8921b2041417 Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Tue, 2 Jun 2020 13:45:12 +0100 Subject: [PATCH 2/3] Windows: If no color flag is already set ... then do not print a warning message https://github.com/bootandy/dust/issues/87 --- src/main.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index beb3fe5..ee68804 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,15 +20,20 @@ static DEFAULT_NUMBER_OF_LINES: usize = 30; #[cfg(windows)] fn init_color(no_color: bool) -> bool { - // Required for windows 10 - // Fails to resolve for windows 8 so disable color - match ansi_term::enable_ansi_support() { - Ok(_) => no_color, - Err(_) => { - eprintln!( - "This version of Windows does not support ANSI colors, setting no_color flag" - ); - true + // If no color is already set do not print a warning message + if no_color { + true + } else { + // Required for windows 10 + // Fails to resolve for windows 8 so disable color + match ansi_term::enable_ansi_support() { + Ok(_) => no_color, + Err(_) => { + eprintln!( + "This version of Windows does not support ANSI colors, setting no_color flag" + ); + true + } } } } From b3d446bfefe606365f87238221bb2bf2a5c5061e Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Tue, 2 Jun 2020 13:57:46 +0100 Subject: [PATCH 3/3] Display: No padding if no bars drawn If not drawing the percent bars do not add padding to the filenames https://github.com/bootandy/dust/issues/89 --- src/display.rs | 15 ++++++++------- tests/tests.rs | 10 ++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/display.rs b/src/display.rs index 573ec5d..770abdd 100644 --- a/src/display.rs +++ b/src/display.rs @@ -285,15 +285,16 @@ pub fn format_string( let name = get_printable_name(&node.name, display_data.short_paths); let width = get_unicode_width_of_indent_and_name(indent, &name); - let name_and_padding = name - + &(repeat(" ") - .take(display_data.longest_string_length - width) - .collect::()); + let (percents, name_and_padding) = if percent_bar != "" { + let percents = format!("│{} │ {:>4}", percent_bar, percent_size_str); - let percents = if percent_bar != "" { - format!("│{} │ {:>4}", percent_bar, percent_size_str) + let name_and_padding = name + + &(repeat(" ") + .take(display_data.longest_string_length - width) + .collect::()); + (percents, name_and_padding) } else { - "".into() + ("".into(), name) }; let pretty_size = if is_biggest && display_data.colors_on { diff --git a/tests/tests.rs b/tests/tests.rs index 28f245a..eef46c9 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -32,6 +32,16 @@ pub fn test_basic_output() { assert!(output.contains("a_file ")); } +#[test] +pub fn test_output_no_bars_means_no_excess_spaces() { + let mut cmd = Command::cargo_bin("dust").unwrap(); + let output = cmd.arg("-b").arg("src/test_dir/").unwrap().stdout; + let output = str::from_utf8(&output).unwrap(); + // If bars are not being shown we don't need to pad the output with spaces + assert!(output.contains("many")); + assert!(!output.contains("many ")); +} + // "windows" result data can vary by host (size seems to be variable by one byte); fix code vs test and re-enable #[cfg_attr(target_os = "windows", ignore)] #[test]