summaryrefslogtreecommitdiffstats
path: root/wincolor
diff options
context:
space:
mode:
authorSteffen Butzer <steffen.butzer@outlook.com>2017-12-29 23:53:18 +0100
committerAndrew Gallant <jamslam@gmail.com>2017-12-30 16:50:18 -0500
commit0d03145293465042bbcd1e323906861c8b5ca18f (patch)
tree73caf4a35e43bc11494bb237f16600b194b8c560 /wincolor
parentf8162d2707d34c26e15325d1abe02a0d926fb845 (diff)
wincolor: migrate to winapi 0.3
Diffstat (limited to 'wincolor')
-rw-r--r--wincolor/Cargo.toml3
-rw-r--r--wincolor/src/lib.rs2
-rw-r--r--wincolor/src/win.rs52
3 files changed, 27 insertions, 30 deletions
diff --git a/wincolor/Cargo.toml b/wincolor/Cargo.toml
index 3bacc0d5..b686082a 100644
--- a/wincolor/Cargo.toml
+++ b/wincolor/Cargo.toml
@@ -17,5 +17,4 @@ name = "wincolor"
bench = false
[dependencies]
-kernel32-sys = "0.2.2"
-winapi = "0.2.8"
+winapi = { version = "0.3", features = ["minwindef", "processenv", "winbase", "wincon"] }
diff --git a/wincolor/src/lib.rs b/wincolor/src/lib.rs
index 457f33ae..722cbd53 100644
--- a/wincolor/src/lib.rs
+++ b/wincolor/src/lib.rs
@@ -24,8 +24,6 @@ println!("This text will be normal.");
#![deny(missing_docs)]
#[cfg(windows)]
-extern crate kernel32;
-#[cfg(windows)]
extern crate winapi;
#[cfg(windows)]
diff --git a/wincolor/src/win.rs b/wincolor/src/win.rs
index c0ad8359..8d5594c8 100644
--- a/wincolor/src/win.rs
+++ b/wincolor/src/win.rs
@@ -1,20 +1,21 @@
use std::io;
use std::mem;
-use kernel32;
-use winapi::{DWORD, WORD};
-use winapi::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
-use winapi::wincon::{
+use winapi::shared::minwindef::{DWORD, WORD};
+use winapi::um::processenv;
+use winapi::um::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
+use winapi::um::wincon::{
+ self,
FOREGROUND_BLUE as FG_BLUE,
FOREGROUND_GREEN as FG_GREEN,
FOREGROUND_RED as FG_RED,
FOREGROUND_INTENSITY as FG_INTENSITY,
};
-const FG_CYAN: DWORD = FG_BLUE | FG_GREEN;
-const FG_MAGENTA: DWORD = FG_BLUE | FG_RED;
-const FG_YELLOW: DWORD = FG_GREEN | FG_RED;
-const FG_WHITE: DWORD = FG_BLUE | FG_GREEN | FG_RED;
+const FG_CYAN: WORD = FG_BLUE | FG_GREEN;
+const FG_MAGENTA: WORD = FG_BLUE | FG_RED;
+const FG_YELLOW: WORD = FG_GREEN | FG_RED;
+const FG_WHITE: WORD = FG_BLUE | FG_GREEN | FG_RED;
/// A Windows console.
///
@@ -40,8 +41,8 @@ impl Console {
fn create_for_stream(handle_id: DWORD) -> io::Result<Console> {
let mut info = unsafe { mem::zeroed() };
let res = unsafe {
- let handle = kernel32::GetStdHandle(handle_id);
- kernel32::GetConsoleScreenBufferInfo(handle, &mut info)
+ let handle = processenv::GetStdHandle(handle_id);
+ wincon::GetConsoleScreenBufferInfo(handle, &mut info)
};
if res == 0 {
return Err(io::Error::last_os_error());
@@ -72,8 +73,8 @@ impl Console {
fn set(&mut self) -> io::Result<()> {
let attr = self.cur_attr.to_word();
let res = unsafe {
- let handle = kernel32::GetStdHandle(self.handle_id);
- kernel32::SetConsoleTextAttribute(handle, attr)
+ let handle = processenv::GetStdHandle(self.handle_id);
+ wincon::SetConsoleTextAttribute(handle, attr)
};
if res == 0 {
return Err(io::Error::last_os_error());
@@ -132,16 +133,15 @@ impl TextAttributes {
w |= self.fg_intense.to_fg();
w |= self.bg_color.to_bg();
w |= self.bg_intense.to_bg();
- w as WORD
+ w
}
fn from_word(word: WORD) -> TextAttributes {
- let attr = word as DWORD;
TextAttributes {
- fg_color: Color::from_fg(attr),
- fg_intense: Intense::from_fg(attr),
- bg_color: Color::from_bg(attr),
- bg_intense: Intense::from_bg(attr),
+ fg_color: Color::from_fg(word),
+ fg_intense: Intense::from_fg(word),
+ bg_color: Color::from_bg(word),
+ bg_intense: Intense::from_bg(word),
}
}
}
@@ -155,22 +155,22 @@ pub enum Intense {
}
impl Intense {
- fn to_bg(&self) -> DWORD {
+ fn to_bg(&self) -> WORD {
self.to_fg() << 4
}
- fn from_bg(word: DWORD) -> Intense {
+ fn from_bg(word: WORD) -> Intense {
Intense::from_fg(word >> 4)
}
- fn to_fg(&self) -> DWORD {
+ fn to_fg(&self) -> WORD {
match *self {
Intense::No => 0,
Intense::Yes => FG_INTENSITY,
}
}
- fn from_fg(word: DWORD) -> Intense {
+ fn from_fg(word: WORD) -> Intense {
if word & FG_INTENSITY > 0 {
Intense::Yes
} else {
@@ -194,15 +194,15 @@ pub enum Color {
}
impl Color {
- fn to_bg(&self) -> DWORD {
+ fn to_bg(&self) -> WORD {
self.to_fg() << 4
}
- fn from_bg(word: DWORD) -> Color {
+ fn from_bg(word: WORD) -> Color {
Color::from_fg(word >> 4)
}
- fn to_fg(&self) -> DWORD {
+ fn to_fg(&self) -> WORD {
match *self {
Color::Black => 0,
Color::Blue => FG_BLUE,
@@ -215,7 +215,7 @@ impl Color {
}
}
- fn from_fg(word: DWORD) -> Color {
+ fn from_fg(word: WORD) -> Color {
match word & 0b111 {
FG_BLUE => Color::Blue,
FG_GREEN => Color::Green,