Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Windows warnings cleanup #217

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions crossterm_input/src/input/windows_input.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! This is a WINDOWS specific implementation for input related action.

use super::*;

use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent,
};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::time::Duration;
use std::{char, io, thread};

use winapi::um::{
wincon::{
Expand All @@ -19,10 +17,12 @@ use winapi::um::{
},
};

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc;
use std::time::Duration;
use std::{char, io, thread};
use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent,
};

use super::*;

pub struct WindowsInput;

Expand Down Expand Up @@ -157,7 +157,7 @@ pub struct AsyncReader {
impl AsyncReader {
/// Construct a new instance of the `AsyncReader`.
/// The reading will immediately start when calling this function.
pub fn new(function: Box<Fn(&Sender<InputEvent>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
pub fn new(function: Box<dyn Fn(&Sender<InputEvent>, &Arc<AtomicBool>) + Send>) -> AsyncReader {
let shutdown_handle = Arc::new(AtomicBool::new(false));

let (event_tx, event_rx) = mpsc::channel();
Expand Down Expand Up @@ -383,10 +383,10 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option<KeyEvent> {
}
} else if key_state.has_state(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) {
match character_raw as u8 {
c @ b'\x01'...b'\x1A' => {
c @ b'\x01'..=b'\x1A' => {
Some(KeyEvent::Ctrl((c as u8 - 0x1 + b'a') as char))
}
c @ b'\x1C'...b'\x1F' => {
c @ b'\x1C'..=b'\x1F' => {
Some(KeyEvent::Ctrl((c as u8 - 0x1C + b'4') as char))
}
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions crossterm_style/src/winapi_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! This module is used for non supporting `ANSI` Windows terminals.

use std::io;
use std::sync::{Once, ONCE_INIT};
use std::sync::Once;

use crossterm_utils::Result;
use crossterm_winapi::{Console, Handle, HandleType, ScreenBuffer};
Expand Down Expand Up @@ -187,5 +187,5 @@ fn original_console_color() -> u16 {
return unsafe { ORIGINAL_CONSOLE_COLOR };
}

static GET_ORIGINAL_CONSOLE_COLOR: Once = ONCE_INIT;
static GET_ORIGINAL_CONSOLE_COLOR: Once = Once::new();
static mut ORIGINAL_CONSOLE_COLOR: u16 = 0;
9 changes: 5 additions & 4 deletions crossterm_winapi/src/console.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use super::{is_true, Coord, Handle, HandleType, WindowPositions};
use std::borrow::ToOwned;
use std::io::{self, Error, Result};
use std::str;

use std::borrow::ToOwned;
use winapi::ctypes::c_void;
use winapi::shared::minwindef::DWORD;
use winapi::shared::ntdef::NULL;
Expand All @@ -17,6 +16,8 @@ use winapi::um::{

use InputRecord;

use super::{is_true, Coord, Handle, HandleType, WindowPositions};

/// Could be used to do some basic things with the console.
pub struct Console {
handle: Handle,
Expand Down Expand Up @@ -165,7 +166,7 @@ impl Console {
}

pub fn read_single_input_event(&self) -> Result<Option<InputRecord>> {
let mut buf_len = self.number_of_console_input_events()?;
let buf_len = self.number_of_console_input_events()?;

// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
Expand All @@ -182,7 +183,7 @@ impl Console {
}

pub fn read_console_input(&self) -> Result<(u32, Vec<InputRecord>)> {
let mut buf_len = self.number_of_console_input_events()?;
let buf_len = self.number_of_console_input_events()?;

// Fast-skipping all the code below if there is nothing to read at all
if buf_len == 0 {
Expand Down