summaryrefslogtreecommitdiffstats
path: root/wincolor
diff options
context:
space:
mode:
authorPeter Williams <peter@newton.cx>2017-01-15 15:36:00 -0500
committerAndrew Gallant <jamslam@gmail.com>2017-01-17 10:42:35 -0500
commite573ab5c609194c4610bf27cc85302450a170d67 (patch)
tree2ba04984a248567761241a9c7dd0b5ce61a1a06b /wincolor
parentf5a2d022ecd16dfe67ea829267e9220136f20167 (diff)
Add stderr support to wincolor.
Diffstat (limited to 'wincolor')
-rw-r--r--wincolor/src/win.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/wincolor/src/win.rs b/wincolor/src/win.rs
index 09de3eb6..e61240b7 100644
--- a/wincolor/src/win.rs
+++ b/wincolor/src/win.rs
@@ -3,7 +3,7 @@ use std::mem;
use kernel32;
use winapi::{DWORD, HANDLE, WORD};
-use winapi::winbase::STD_OUTPUT_HANDLE;
+use winapi::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
use winapi::wincon::{
FOREGROUND_BLUE as FG_BLUE,
FOREGROUND_GREEN as FG_GREEN,
@@ -44,13 +44,11 @@ impl Drop for Console {
}
impl Console {
- /// Create a new Console to stdout.
- ///
- /// If there was a problem creating the console, then an error is returned.
- pub fn stdout() -> io::Result<Console> {
+ /// Get a console for a standard I/O stream.
+ fn create_for_stream(handle_id: DWORD) -> io::Result<Console> {
let mut info = unsafe { mem::zeroed() };
let (handle, res) = unsafe {
- let handle = kernel32::GetStdHandle(STD_OUTPUT_HANDLE);
+ let handle = kernel32::GetStdHandle(handle_id);
(handle, kernel32::GetConsoleScreenBufferInfo(handle, &mut info))
};
if res == 0 {
@@ -64,6 +62,20 @@ impl Console {
})
}
+ /// Create a new Console to stdout.
+ ///
+ /// If there was a problem creating the console, then an error is returned.
+ pub fn stdout() -> io::Result<Console> {
+ Self::create_for_stream(STD_OUTPUT_HANDLE)
+ }
+
+ /// Create a new Console to stderr.
+ ///
+ /// If there was a problem creating the console, then an error is returned.
+ pub fn stderr() -> io::Result<Console> {
+ Self::create_for_stream(STD_ERROR_HANDLE)
+ }
+
/// Applies the current text attributes.
fn set(&mut self) -> io::Result<()> {
let attr = self.cur_attr.to_word();