#winapi #abstraction #crossterm #windows #screen-buffer

crossterm_winapi

WinAPI wrapper that provides some basic simple abstractions around common WinAPI calls

19 releases

0.9.1 Jun 12, 2023
0.9.0 Oct 19, 2021
0.8.1 Oct 11, 2021
0.8.0 May 6, 2021
0.1.1 Jan 27, 2019

#20 in Windows APIs

Download history 87652/week @ 2023-11-21 104685/week @ 2023-11-28 93365/week @ 2023-12-05 90474/week @ 2023-12-12 86902/week @ 2023-12-19 55792/week @ 2023-12-26 94097/week @ 2024-01-02 104660/week @ 2024-01-09 113214/week @ 2024-01-16 133858/week @ 2024-01-23 137630/week @ 2024-01-30 135907/week @ 2024-02-06 130623/week @ 2024-02-13 133442/week @ 2024-02-20 132801/week @ 2024-02-27 107859/week @ 2024-03-05

526,055 downloads per month
Used in 1,677 crates (9 directly)

MIT license

51KB
849 lines

Lines of Code Latest Version MIT docs

Crossterm Windows API Abstractions

This crate provides some wrappers aground common used WinAPI functions.

The purpose of this library is originally meant for the crossterm, but could be used apart from it. Although, notice that it unstable right because some changes to the API could be expected.

Features

This crate provides some abstractions over reading input, console screen buffer, and handle.

The following WinAPI calls:

  • CONSOLE_SCREEN_BUFFER_INFO (used to extract information like cursor pos, terminal size etc.)
  • CONSOLE_FONT_INFO (used to extract font info like size)
  • HANDLE (the handle needed to run functions from WinAPI)
  • SetConsoleActiveScreenBuffer (activate an other screen buffer)
  • Set/GetConsoleMode (e.g. console modes like disabling output)
  • SetConsoleTextAttribute (eg. coloring)
  • SetConsoleWindowInfo (changing the buffer location e.g. scrolling)
  • FillConsoleOutputAttribute, FillConsoleOutputCharacter (used to replace some block of cells with a color or character.)
  • SetConsoleInfo
  • ReadConsoleW
  • Semaphore object handling

Example

The examples repository has more complete and verbose examples.

Screen buffer information

use crossterm_winapi::{ScreenBuffer, Handle};

fn print_screen_buffer_information() {
    let screen_buffer = ScreenBuffer::current().unwrap();

    // get console screen buffer information
    let csbi = screen_buffer.info().unwrap();

    println!("cursor post: {:?}", csbi.cursor_pos());
    println!("attributes: {:?}", csbi.attributes());
    println!("terminal window dimentions {:?}", csbi.terminal_window());
    println!("terminal size {:?}", csbi.terminal_size());
}

Handle

use crossterm_winapi::{HandleType, Handle};

fn get_different_handle_types() {
    let out_put_handle = Handle::new(HandleType::OutputHandle).unwrap();
    let out_put_handle = Handle::new(HandleType::InputHandle).unwrap();
    let curr_out_put_handle = Handle::new(HandleType::CurrentOutputHandle).unwrap();
    let curr_out_put_handle = Handle::new(HandleType::CurrentInputHandle).unwrap();
}

Dependencies

~175KB