mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-01 04:32:01 -07:00
Add stderr support to wincolor.
This commit is contained in:
committed by
Andrew Gallant
parent
f5a2d022ec
commit
e573ab5c60
@@ -3,7 +3,7 @@ use std::mem;
|
|||||||
|
|
||||||
use kernel32;
|
use kernel32;
|
||||||
use winapi::{DWORD, HANDLE, WORD};
|
use winapi::{DWORD, HANDLE, WORD};
|
||||||
use winapi::winbase::STD_OUTPUT_HANDLE;
|
use winapi::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
|
||||||
use winapi::wincon::{
|
use winapi::wincon::{
|
||||||
FOREGROUND_BLUE as FG_BLUE,
|
FOREGROUND_BLUE as FG_BLUE,
|
||||||
FOREGROUND_GREEN as FG_GREEN,
|
FOREGROUND_GREEN as FG_GREEN,
|
||||||
@@ -44,13 +44,11 @@ impl Drop for Console {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Console {
|
impl Console {
|
||||||
/// Create a new Console to stdout.
|
/// Get a console for a standard I/O stream.
|
||||||
///
|
fn create_for_stream(handle_id: DWORD) -> io::Result<Console> {
|
||||||
/// If there was a problem creating the console, then an error is returned.
|
|
||||||
pub fn stdout() -> io::Result<Console> {
|
|
||||||
let mut info = unsafe { mem::zeroed() };
|
let mut info = unsafe { mem::zeroed() };
|
||||||
let (handle, res) = unsafe {
|
let (handle, res) = unsafe {
|
||||||
let handle = kernel32::GetStdHandle(STD_OUTPUT_HANDLE);
|
let handle = kernel32::GetStdHandle(handle_id);
|
||||||
(handle, kernel32::GetConsoleScreenBufferInfo(handle, &mut info))
|
(handle, kernel32::GetConsoleScreenBufferInfo(handle, &mut info))
|
||||||
};
|
};
|
||||||
if res == 0 {
|
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.
|
/// Applies the current text attributes.
|
||||||
fn set(&mut self) -> io::Result<()> {
|
fn set(&mut self) -> io::Result<()> {
|
||||||
let attr = self.cur_attr.to_word();
|
let attr = self.cur_attr.to_word();
|
||||||
|
Reference in New Issue
Block a user