diff options
| author | bors <bors@rust-lang.org> | 2024-05-26 10:57:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-05-26 10:57:58 +0000 |
| commit | a6a017d3f3f08228074175aa7125a9ac1c122bcf (patch) | |
| tree | 4b75436adcde08110a574778c9ff645c99fabfc3 | |
| parent | 5fe554350208b72cb8b66ce39bf0b92b1bba6edd (diff) | |
| parent | b06b122d8c49928bb3dc597c1d6cdfe11b414079 (diff) | |
| download | rust-a6a017d3f3f08228074175aa7125a9ac1c122bcf.tar.gz rust-a6a017d3f3f08228074175aa7125a9ac1c122bcf.zip | |
Auto merge of #125570 - tesuji:stdout-handle, r=Nilstrieb
Use STD_OUTPUT_HANDLE instead of magic number
| -rw-r--r-- | library/test/src/term/win.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/library/test/src/term/win.rs b/library/test/src/term/win.rs index 55020141a82..65764c0ffc1 100644 --- a/library/test/src/term/win.rs +++ b/library/test/src/term/win.rs @@ -22,6 +22,8 @@ type WORD = u16; type DWORD = u32; type BOOL = i32; type HANDLE = *mut u8; +// https://docs.microsoft.com/en-us/windows/console/getstdhandle +const STD_OUTPUT_HANDLE: DWORD = -11 as _; #[allow(non_snake_case)] #[repr(C)] @@ -99,16 +101,13 @@ impl<T: Write + Send + 'static> WinConsole<T> { accum |= color_to_bits(self.background) << 4; unsafe { - // Magic -11 means stdout, from - // https://docs.microsoft.com/en-us/windows/console/getstdhandle - // // You may be wondering, "but what about stderr?", and the answer // to that is that setting terminal attributes on the stdout // handle also sets them for stderr, since they go to the same // terminal! Admittedly, this is fragile, since stderr could be // redirected to a different console. This is good enough for // rustc though. See #13400. - let out = GetStdHandle(-11i32 as DWORD); + let out = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(out, accum); } } @@ -120,9 +119,8 @@ impl<T: Write + Send + 'static> WinConsole<T> { let bg; unsafe { let mut buffer_info = MaybeUninit::<CONSOLE_SCREEN_BUFFER_INFO>::uninit(); - if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), buffer_info.as_mut_ptr()) - != 0 - { + let handle = GetStdHandle(STD_OUTPUT_HANDLE); + if GetConsoleScreenBufferInfo(handle, buffer_info.as_mut_ptr()) != 0 { let buffer_info = buffer_info.assume_init(); fg = bits_to_color(buffer_info.wAttributes); bg = bits_to_color(buffer_info.wAttributes >> 4); |
