summaryrefslogtreecommitdiffstats
path: root/wincolor/src/win.rs
diff options
context:
space:
mode:
Diffstat (limited to 'wincolor/src/win.rs')
-rw-r--r--wincolor/src/win.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/wincolor/src/win.rs b/wincolor/src/win.rs
index 8d5594c8..43ccdcdd 100644
--- a/wincolor/src/win.rs
+++ b/wincolor/src/win.rs
@@ -2,6 +2,7 @@ use std::io;
use std::mem;
use winapi::shared::minwindef::{DWORD, WORD};
+use winapi::um::consoleapi;
use winapi::um::processenv;
use winapi::um::winbase::{STD_ERROR_HANDLE, STD_OUTPUT_HANDLE};
use winapi::um::wincon::{
@@ -115,6 +116,35 @@ impl Console {
self.cur_attr = self.start_attr;
self.set()
}
+
+ /// Toggle virtual terminal processing.
+ ///
+ /// This method attempts to toggle virtual terminal processing for this
+ /// console. If there was a problem toggling it, then an error returned.
+ /// On success, the caller may assume that toggling it was successful.
+ ///
+ /// When virtual terminal processing is enabled, characters emitted to the
+ /// console are parsed for VT100 and similar control character sequences
+ /// that control color and other similar operations.
+ pub fn set_virtual_terminal_processing(
+ &mut self,
+ yes: bool,
+ ) -> io::Result<()> {
+ let mut lpmode = 0;
+ let handle = unsafe { processenv::GetStdHandle(self.handle_id) };
+ if unsafe { consoleapi::GetConsoleMode(handle, &mut lpmode) } == 0 {
+ return Err(io::Error::last_os_error());
+ }
+ if yes {
+ lpmode |= wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+ } else {
+ lpmode &= !wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+ }
+ if unsafe { consoleapi::SetConsoleMode(handle, lpmode) } == 0 {
+ return Err(io::Error::last_os_error());
+ }
+ Ok(())
+ }
}
/// A representation of text attributes for the Windows console.