Struct crossterm_winapi::Console
source · pub struct Console { /* private fields */ }
Expand description
A wrapper around a screen buffer.
Implementations§
source§impl Console
impl Console
sourcepub fn output() -> Result<Console>
pub fn output() -> Result<Console>
Create new instance of Console
.
This created instance will use the default output handle (STD_OUTPUT_HANDLE) as handle for the function call it wraps.
sourcepub fn set_text_attribute(&self, value: u16) -> Result<()>
pub fn set_text_attribute(&self, value: u16) -> Result<()>
Sets the attributes of characters written to the console screen buffer by the WriteFile
or WriteConsole
functions, or echoed by the ReadFile
or ReadConsole
functions.
This function affects text written after the function call.
The attributes is a bitmask of possible character attributes.
This wraps
SetConsoleTextAttribute
.
Examples found in repository?
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn set_background_color() -> Result<()> {
// background value
const BLUE_BACKGROUND: u16 = 0x0010;
let screen_buffer = ScreenBuffer::current()?;
let csbi = screen_buffer.info()?;
// Notice that the color values are stored in wAttribute.
// So wee need to use bitwise operators to check if the values exists or to get current console colors.
let attrs = csbi.attributes();
let fg_color = attrs & 0x0007;
// apply the blue background flag to the current attributes
let new_color = fg_color | BLUE_BACKGROUND;
// set the console text attribute to the new color value.
Console::from(screen_buffer.handle().clone()).set_text_attribute(new_color)?;
Ok(())
}
#[cfg(windows)]
fn set_foreground_color() -> Result<()> {
// background value
const BLUE_FOREGROUND: u16 = 0x0001;
let screen_buffer = ScreenBuffer::current()?;
let csbi = screen_buffer.info()?;
// Notice that the color values are stored in wAttribute.
// So we need to use bitwise operators to check if the values exists or to get current console colors.
let attrs = csbi.attributes();
let bg_color = attrs & 0x0070;
let mut color = BLUE_FOREGROUND | bg_color;
// background intensity is a separate value in attrs,
// wee need to check if this was applied to the current bg color.
if (attrs & 0x0080 as u16) != 0 {
color = color | 0x0080 as u16;
}
// set the console text attribute to the new color value.
Console::from(screen_buffer.handle().clone()).set_text_attribute(color)?;
Ok(())
}
sourcepub fn set_console_info(
&self,
absolute: bool,
rect: WindowPositions
) -> Result<()>
pub fn set_console_info( &self, absolute: bool, rect: WindowPositions ) -> Result<()>
Sets the current size and position of a console screen buffer’s window.
This wraps
SetConsoleWindowInfo
.
sourcepub fn fill_whit_character(
&self,
start_location: Coord,
cells_to_write: u32,
filling_char: char
) -> Result<u32>
pub fn fill_whit_character( &self, start_location: Coord, cells_to_write: u32, filling_char: char ) -> Result<u32>
Writes a character to the console screen buffer a specified number of times, beginning at the specified coordinates. Returns the number of characters that have been written.
This wraps
FillConsoleOutputCharacterA
.
sourcepub fn fill_whit_attribute(
&self,
start_location: Coord,
cells_to_write: u32,
dw_attribute: u16
) -> Result<u32>
pub fn fill_whit_attribute( &self, start_location: Coord, cells_to_write: u32, dw_attribute: u16 ) -> Result<u32>
Sets the character attributes for a specified number of character cells, beginning at the specified coordinates in a screen buffer. Returns the number of cells that have been modified.
This wraps
FillConsoleOutputAttribute
.
sourcepub fn largest_window_size(&self) -> Result<Coord>
pub fn largest_window_size(&self) -> Result<Coord>
Retrieves the size of the largest possible console window, based on the current text and the size of the display.
This wraps GetLargestConsoleWindowSize
sourcepub fn write_char_buffer(&self, buf: &[u8]) -> Result<usize>
pub fn write_char_buffer(&self, buf: &[u8]) -> Result<usize>
Writes a character string to a console screen buffer beginning at the current cursor location.
This wraps
WriteConsoleW
.
sourcepub fn read_single_input_event(&self) -> Result<InputRecord>
pub fn read_single_input_event(&self) -> Result<InputRecord>
Read one input event.
This wraps
ReadConsoleInputW
.
sourcepub fn read_console_input(&self) -> Result<Vec<InputRecord>>
pub fn read_console_input(&self) -> Result<Vec<InputRecord>>
Read all available input events without blocking.
This wraps
ReadConsoleInputW
.
sourcepub fn number_of_console_input_events(&self) -> Result<u32>
pub fn number_of_console_input_events(&self) -> Result<u32>
Get the number of available input events that can be read without blocking.
This wraps
GetNumberOfConsoleInputEvents
.