2
2
3
3
// FIXME (#13400): this is only a tiny fraction of the Windows console api
4
4
5
- extern crate libc;
6
-
7
5
use std:: io;
8
6
use std:: io:: prelude:: * ;
9
7
@@ -20,19 +18,36 @@ pub struct WinConsole<T> {
20
18
background : color:: Color ,
21
19
}
22
20
21
+ type SHORT = i16 ;
23
22
type WORD = u16 ;
24
23
type DWORD = u32 ;
25
24
type BOOL = i32 ;
26
25
type HANDLE = * mut u8 ;
27
26
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
+
28
43
#[ allow( non_snake_case) ]
29
44
#[ repr( C ) ]
30
45
struct CONSOLE_SCREEN_BUFFER_INFO {
31
- dwSize : [ libc :: c_short ; 2 ] ,
32
- dwCursorPosition : [ libc :: c_short ; 2 ] ,
46
+ dwSize : COORD ,
47
+ dwCursorPosition : COORD ,
33
48
wAttributes : WORD ,
34
- srWindow : [ libc :: c_short ; 4 ] ,
35
- dwMaximumWindowSize : [ libc :: c_short ; 2 ] ,
49
+ srWindow : SMALL_RECT ,
50
+ dwMaximumWindowSize : COORD ,
36
51
}
37
52
38
53
#[ allow( non_snake_case) ]
@@ -105,12 +120,17 @@ impl<T: Write + Send + 'static> WinConsole<T> {
105
120
106
121
/// Returns `None` whenever the terminal cannot be created for some reason.
107
122
pub fn new ( out : T ) -> io:: Result < WinConsole < T > > {
123
+ use std:: mem:: MaybeUninit ;
124
+
108
125
let fg;
109
126
let bg;
110
127
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 ( ) ;
114
134
fg = bits_to_color ( buffer_info. wAttributes ) ;
115
135
bg = bits_to_color ( buffer_info. wAttributes >> 4 ) ;
116
136
} else {
0 commit comments