From 4cef6aaa84935fde8827432a5f383cd455d84163 Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Sat, 20 Aug 2022 09:22:51 +0100 Subject: [PATCH] Refactor: init_color function Refactor function so windows & linux are forced to have same signature instead of 2 different functions --- src/main.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5ce3480..cb92ebb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,29 +31,30 @@ mod utils; static DEFAULT_NUMBER_OF_LINES: usize = 30; static DEFAULT_TERMINAL_WIDTH: usize = 80; -#[cfg(not(windows))] fn init_color(no_color: bool) -> bool { - no_color -} - -#[cfg(windows)] -fn init_color(no_color: bool) -> bool { - // If no color is already set do not print a warning message - if no_color { - true - } else { - // Required for windows 10 - // Fails to resolve for windows 8 so disable color - match ansi_term::enable_ansi_support() { - Ok(_) => no_color, - Err(_) => { - eprintln!( + #[cfg(windows)] + { + // If no color is already set do not print a warning message + if no_color { + true + } else { + // 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 + true + } } } } + #[cfg(not(windows))] + { + no_color + } } fn get_height_of_terminal() -> usize {