#[cfg(windows)]
use std::io::Result;
#[cfg(windows)]
use crossterm_winapi::{Console, ScreenBuffer};
#[cfg(windows)]
fn set_background_color() -> Result<()> {
const BLUE_BACKGROUND: u16 = 0x0010;
let screen_buffer = ScreenBuffer::current()?;
let csbi = screen_buffer.info()?;
let attrs = csbi.attributes();
let fg_color = attrs & 0x0007;
let new_color = fg_color | BLUE_BACKGROUND;
Console::from(screen_buffer.handle().clone()).set_text_attribute(new_color)?;
Ok(())
}
#[cfg(windows)]
fn set_foreground_color() -> Result<()> {
const BLUE_FOREGROUND: u16 = 0x0001;
let screen_buffer = ScreenBuffer::current()?;
let csbi = screen_buffer.info()?;
let attrs = csbi.attributes();
let bg_color = attrs & 0x0070;
let mut color = BLUE_FOREGROUND | bg_color;
if (attrs & 0x0080 as u16) != 0 {
color = color | 0x0080 as u16;
}
Console::from(screen_buffer.handle().clone()).set_text_attribute(color)?;
Ok(())
}
#[cfg(windows)]
fn main() -> Result<()> {
set_background_color()?;
set_foreground_color()
}
#[cfg(not(windows))]
fn main() {
println!("This example is for the Windows platform only.");
}