From 38938e005ea7437533771099419012580461f2f1 Mon Sep 17 00:00:00 2001 From: Adam Lesperance Date: Fri, 27 Dec 2019 13:33:20 -0600 Subject: [PATCH] Fix colors on windows * Initialize ansi_term if we're on windows * Silence build warning on non-unix targets * Update ansi-term which has windows specific fixes (and assert_cli while I'm at it) --- src/main.rs | 9 +++++++++ src/utils/platform.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index ce51d69..d8b2f56 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,16 @@ mod utils; static DEFAULT_NUMBER_OF_LINES: usize = 20; +#[cfg(windows)] +fn init_color() { + ansi_term::enable_ansi_support().expect("Couldn't enable color support"); +} + +#[cfg(not(windows))] +fn init_color() {} + fn main() { + init_color(); let def_num_str = DEFAULT_NUMBER_OF_LINES.to_string(); let options = App::new("Dust") .about("Like du but more intuitive") diff --git a/src/utils/platform.rs b/src/utils/platform.rs index e694ac6..86276dc 100644 --- a/src/utils/platform.rs +++ b/src/utils/platform.rs @@ -1,5 +1,6 @@ use jwalk::DirEntry; +#[cfg(target_family = "unix")] fn get_block_size() -> u64 { // All os specific implementations of MetatdataExt seem to define a block as 512 bytes // https://doc.rust-lang.org/std/os/linux/fs/trait.MetadataExt.html#tymethod.st_blocks