feat: 🎸 Enabling ansi code support in windows terminals

This commit is contained in:
Atsukoro1 2022-12-05 22:25:25 +01:00
parent 4f6e76fc54
commit 58b059bcbf
2 changed files with 13 additions and 4 deletions

View file

@ -10,4 +10,7 @@ include = [
"**/*.rs",
"Cargo.toml",
"ponies/*"
]
]
[dependencies]
ansi_term = "0.12.1"

View file

@ -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);