From 19d938b05e8e10489a78357c4487f9ad0fd8bb3a Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Sat, 29 Feb 2020 01:39:38 +0000 Subject: [PATCH] Maybe fix windows 8 support enable_ansi_support must be run for windows 10 but is not required and indeed fails if run on windows < 10. Disable the expect so the code might run on windows 8 may fix: https://github.com/bootandy/dust/issues/70 --- src/display.rs | 18 +++++++----------- src/main.rs | 23 +++++++++++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/display.rs b/src/display.rs index 977cd7e..56d4606 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,7 +1,6 @@ extern crate ansi_term; use self::ansi_term::Colour::Fixed; -use self::ansi_term::Style; use crate::utils::Node; use terminal_size::{terminal_size, Height, Width}; @@ -287,16 +286,13 @@ pub fn format_string( "".into() }; - format!( - "{} {}{}", - if is_biggest && display_data.colors_on { - Fixed(196).paint(pretty_size) - } else { - Style::new().paint(pretty_size) - }, - tree_and_path, - percents, - ) + let pretty_size = if is_biggest && display_data.colors_on { + format!("{}", Fixed(196).paint(pretty_size)) + } else { + pretty_size + }; + + format!("{} {}{}", pretty_size, tree_and_path, percents) } fn human_readable_number(size: u64) -> String { diff --git a/src/main.rs b/src/main.rs index 69d2681..f257936 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,12 +16,24 @@ mod utils; static DEFAULT_NUMBER_OF_LINES: usize = 30; #[cfg(windows)] -fn init_color() { - ansi_term::enable_ansi_support().expect("Couldn't enable color support"); +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 + } + } } #[cfg(not(windows))] -fn init_color() {} +fn init_color(no_color: bool) -> bool { + no_color +} fn get_height_of_terminal() -> usize { // Windows CI runners detect a terminal height of 0 @@ -33,8 +45,6 @@ fn get_height_of_terminal() -> usize { } fn main() { - init_color(); - let default_height = get_height_of_terminal(); let def_num_str = default_height.to_string(); @@ -157,6 +167,7 @@ fn main() { return; } + let no_colors = init_color(options.is_present("no_colors")); let use_apparent_size = options.is_present("display_apparent_size"); let limit_filesystem = options.is_present("limit_filesystem"); let ignore_directories = match options.values_of("ignore_directory") { @@ -185,7 +196,7 @@ fn main() { permissions, options.is_present("display_full_paths"), !options.is_present("reverse"), - options.is_present("no_colors"), + no_colors, options.is_present("no_bars"), tree, );