mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
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
This commit is contained in:
+6
-10
@@ -1,7 +1,6 @@
|
|||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
|
|
||||||
use self::ansi_term::Colour::Fixed;
|
use self::ansi_term::Colour::Fixed;
|
||||||
use self::ansi_term::Style;
|
|
||||||
use crate::utils::Node;
|
use crate::utils::Node;
|
||||||
|
|
||||||
use terminal_size::{terminal_size, Height, Width};
|
use terminal_size::{terminal_size, Height, Width};
|
||||||
@@ -287,16 +286,13 @@ pub fn format_string(
|
|||||||
"".into()
|
"".into()
|
||||||
};
|
};
|
||||||
|
|
||||||
format!(
|
let pretty_size = if is_biggest && display_data.colors_on {
|
||||||
"{} {}{}",
|
format!("{}", Fixed(196).paint(pretty_size))
|
||||||
if is_biggest && display_data.colors_on {
|
|
||||||
Fixed(196).paint(pretty_size)
|
|
||||||
} else {
|
} else {
|
||||||
Style::new().paint(pretty_size)
|
pretty_size
|
||||||
},
|
};
|
||||||
tree_and_path,
|
|
||||||
percents,
|
format!("{} {}{}", pretty_size, tree_and_path, percents)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn human_readable_number(size: u64) -> String {
|
fn human_readable_number(size: u64) -> String {
|
||||||
|
|||||||
+17
-6
@@ -16,12 +16,24 @@ mod utils;
|
|||||||
static DEFAULT_NUMBER_OF_LINES: usize = 30;
|
static DEFAULT_NUMBER_OF_LINES: usize = 30;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn init_color() {
|
fn init_color(no_color: bool) -> bool {
|
||||||
ansi_term::enable_ansi_support().expect("Couldn't enable color support");
|
// 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))]
|
#[cfg(not(windows))]
|
||||||
fn init_color() {}
|
fn init_color(no_color: bool) -> bool {
|
||||||
|
no_color
|
||||||
|
}
|
||||||
|
|
||||||
fn get_height_of_terminal() -> usize {
|
fn get_height_of_terminal() -> usize {
|
||||||
// Windows CI runners detect a terminal height of 0
|
// Windows CI runners detect a terminal height of 0
|
||||||
@@ -33,8 +45,6 @@ fn get_height_of_terminal() -> usize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
init_color();
|
|
||||||
|
|
||||||
let default_height = get_height_of_terminal();
|
let default_height = get_height_of_terminal();
|
||||||
let def_num_str = default_height.to_string();
|
let def_num_str = default_height.to_string();
|
||||||
|
|
||||||
@@ -157,6 +167,7 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let no_colors = init_color(options.is_present("no_colors"));
|
||||||
let use_apparent_size = options.is_present("display_apparent_size");
|
let use_apparent_size = options.is_present("display_apparent_size");
|
||||||
let limit_filesystem = options.is_present("limit_filesystem");
|
let limit_filesystem = options.is_present("limit_filesystem");
|
||||||
let ignore_directories = match options.values_of("ignore_directory") {
|
let ignore_directories = match options.values_of("ignore_directory") {
|
||||||
@@ -185,7 +196,7 @@ fn main() {
|
|||||||
permissions,
|
permissions,
|
||||||
options.is_present("display_full_paths"),
|
options.is_present("display_full_paths"),
|
||||||
!options.is_present("reverse"),
|
!options.is_present("reverse"),
|
||||||
options.is_present("no_colors"),
|
no_colors,
|
||||||
options.is_present("no_bars"),
|
options.is_present("no_bars"),
|
||||||
tree,
|
tree,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user