]> git.lizzy.rs Git - rust.git/blob - src/libtest/helpers/isatty.rs
Rollup merge of #66789 - eddyb:mir-source-scope-local-data, r=oli-obk
[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", target_os = "hermit",
6     all(target_arch = "wasm32", not(target_os = "emscripten")),
7     all(target_vendor = "fortanix", target_env = "sgx")
8 ))]
9 pub fn stdout_isatty() -> bool {
10     // FIXME: Implement isatty on SGX
11     false
12 }
13 #[cfg(unix)]
14 pub fn stdout_isatty() -> bool {
15     unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
16 }
17 #[cfg(windows)]
18 pub fn stdout_isatty() -> bool {
19     type DWORD = u32;
20     type BOOL = i32;
21     type HANDLE = *mut u8;
22     type LPDWORD = *mut u32;
23     const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
24     extern "system" {
25         fn GetStdHandle(which: DWORD) -> HANDLE;
26         fn GetConsoleMode(hConsoleHandle: HANDLE, lpMode: LPDWORD) -> BOOL;
27     }
28     unsafe {
29         let handle = GetStdHandle(STD_OUTPUT_HANDLE);
30         let mut out = 0;
31         GetConsoleMode(handle, &mut out) != 0
32     }
33 }