From 58b059bcbf0bb1356e82b1e36659dbcd6e8626b8 Mon Sep 17 00:00:00 2001 From: Atsukoro1 Date: Mon, 5 Dec 2022 22:25:25 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Enabling=20ansi=20code?= =?UTF-8?q?=20support=20in=20windows=20terminals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 5 ++++- src/helpers/colors.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 94a8097..fef10f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,7 @@ include = [ "**/*.rs", "Cargo.toml", "ponies/*" -] \ No newline at end of file +] + +[dependencies] +ansi_term = "0.12.1" \ No newline at end of file diff --git a/src/helpers/colors.rs b/src/helpers/colors.rs index 2e23a58..b3ddd54 100644 --- a/src/helpers/colors.rs +++ b/src/helpers/colors.rs @@ -1,3 +1,4 @@ +// #[cfg(any(target_os = "linux", target_os = "macos"))] pub const COLORS : [(&str, &str); 34] = [ ("black", "\u{001b}[30m"), ("red", "\u{001b}[31m"), @@ -36,10 +37,15 @@ pub const COLORS : [(&str, &str); 34] = [ ]; pub fn print(text: &str, inline: bool, color: &str) { - let color = color; + let color = COLORS.iter().find( + |(name, _)| name == &color + ).unwrap().1; - let color = color; - let color = COLORS.iter().find(|(name, _)| name == &color).unwrap().1; + #[cfg(windows)] + { + use ansi_term::enable_ansi_support; + enable_ansi_support().unwrap(); + } if inline { print!("{}{}", color, text);