windows.rs
This file
Path
src/windows.rs
39 lines · 1.4 KiB · Rust
Last changed by
Fix Windows moduleDavid Peterbefore adoption46db4a3
History of this fileTake it
Move 'win' crate back into local modulesharkdpbefore adoptionb3f1e18
lines 1–11why, one step back1// Copyright (c) 2017 fd developers2// Licensed under the Apache License, Version 2.03// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>4// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,5// at your option. All files in the project carrying such6// notice may not be copied, modified, or distributed except7// according to those terms.89extern crate kernel32;10extern crate winapi;11Fix Windows moduleDavid Peterbefore adoption46db4a3
lines 12–13why, one step back12use self::kernel32::{GetStdHandle, GetConsoleMode, SetConsoleMode};13use self::winapi::{STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE};Move 'win' crate back into local modulesharkdpbefore adoptionb3f1e18
lines 14–39why, one step back1415const ENABLE_VIRTUAL_TERMINAL_PROCESSING: u32 = 0x0004;1617// https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#example18pub fn enable_colored_output() -> bool {19 unsafe {20 let handle = GetStdHandle(STD_OUTPUT_HANDLE);21 if handle == INVALID_HANDLE_VALUE {22 return false;23 }2425 // https://docs.microsoft.com/en-us/windows/console/getconsolemode26 let mut mode = 0;27 if GetConsoleMode(handle, &mut mode) == 0 {28 return false;29 }30 mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;3132 // https://docs.microsoft.com/en-us/windows/console/setconsolemode33 //34 // A console consists of an input buffer and one or more screen buffers. ... Setting the35 // output modes of one screen buffer does not affect the output modes of other screen36 // buffers.37 SetConsoleMode(handle, mode) != 038 }39}