#winapi #crossterm #windows #abstractions #screen_buffer

crossterm_winapi

An WinApi wrapper that provides some basic simple abstractions aground common WinApi calls

3 releases

0.1.2 Apr 2, 2019
0.1.1 Jan 27, 2019
0.1.0 Jan 2, 2019

#13 in Windows APIs

Download history 11/week @ 2018-12-27 46/week @ 2019-01-03 53/week @ 2019-01-10 107/week @ 2019-01-17 110/week @ 2019-01-24 164/week @ 2019-01-31 79/week @ 2019-02-07 104/week @ 2019-02-14 135/week @ 2019-02-21 76/week @ 2019-02-28 108/week @ 2019-03-07 145/week @ 2019-03-14 123/week @ 2019-03-21 133/week @ 2019-03-28

455 downloads per month
Used in 17 crates (6 directly)

MIT license

41KB
699 lines

Crossterm Winapi | Common WinApi Abstractions

Lines of Code Latest Version MIT docs

This crate provides some wrappers aground common used WinApi functions. The purpose of this library is originally meant for crossterm, and it is very unstable right because of that some changes 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.)
  • 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

Example

Here are some examples do demonstrate how to work whit this crate. Please see examples for more

Screenbuffer 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();
}

Inspiration

I wanted to expose some of the api crossterm uses for WinApi.

  1. I thought it would be helpful for other people to, to have a small rust seemable abstraction over the WinApi bindings.
  2. I have some future plans for crossterm wherefore I needed to seperate the WinAPi logic out of the currenbt librarie.

Dependencies

~531KB

  • winapi 0.3.5+winbase+consoleapi+processenv+handleapi