-
-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jakwings/fd@a44e677 -> subdirectory "win"
- Loading branch information
Showing
6 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "windows" | ||
version = "0.0.0" | ||
|
||
[dependencies] | ||
kernel32-sys = "0.2" | ||
winapi = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extern crate kernel32; | ||
extern crate winapi; | ||
|
||
use kernel32::{GetStdHandle, GetConsoleMode, SetConsoleMode}; | ||
use winapi::{STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE}; | ||
|
||
const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x0004; | ||
|
||
// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example | ||
pub fn enable_colored_output() -> bool { | ||
unsafe { | ||
let handle = GetStdHandle(STD_OUTPUT_HANDLE); | ||
if handle == INVALID_HANDLE_VALUE { | ||
return false; | ||
} | ||
|
||
// https://docs.microsoft.com/en-us/windows/console/getconsolemode | ||
let mut mode = 0; | ||
if GetConsoleMode(handle, &mut mode) == 0 { | ||
return false; | ||
} | ||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | ||
|
||
// https://docs.microsoft.com/en-us/windows/console/setconsolemode | ||
// | ||
// A console consists of an input buffer and one or more screen buffers. ... Setting the | ||
// output modes of one screen buffer does not affect the output modes of other screen | ||
// buffers. | ||
SetConsoleMode(handle, mode) != 0 | ||
} | ||
} |