Struct crossterm_winapi::Handle
source · pub struct Handle { /* private fields */ }
Expand description
This abstracts away some WinAPI calls to set and get some console handles.
It wraps WinAPI’s HANDLE
type.
Implementations§
source§impl Handle
impl Handle
sourcepub fn new(handle: HandleType) -> Result<Handle>
pub fn new(handle: HandleType) -> Result<Handle>
Create a new handle of a certaint type.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() -> Result<()> {
// see the description of the types to see what they do.
let out_put_handle = Handle::new(HandleType::OutputHandle)?;
let out_put_handle = Handle::new(HandleType::InputHandle)?;
let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle)?;
let curr_out_put_handle = Handle::new(HandleType::CurrentInputHandle)?;
// now you have this handle you might want to get the WinAPI `HANDLE` it is wrapping.
// you can do this by defencing.
let handle /*:HANDLE*/ = *out_put_handle;
// you can also pass you own `HANDLE` to create an instance of `Handle`
let handle = unsafe { Handle::from_raw(handle) }; /* winapi::um::winnt::HANDLE */
Ok(())
}
sourcepub unsafe fn from_raw(handle: HANDLE) -> Self
pub unsafe fn from_raw(handle: HANDLE) -> Self
Construct a handle from a raw handle.
Safety
This is unsafe since there is not guarantee that the underlying HANDLE is thread-safe to implement Send
and Sync
.
Most HANDLE’s however, are thread safe.
Examples found in repository?
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
fn main() -> Result<()> {
// see the description of the types to see what they do.
let out_put_handle = Handle::new(HandleType::OutputHandle)?;
let out_put_handle = Handle::new(HandleType::InputHandle)?;
let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle)?;
let curr_out_put_handle = Handle::new(HandleType::CurrentInputHandle)?;
// now you have this handle you might want to get the WinAPI `HANDLE` it is wrapping.
// you can do this by defencing.
let handle /*:HANDLE*/ = *out_put_handle;
// you can also pass you own `HANDLE` to create an instance of `Handle`
let handle = unsafe { Handle::from_raw(handle) }; /* winapi::um::winnt::HANDLE */
Ok(())
}
sourcepub fn current_out_handle() -> Result<Handle>
pub fn current_out_handle() -> Result<Handle>
Get the handle of the active screen buffer. When using multiple screen buffers this will always point to the to the current screen output buffer.
This function uses CONOUT$
to create a file handle to the current output buffer.
This wraps
CreateFileW
.
sourcepub fn current_in_handle() -> Result<Handle>
pub fn current_in_handle() -> Result<Handle>
Get the handle of the console input buffer.
This function uses CONIN$
to create a file handle to the current input buffer.
This wraps
CreateFileW
.
sourcepub fn output_handle() -> Result<Handle>
pub fn output_handle() -> Result<Handle>
Get the handle of the standard output.
On success this function returns the HANDLE
to STD_OUTPUT_HANDLE
.
This wraps GetStdHandle
called with STD_OUTPUT_HANDLE
.
sourcepub fn input_handle() -> Result<Handle>
pub fn input_handle() -> Result<Handle>
Get the handle of the input screen buffer.
On success this function returns the HANDLE
to STD_INPUT_HANDLE
.
This wraps GetStdHandle
called with STD_INPUT_HANDLE
.
sourcepub fn is_valid_handle(handle: &HANDLE) -> bool
pub fn is_valid_handle(handle: &HANDLE) -> bool
Checks if the console handle is an invalid handle value.
This is done by checking if the passed HANDLE
is equal to INVALID_HANDLE_VALUE
.