Refactor: init_color function

Refactor function so windows & linux are forced to have same signature
instead of 2 different functions
This commit is contained in:
andy.boot
2022-08-20 09:22:51 +01:00
parent d477145694
commit 4cef6aaa84
+18 -17
View File
@@ -31,29 +31,30 @@ mod utils;
static DEFAULT_NUMBER_OF_LINES: usize = 30; static DEFAULT_NUMBER_OF_LINES: usize = 30;
static DEFAULT_TERMINAL_WIDTH: usize = 80; static DEFAULT_TERMINAL_WIDTH: usize = 80;
#[cfg(not(windows))]
fn init_color(no_color: bool) -> bool { fn init_color(no_color: bool) -> bool {
no_color #[cfg(windows)]
} {
// If no color is already set do not print a warning message
#[cfg(windows)] if no_color {
fn init_color(no_color: bool) -> bool { true
// If no color is already set do not print a warning message } else {
if no_color { // Required for windows 10
true // Fails to resolve for windows 8 so disable color
} else { match ansi_term::enable_ansi_support() {
// Required for windows 10 Ok(_) => no_color,
// Fails to resolve for windows 8 so disable color Err(_) => {
match ansi_term::enable_ansi_support() { eprintln!(
Ok(_) => no_color,
Err(_) => {
eprintln!(
"This version of Windows does not support ANSI colors, setting no_color flag" "This version of Windows does not support ANSI colors, setting no_color flag"
); );
true true
}
} }
} }
} }
#[cfg(not(windows))]
{
no_color
}
} }
fn get_height_of_terminal() -> usize { fn get_height_of_terminal() -> usize {