@@ -22,6 +22,8 @@ type WORD = u16;
2222type DWORD =u32 ;
2323type BOOL =i32 ;
2424type HANDLE =* mut u8 ;
25+ // https://docs.microsoft.com/en-us/windows/console/getstdhandle
26+ const STD_OUTPUT_HANDLE : DWORD = -11 as _ ;
2527
2628#[ allow( non_snake_case) ]
2729#[ repr( C ) ]
@@ -99,16 +101,13 @@ impl<T: Write + Send + 'static> WinConsole<T> {
99101 accum |=color_to_bits ( self . background ) <<4 ;
100102
101103unsafe {
102- // Magic -11 means stdout, from
103- // https://docs.microsoft.com/en-us/windows/console/getstdhandle
104- //
105104// You may be wondering, "but what about stderr?", and the answer
106105// to that is that setting terminal attributes on the stdout
107106// handle also sets them for stderr, since they go to the same
108107// terminal! Admittedly, this is fragile, since stderr could be
109108// redirected to a different console. This is good enough for
110109// rustc though. See #13400.
111- let out =GetStdHandle ( - 11i32 as DWORD ) ;
110+ let out =GetStdHandle ( STD_OUTPUT_HANDLE ) ;
112111SetConsoleTextAttribute ( out, accum) ;
113112}
114113}
@@ -120,9 +119,8 @@ impl<T: Write + Send + 'static> WinConsole<T> {
120119let bg;
121120unsafe {
122121let 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 {
126124let buffer_info = buffer_info. assume_init ( ) ;
127125 fg =bits_to_color ( buffer_info. wAttributes ) ;
128126 bg =bits_to_color ( buffer_info. wAttributes >>4 ) ;