]> git.lizzy.rs Git - rust.git/blobdiff - src/libterm/win.rs
Rollup merge of #68143 - skinny121:const-param-type-elided-lifetime, r=petrochenkov
[rust.git] / src / libterm / win.rs
index e5911de8396c13bbec4374ff52d9de19629931a7..c24cf9518aa2539e9e829d9c6e6e081f5942634e 100644 (file)
@@ -5,8 +5,8 @@
 use std::io;
 use std::io::prelude::*;
 
-use crate::Attr;
 use crate::color;
+use crate::Attr;
 use crate::Terminal;
 
 /// A Terminal implementation that uses the Win32 Console API.
@@ -73,11 +73,7 @@ fn color_to_bits(color: color::Color) -> u16 {
         _ => unreachable!(),
     };
 
-    if color >= 8 {
-        bits | 0x8
-    } else {
-        bits
-    }
+    if color >= 8 { bits | 0x8 } else { bits }
 }
 
 fn bits_to_color(bits: u16) -> color::Color {
@@ -93,7 +89,7 @@ fn bits_to_color(bits: u16) -> color::Color {
         _ => unreachable!(),
     };
 
-    color | (bits & 0x8) // copy the hi-intensity bit
+    color | (u32::from(bits) & 0x8) // copy the hi-intensity bit
 }
 
 impl<T: Write + Send + 'static> WinConsole<T> {
@@ -105,7 +101,7 @@ fn apply(&mut self) {
 
         unsafe {
             // Magic -11 means stdout, from
-            // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx
+            // 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
@@ -126,11 +122,10 @@ pub fn new(out: T) -> io::Result<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 buffer_info = buffer_info.assume_init() ;
+            if GetConsoleScreenBufferInfo(GetStdHandle(-11i32 as DWORD), 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);
             } else {
@@ -217,7 +212,8 @@ fn get_mut(&mut self) -> &mut T {
     }
 
     fn into_inner(self) -> T
-        where Self: Sized
+    where
+        Self: Sized,
     {
         self.buf
     }