Trait WindowsApi
pub trait WindowsApi: Send + Sync {
Show 34 methods
// Required methods
fn set_console_title(&self, title: &str) -> Result<()>;
fn get_console_title(&self, buffer: &mut [u16]) -> i32;
fn get_os_version(&self) -> String;
fn arrange_console(
&self,
x: i32,
y: i32,
width: i32,
height: i32,
) -> Result<()>;
fn set_console_text_attribute(
&self,
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> Result<()>;
fn get_console_screen_buffer_info(
&self,
) -> Result<CONSOLE_SCREEN_BUFFER_INFO>;
fn fill_console_output_attribute(
&self,
attribute: u16,
length: u32,
coord: COORD,
) -> Result<u32>;
fn scroll_console_screen_buffer(
&self,
scroll_rect: SMALL_RECT,
scroll_target: COORD,
fill_char: CHAR_INFO,
) -> Result<()>;
fn set_console_cursor_position(&self, position: COORD) -> Result<()>;
fn get_std_handle(&self, handle_type: STD_HANDLE) -> Result<HANDLE>;
fn read_console_input(&self, buffer: &mut [INPUT_RECORD]) -> Result<u32>;
fn set_console_border_color(&self, color: &COLORREF) -> Result<()>;
fn invalidate_console_window(&self) -> Result<()>;
fn write_console_input(
&self,
buffer: &[INPUT_RECORD],
number_written: &mut u32,
) -> Result<()>;
fn get_last_error(&self) -> u32;
fn generate_console_ctrl_event(
&self,
ctrl_event: u32,
process_group_id: u32,
) -> Result<()>;
fn get_stdout_handle(&self) -> Result<HANDLE>;
fn get_console_attached_process_count(&self) -> u32;
fn create_process_raw(
&self,
application: &str,
command_line: PWSTR,
startup_info: &mut STARTUPINFOW,
process_info: &mut PROCESS_INFORMATION,
) -> Result<()>;
fn get_window_handle_for_process(&self, process_id: u32) -> HWND;
fn get_console_window(&self) -> HWND;
fn get_foreground_window(&self) -> HWND;
fn bring_window_to_top(
&self,
hwnd: HWND,
with_keyboard_focus: bool,
) -> Result<()>;
fn get_console_mode(&self, handle: HANDLE) -> Result<CONSOLE_MODE>;
fn set_console_mode(&self, handle: HANDLE, mode: CONSOLE_MODE) -> Result<()>;
fn get_exit_code(&self, handle: HANDLE) -> Result<u32>;
fn move_window(
&self,
hwnd: HWND,
x: i32,
y: i32,
width: i32,
height: i32,
repaint: bool,
) -> Result<()>;
fn get_window_placement(&self, hwnd: HWND) -> Result<WINDOWPLACEMENT>;
fn show_window(&self, hwnd: HWND, cmd_show: SHOW_WINDOW_CMD) -> Result<bool>;
fn is_window(&self, hwnd: HWND) -> bool;
fn open_process(
&self,
access: u32,
inherit: bool,
process_id: u32,
) -> Result<HANDLE>;
fn get_system_metrics(&self, index: SYSTEM_METRICS_INDEX) -> i32;
fn set_process_dpi_awareness(
&self,
value: PROCESS_DPI_AWARENESS,
) -> Result<()>;
// Provided method
fn create_process_with_args(
&self,
application: &str,
args: Vec<String>,
with_keyboard_focus: bool,
) -> Option<PROCESS_INFORMATION> { ... }
}Expand description
Trait for Windows API operations to enable mocking in tests.
This trait abstracts Windows API calls to allow for unit testing without actual system interaction. All console and system operations should go through this trait.
Required Methods§
fn set_console_title(&self, title: &str) -> Result<()>
fn set_console_title(&self, title: &str) -> Result<()>
fn get_console_title(&self, buffer: &mut [u16]) -> i32
fn get_console_title(&self, buffer: &mut [u16]) -> i32
fn get_os_version(&self) -> String
fn get_os_version(&self) -> String
fn arrange_console(&self, x: i32, y: i32, width: i32, height: i32) -> Result<()>
fn arrange_console(&self, x: i32, y: i32, width: i32, height: i32) -> Result<()>
Arranges the console window position and size.
§Arguments
x- The x coordinate to move the window toy- The y coordinate to move the window towidth- The width in pixels to resize the window toheight- The height in pixels to resize the window to
§Returns
Result indicating success or failure of the operation
fn set_console_text_attribute(
&self,
attributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> Result<()>
fn set_console_text_attribute( &self, attributes: CONSOLE_CHARACTER_ATTRIBUTES, ) -> Result<()>
fn get_console_screen_buffer_info(&self) -> Result<CONSOLE_SCREEN_BUFFER_INFO>
fn get_console_screen_buffer_info(&self) -> Result<CONSOLE_SCREEN_BUFFER_INFO>
fn fill_console_output_attribute(
&self,
attribute: u16,
length: u32,
coord: COORD,
) -> Result<u32>
fn fill_console_output_attribute( &self, attribute: u16, length: u32, coord: COORD, ) -> Result<u32>
fn scroll_console_screen_buffer(
&self,
scroll_rect: SMALL_RECT,
scroll_target: COORD,
fill_char: CHAR_INFO,
) -> Result<()>
fn scroll_console_screen_buffer( &self, scroll_rect: SMALL_RECT, scroll_target: COORD, fill_char: CHAR_INFO, ) -> Result<()>
fn set_console_cursor_position(&self, position: COORD) -> Result<()>
fn set_console_cursor_position(&self, position: COORD) -> Result<()>
fn get_std_handle(&self, handle_type: STD_HANDLE) -> Result<HANDLE>
fn get_std_handle(&self, handle_type: STD_HANDLE) -> Result<HANDLE>
fn read_console_input(&self, buffer: &mut [INPUT_RECORD]) -> Result<u32>
fn read_console_input(&self, buffer: &mut [INPUT_RECORD]) -> Result<u32>
fn set_console_border_color(&self, color: &COLORREF) -> Result<()>
fn set_console_border_color(&self, color: &COLORREF) -> Result<()>
fn invalidate_console_window(&self) -> Result<()>
fn invalidate_console_window(&self) -> Result<()>
Marks the entire console window client area as needing a redraw.
Used to nudge the legacy Win10 conhost into repainting from its own buffer state after bulk attribute changes that the renderer otherwise leaves stale on the trailing row/column.
§Returns
Result indicating success or failure of the operation
fn write_console_input(
&self,
buffer: &[INPUT_RECORD],
number_written: &mut u32,
) -> Result<()>
fn write_console_input( &self, buffer: &[INPUT_RECORD], number_written: &mut u32, ) -> Result<()>
fn get_last_error(&self) -> u32
fn get_last_error(&self) -> u32
fn generate_console_ctrl_event(
&self,
ctrl_event: u32,
process_group_id: u32,
) -> Result<()>
fn generate_console_ctrl_event( &self, ctrl_event: u32, process_group_id: u32, ) -> Result<()>
fn get_stdout_handle(&self) -> Result<HANDLE>
fn get_stdout_handle(&self) -> Result<HANDLE>
fn get_console_attached_process_count(&self) -> u32
fn get_console_attached_process_count(&self) -> u32
fn create_process_raw(
&self,
application: &str,
command_line: PWSTR,
startup_info: &mut STARTUPINFOW,
process_info: &mut PROCESS_INFORMATION,
) -> Result<()>
fn create_process_raw( &self, application: &str, command_line: PWSTR, startup_info: &mut STARTUPINFOW, process_info: &mut PROCESS_INFORMATION, ) -> Result<()>
fn get_window_handle_for_process(&self, process_id: u32) -> HWND
fn get_window_handle_for_process(&self, process_id: u32) -> HWND
fn get_console_window(&self) -> HWND
fn get_console_window(&self) -> HWND
fn get_foreground_window(&self) -> HWND
fn get_foreground_window(&self) -> HWND
fn bring_window_to_top(
&self,
hwnd: HWND,
with_keyboard_focus: bool,
) -> Result<()>
fn bring_window_to_top( &self, hwnd: HWND, with_keyboard_focus: bool, ) -> Result<()>
Bring hwnd to the top of the z-order.
When with_keyboard_focus is true the window is also activated and
receives keyboard focus. When false the window is raised without
activation, avoiding the taskbar flash that would happen if the
window is not the current input target.
§Arguments
hwnd- Handle to the window to raise.with_keyboard_focus- Whether to activate the window and give it keyboard focus.
§Returns
Result indicating success or failure of the operation
fn get_console_mode(&self, handle: HANDLE) -> Result<CONSOLE_MODE>
fn get_console_mode(&self, handle: HANDLE) -> Result<CONSOLE_MODE>
fn set_console_mode(&self, handle: HANDLE, mode: CONSOLE_MODE) -> Result<()>
fn set_console_mode(&self, handle: HANDLE, mode: CONSOLE_MODE) -> Result<()>
fn get_exit_code(&self, handle: HANDLE) -> Result<u32>
fn get_exit_code(&self, handle: HANDLE) -> Result<u32>
fn move_window(
&self,
hwnd: HWND,
x: i32,
y: i32,
width: i32,
height: i32,
repaint: bool,
) -> Result<()>
fn move_window( &self, hwnd: HWND, x: i32, y: i32, width: i32, height: i32, repaint: bool, ) -> Result<()>
fn get_window_placement(&self, hwnd: HWND) -> Result<WINDOWPLACEMENT>
fn get_window_placement(&self, hwnd: HWND) -> Result<WINDOWPLACEMENT>
fn show_window(&self, hwnd: HWND, cmd_show: SHOW_WINDOW_CMD) -> Result<bool>
fn show_window(&self, hwnd: HWND, cmd_show: SHOW_WINDOW_CMD) -> Result<bool>
fn open_process(
&self,
access: u32,
inherit: bool,
process_id: u32,
) -> Result<HANDLE>
fn open_process( &self, access: u32, inherit: bool, process_id: u32, ) -> Result<HANDLE>
fn get_system_metrics(&self, index: SYSTEM_METRICS_INDEX) -> i32
fn get_system_metrics(&self, index: SYSTEM_METRICS_INDEX) -> i32
fn set_process_dpi_awareness(&self, value: PROCESS_DPI_AWARENESS) -> Result<()>
fn set_process_dpi_awareness(&self, value: PROCESS_DPI_AWARENESS) -> Result<()>
Provided Methods§
fn create_process_with_args(
&self,
application: &str,
args: Vec<String>,
with_keyboard_focus: bool,
) -> Option<PROCESS_INFORMATION>
fn create_process_with_args( &self, application: &str, args: Vec<String>, with_keyboard_focus: bool, ) -> Option<PROCESS_INFORMATION>
Create a new process attached to its own console window.
When with_keyboard_focus is false the new console window is
shown without activation (STARTF_USESHOWWINDOW +
SW_SHOWNOACTIVATE), so the caller retains keyboard focus.
Used when the daemon spawns client consoles - otherwise the
last-spawned client wins the foreground and Windows refuses to
let the daemon steal it back.
§Arguments
application- Application name including file extensionargs- List of arguments to the applicationwith_keyboard_focus- Whether the new console window should take foreground focus when it appears.
§Returns
Process information if successful, None otherwise