Merge pull request #78 from bootandy/ab-fix-build

Maybe fix windows 8 support
This commit is contained in:
andy.boot
2020-02-29 23:06:57 +00:00
committed by GitHub
2 changed files with 24 additions and 17 deletions
+7 -11
View File
@@ -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 {
+17 -6
View File
@@ -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,
);