22
33// FIXME (#13400): this is only a tiny fraction of the Windows console api
44
5- extern crate libc;
6-
75use std:: io;
86use std:: io:: prelude:: * ;
97
@@ -20,19 +18,36 @@ pub struct WinConsole<T> {
2018 background : color:: Color ,
2119}
2220
21+ type SHORT = i16 ;
2322type WORD = u16 ;
2423type DWORD = u32 ;
2524type BOOL = i32 ;
2625type HANDLE = * mut u8 ;
2726
27+ #[ allow( non_snake_case) ]
28+ #[ repr( C ) ]
29+ struct SMALL_RECT {
30+ Left : SHORT ,
31+ Top : SHORT ,
32+ Right : SHORT ,
33+ Bottom : SHORT ,
34+ }
35+
36+ #[ allow( non_snake_case) ]
37+ #[ repr( C ) ]
38+ struct COORD {
39+ X : SHORT ,
40+ Y : SHORT ,
41+ }
42+
2843#[ allow( non_snake_case) ]
2944#[ repr( C ) ]
3045struct CONSOLE_SCREEN_BUFFER_INFO {
31- dwSize : [ libc :: c_short ; 2 ] ,
32- dwCursorPosition : [ libc :: c_short ; 2 ] ,
46+ dwSize : COORD ,
47+ dwCursorPosition : COORD ,
3348 wAttributes : WORD ,
34- srWindow : [ libc :: c_short ; 4 ] ,
35- dwMaximumWindowSize : [ libc :: c_short ; 2 ] ,
49+ srWindow : SMALL_RECT ,
50+ dwMaximumWindowSize : COORD ,
3651}
3752
3853#[ allow( non_snake_case) ]
@@ -105,12 +120,17 @@ impl<T: Write + Send + 'static> WinConsole<T> {
105120
106121 /// Returns `None` whenever the terminal cannot be created for some reason.
107122 pub fn new ( out : T ) -> io:: Result < WinConsole < T > > {
123+ use std:: mem:: MaybeUninit ;
124+
108125 let fg;
109126 let bg;
110127 unsafe {
111- #[ allow( deprecated) ]
112- let mut buffer_info = :: std:: mem:: uninitialized ( ) ;
113- if GetConsoleScreenBufferInfo ( GetStdHandle ( -11i32 as DWORD ) , & mut buffer_info) != 0 {
128+ let mut buffer_info = MaybeUninit :: < CONSOLE_SCREEN_BUFFER_INFO > :: uninit ( ) ;
129+ if GetConsoleScreenBufferInfo (
130+ GetStdHandle ( -11i32 as DWORD ) ,
131+ buffer_info. as_mut_ptr ( )
132+ ) != 0 {
133+ let buffer_info = buffer_info. assume_init ( ) ;
114134 fg = bits_to_color ( buffer_info. wAttributes ) ;
115135 bg = bits_to_color ( buffer_info. wAttributes >> 4 ) ;
116136 } else {
0 commit comments