Skip to content

Commit

Permalink
Fix windows build errors, winapi 0.3.5 compability
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hauser committed Jun 11, 2018
1 parent 7f32a94 commit b69de45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
[package]
name = "term_cursor"
description = "A crate for handling terminal cursor movement in a platform independent way."
version = "0.2.0"
version = "0.2.1"
authors = ["Daniel Hauser <daniel.hauser@liwest.at>"]
keywords = ["terminal", "console", "cursor", "caret"]
license = "MIT"
repository = "https://github.com/Lisoph/term_cursor"
readme = "README.md"

[target."cfg(windows)".dependencies]
winapi = "0.3.4"
kernel32-sys = "0.2.2"
winapi = { version = "0.3.5", features = ["minwindef", "winbase", "wincon", "processenv"] }

[target."cfg(not(windows))".dependencies]
termios = "0.3.0"
25 changes: 11 additions & 14 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ pub use self::platform_impl::*;

#[cfg(target_os = "windows")]
mod platform_impl {
use super::*;

extern crate kernel32;
extern crate winapi;
use super::*;

use std::io::Write;

use self::winapi::minwindef::{DWORD, FALSE};
use self::winapi::winbase;
use self::winapi::wincon::CONSOLE_SCREEN_BUFFER_INFOEX as ScreenBufferInfo;
use self::winapi::wincon::COORD;
use self::winapi::winnt::{HANDLE, WCHAR};
use self::winapi::{shared::minwindef::{DWORD, FALSE},
um::{processenv, winbase, wincon,
wincon::{CONSOLE_SCREEN_BUFFER_INFOEX as ScreenBufferInfo, COORD},
winnt::{HANDLE, WCHAR}}};

fn get_handle() -> Result<HANDLE, Error> {
match unsafe { kernel32::GetStdHandle(winbase::STD_OUTPUT_HANDLE) } {
match unsafe { processenv::GetStdHandle(winbase::STD_OUTPUT_HANDLE) } {
hdl if hdl.is_null() => Err(Error::PlatformSpecific),
hdl => Ok(hdl),
}
Expand All @@ -30,7 +27,7 @@ mod platform_impl {
unsafe {
let mut info: ScreenBufferInfo = std::mem::zeroed();
info.cbSize = std::mem::size_of::<ScreenBufferInfo>() as u32;
match kernel32::GetConsoleScreenBufferInfoEx(get_handle()?, &mut info as *mut _) {
match wincon::GetConsoleScreenBufferInfoEx(get_handle()?, &mut info as *mut _) {
FALSE => Err(Error::PlatformSpecific),
_ => Ok(info),
}
Expand All @@ -43,7 +40,7 @@ mod platform_impl {
X: x as i16,
Y: y as i16,
};
match unsafe { kernel32::SetConsoleCursorPosition(get_handle()?, coord) } {
match unsafe { wincon::SetConsoleCursorPosition(get_handle()?, coord) } {
FALSE => Err(Error::PlatformSpecific),
_ => Ok(()),
}
Expand All @@ -65,7 +62,7 @@ mod platform_impl {
let mut _written: DWORD = 0;

let res = unsafe {
kernel32::FillConsoleOutputCharacterW(
wincon::FillConsoleOutputCharacterW(
get_handle()?,
' ' as WCHAR,
size,
Expand All @@ -79,7 +76,7 @@ mod platform_impl {
}

let res = unsafe {
kernel32::FillConsoleOutputAttribute(
wincon::FillConsoleOutputAttribute(
get_handle()?,
info.wAttributes,
size,
Expand Down Expand Up @@ -128,7 +125,7 @@ mod platform_impl {
stdout.flush()?;

let mut buf = [0u8; 2];

// Expect `ESC[`
std::io::stdin().read_exact(&mut buf)?;
if buf[0] != 0x1B || buf[1] as char != '[' {
Expand Down

0 comments on commit b69de45

Please sign in to comment.