#winapi #crossterm #windows #abstractions #screen_buffer

crossterm_winapi

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

8 releases

✓ Uses Rust 2018 edition

0.2.1 Sep 25, 2019
0.2.0 Sep 24, 2019
0.1.5 Jul 25, 2019
0.1.4 May 20, 2019
0.1.1 Jan 27, 2019

#1 in #winapi

Download history 232/week @ 2019-06-12 183/week @ 2019-06-19 265/week @ 2019-06-26 296/week @ 2019-07-03 324/week @ 2019-07-10 328/week @ 2019-07-17 309/week @ 2019-07-24 319/week @ 2019-07-31 424/week @ 2019-08-07 1352/week @ 2019-08-14 1282/week @ 2019-08-21 721/week @ 2019-08-28 480/week @ 2019-09-04 531/week @ 2019-09-11 547/week @ 2019-09-18

2,386 downloads per month
Used in 48 crates (6 directly)

MIT license

42KB
728 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.)
  • 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

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

~26KB