Skip to content

Commit

Permalink
Add get_console_output_buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
whme committed Mar 17, 2024
1 parent a7af013 commit 9d2ecf6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ pub fn set_console_title(title: &str) {

pub fn set_console_color(color: CONSOLE_CHARACTER_ATTRIBUTES) {
unsafe {
SetConsoleTextAttribute(get_std_handle(STD_OUTPUT_HANDLE), color).unwrap();
SetConsoleTextAttribute(get_console_output_buffer(), color).unwrap();
}
let mut number_of_attrs_written: u32 = 0;
let mut buffer_info = CONSOLE_SCREEN_BUFFER_INFO::default();
unsafe {
GetConsoleScreenBufferInfo(get_std_handle(STD_OUTPUT_HANDLE), &mut buffer_info).unwrap();
GetConsoleScreenBufferInfo(get_console_output_buffer(), &mut buffer_info).unwrap();
for y in 0..buffer_info.dwSize.Y {
FillConsoleOutputAttribute(
get_std_handle(STD_OUTPUT_HANDLE),
get_console_output_buffer(),
color.0,
buffer_info.dwSize.X.try_into().unwrap(),
COORD { X: 0, Y: y },
Expand All @@ -60,7 +60,7 @@ pub fn set_console_color(color: CONSOLE_CHARACTER_ATTRIBUTES) {

pub fn clear_screen() {
let mut buffer_info = CONSOLE_SCREEN_BUFFER_INFO::default();
let console_output_handle = get_std_handle(STD_OUTPUT_HANDLE);
let console_output_handle = get_console_output_buffer();
unsafe {
GetConsoleScreenBufferInfo(console_output_handle, &mut buffer_info).unwrap();
}
Expand Down Expand Up @@ -145,6 +145,10 @@ pub fn get_console_input_buffer() -> HANDLE {
return get_std_handle(STD_INPUT_HANDLE);
}

pub fn get_console_output_buffer() -> HANDLE {
return get_std_handle(STD_OUTPUT_HANDLE);
}

fn read_console_input() -> INPUT_RECORD {
const NB_EVENTS: usize = 1;
let mut input_buffer: [INPUT_RECORD; NB_EVENTS] = [INPUT_RECORD::default(); NB_EVENTS];
Expand Down

0 comments on commit 9d2ecf6

Please sign in to comment.