fix: 🐛 Code style

This commit is contained in:
Atsukoro1 2022-12-05 22:52:08 +01:00
parent b27899a223
commit b847d16307
3 changed files with 30 additions and 30 deletions

View file

@ -1,5 +1,3 @@
use crate::helpers::console::enable_ansi_support;
pub const COLORS : [(&str, &str); 34] = [ pub const COLORS : [(&str, &str); 34] = [
("black", "\u{001b}[30m"), ("black", "\u{001b}[30m"),
("red", "\u{001b}[31m"), ("red", "\u{001b}[31m"),
@ -37,6 +35,35 @@ pub const COLORS : [(&str, &str); 34] = [
("bright_white_bold", "\u{001b}[97m\u{001b}[1m"), ("bright_white_bold", "\u{001b}[97m\u{001b}[1m"),
]; ];
#[cfg(target_os = "windows")]
fn enable_ansi_support() {
{
use std::os::windows::prelude::AsRawHandle;
const ENABLE_V_TERM_PROCESSING: u32 = 0x0004;
let stdout = std::io::stdout();
let handle = stdout.lock();
let mut mode = 0;
unsafe {
let handle = handle.as_raw_handle();
let result = kernel32::GetConsoleMode(handle, &mut mode);
if result == 0 {
return;
}
mode |= ENABLE_V_TERM_PROCESSING;
let result = kernel32::SetConsoleMode(handle, mode);
if result == 0 {
return;
}
}
}
}
pub fn print(text: &str, inline: bool, color: &str) { pub fn print(text: &str, inline: bool, color: &str) {
let color = COLORS.iter().find( let color = COLORS.iter().find(
|(name, _)| name == &color |(name, _)| name == &color

View file

@ -1,26 +0,0 @@
#[cfg(target_os = "windows")]
pub fn enable_ansi_support() {
use std::os::windows::prelude::AsRawHandle;
const ENABLE_V_TERM_PROCESSING: u32 = 0x0004;
let stdout = std::io::stdout();
let handle = stdout.lock();
let mut mode = 0;
unsafe {
let handle = handle.as_raw_handle();
let result = kernel32::GetConsoleMode(handle, &mut mode);
if result == 0 {
return;
}
mode |= ENABLE_V_TERM_PROCESSING;
let result = kernel32::SetConsoleMode(handle, mode);
if result == 0 {
return;
}
}
}

View file

@ -3,5 +3,4 @@ pub mod file;
pub mod colors; pub mod colors;
pub mod print; pub mod print;
pub mod paths; pub mod paths;
pub mod ponies; pub mod ponies;
pub mod console;