@@ -22,6 +22,8 @@ type WORD = u16;
22
22
type DWORD = u32 ;
23
23
type BOOL = i32 ;
24
24
type HANDLE = * mut u8 ;
25
+ // https://docs.microsoft.com/en-us/windows/console/getstdhandle
26
+ const STD_OUTPUT_HANDLE : DWORD = -11 as _ ;
25
27
26
28
#[ allow( non_snake_case) ]
27
29
#[ repr( C ) ]
@@ -99,16 +101,13 @@ impl<T: Write + Send + 'static> WinConsole<T> {
99
101
accum |= color_to_bits ( self . background ) << 4 ;
100
102
101
103
unsafe {
102
- // Magic -11 means stdout, from
103
- // https://docs.microsoft.com/en-us/windows/console/getstdhandle
104
- //
105
104
// You may be wondering, "but what about stderr?", and the answer
106
105
// to that is that setting terminal attributes on the stdout
107
106
// handle also sets them for stderr, since they go to the same
108
107
// terminal! Admittedly, this is fragile, since stderr could be
109
108
// redirected to a different console. This is good enough for
110
109
// rustc though. See #13400.
111
- let out = GetStdHandle ( - 11i32 as DWORD ) ;
110
+ let out = GetStdHandle ( STD_OUTPUT_HANDLE ) ;
112
111
SetConsoleTextAttribute ( out, accum) ;
113
112
}
114
113
}
@@ -120,9 +119,8 @@ impl<T: Write + Send + 'static> WinConsole<T> {
120
119
let bg;
121
120
unsafe {
122
121
let mut buffer_info = MaybeUninit :: < CONSOLE_SCREEN_BUFFER_INFO > :: uninit ( ) ;
123
- if GetConsoleScreenBufferInfo ( GetStdHandle ( -11i32 as DWORD ) , buffer_info. as_mut_ptr ( ) )
124
- != 0
125
- {
122
+ let handle = GetStdHandle ( STD_OUTPUT_HANDLE ) ;
123
+ if GetConsoleScreenBufferInfo ( handle, buffer_info. as_mut_ptr ( ) ) != 0 {
126
124
let buffer_info = buffer_info. assume_init ( ) ;
127
125
fg = bits_to_color ( buffer_info. wAttributes ) ;
128
126
bg = bits_to_color ( buffer_info. wAttributes >> 4 ) ;
0 commit comments