]> git.lizzy.rs Git - rust.git/blob - src/libtest/helpers/isatty.rs
Rollup merge of #67561 - euclio:remove-description, r=jonas-schievink
[rust.git] / src / libtest / helpers / isatty.rs
1 //! Helper module which provides a function to test
2 //! if stdout is a tty.
3
4 #[cfg(any(
5     target_os = "cloudabi",
6     target_os = "hermit",
7     all(target_arch = "wasm32", not(target_os = "emscripten")),
8     all(target_vendor = "fortanix", target_env = "sgx")
9 ))]
10 pub fn stdout_isatty() -> bool {
11     // FIXME: Implement isatty on SGX
12     false
13 }
14 #[cfg(unix)]
15 pub fn stdout_isatty() -> bool {
16     unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
17 }
18 #[cfg(windows)]
19 pub fn stdout_isatty() -> bool {
20     type DWORD = u32;
21     type BOOL = i32;
22     type HANDLE = *mut u8;
23     type LPDWORD = *mut u32;
24     const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
25     extern "system" {
26         fn GetStdHandle(which: DWORD) -> HANDLE;
27         fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL;
28     }
29     unsafe {
30         let handle = GetStdHandle(STD_OUTPUT_HANDLE);
31         let mut out = 0;
32         GetConsoleMode(handle, &mut out) != 0
33     }
34 }