From 572e8422536ab8c6f19b96a046bc6aa1d0a83ae6 Mon Sep 17 00:00:00 2001 From: Timon Date: Sun, 25 Nov 2018 06:16:02 -0800 Subject: [PATCH] Cleanup windows (#52) * Removed unused imports and ran 'cargo fix' --- examples/program_examples/command_bar.rs | 4 ++-- examples/program_examples/logging.rs | 6 +++--- src/common/commands/win_commands.rs | 8 +++----- src/common/screen/raw.rs | 2 +- src/kernel/windows_kernel/csbi.rs | 3 +-- src/kernel/windows_kernel/cursor.rs | 6 ++---- src/kernel/windows_kernel/handle.rs | 5 +---- src/kernel/windows_kernel/kernel.rs | 1 - src/kernel/windows_kernel/mod.rs | 2 -- src/kernel/windows_kernel/terminal.rs | 3 +-- src/kernel/windows_kernel/writing.rs | 5 ++--- src/modules/cursor/winapi_cursor.rs | 2 +- src/modules/output/test.rs | 4 ++-- src/modules/output/winapi_output.rs | 5 ----- src/modules/style/winapi_color.rs | 10 +++++----- src/modules/terminal/winapi_terminal.rs | 12 ++++++------ 16 files changed, 30 insertions(+), 48 deletions(-) diff --git a/examples/program_examples/command_bar.rs b/examples/program_examples/command_bar.rs index 8b86207..7c8c88f 100644 --- a/examples/program_examples/command_bar.rs +++ b/examples/program_examples/command_bar.rs @@ -16,7 +16,7 @@ fn main() { let cursor = crossterm.cursor(); cursor.hide(); - let mut input_buf = Arc::new(Mutex::new(String::new())); + let input_buf = Arc::new(Mutex::new(String::new())); let threads = log(input_buf.clone(), &screen); @@ -58,7 +58,7 @@ fn log(input_buf: Arc>, screen: &Screen) -> Vec (SyncFlagTx, SyncFlagRx) { fn main() { let (_results_tx, _results_rx): (Sender, Receiver) = mpsc::channel(); - let (mut more_jobs_tx, more_jobs_rx) = new_sync_flag(true); + let (more_jobs_tx, more_jobs_rx) = new_sync_flag(true); // queue with all log entry's. let queue = WorkQueue::new(); // queue x logs with different threads. - let thread_handles = log_with_different_threads(more_jobs_tx.clone(), queue.clone()); + let _thread_handles = log_with_different_threads(more_jobs_tx.clone(), queue.clone()); // a thread that will log all logs in the queue. handle_incoming_logs(more_jobs_rx.clone(), queue.clone()); @@ -107,7 +107,7 @@ fn main() { fn handle_incoming_logs(more_jobs_rx: SyncFlagRx, queue: WorkQueue) { thread::spawn(move || { - let mut screen: Screen = Screen::default(); + let screen: Screen = Screen::default(); // Loop while there's expected to be work, looking for work. while more_jobs_rx.get().unwrap() { diff --git a/src/common/commands/win_commands.rs b/src/common/commands/win_commands.rs index 1c2ab44..ed14e28 100644 --- a/src/common/commands/win_commands.rs +++ b/src/common/commands/win_commands.rs @@ -8,8 +8,6 @@ use winapi::um::wincon; use winapi::um::wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING; use std::io::{Error, ErrorKind, Result}; -use std::sync::Arc; -use winapi::um::winnt::HANDLE; /// This command is used for enabling and disabling ANSI code support for windows systems, /// For more info check: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences. @@ -144,8 +142,8 @@ impl ToAlternateScreenCommand { } impl IAlternateScreenCommand for ToAlternateScreenCommand { - fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> { - let handle = handle::get_output_handle()?; + fn enable(&self, _stdout: &mut TerminalOutput) -> Result<()> { + let _handle = handle::get_output_handle()?; // create a new screen buffer to copy to. let new_handle = csbi::create_console_screen_buffer(); @@ -156,7 +154,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand { Ok(()) } - fn disable(&self, stdout: &TerminalOutput) -> Result<()> { + fn disable(&self, _stdout: &TerminalOutput) -> Result<()> { let handle = handle::get_output_handle()?; csbi::set_active_screen_buffer(handle); diff --git a/src/common/screen/raw.rs b/src/common/screen/raw.rs index 681c579..cbe35e5 100644 --- a/src/common/screen/raw.rs +++ b/src/common/screen/raw.rs @@ -42,7 +42,7 @@ impl RawScreen { #[cfg(not(target_os = "windows"))] let mut command = unix_command::RawModeCommand::new(); #[cfg(target_os = "windows")] - let mut command = win_commands::RawModeCommand::new(); + let command = win_commands::RawModeCommand::new(); command.disable()?; Ok(()) diff --git a/src/kernel/windows_kernel/csbi.rs b/src/kernel/windows_kernel/csbi.rs index 657c208..70afd0b 100644 --- a/src/kernel/windows_kernel/csbi.rs +++ b/src/kernel/windows_kernel/csbi.rs @@ -10,11 +10,10 @@ use winapi::um::wincon::{ use winapi::um::winnt::{FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE}; -use super::{handle, kernel, Empty, TerminalOutput, HANDLE}; +use super::{handle, kernel, Empty, HANDLE}; use std::io::{self, Result}; use std::mem::size_of; -use std::sync::Arc; use std::sync::{Once, ONCE_INIT}; /// Create a new console screen buffer info struct. diff --git a/src/kernel/windows_kernel/cursor.rs b/src/kernel/windows_kernel/cursor.rs index 9105dc4..eecd8ce 100644 --- a/src/kernel/windows_kernel/cursor.rs +++ b/src/kernel/windows_kernel/cursor.rs @@ -5,11 +5,9 @@ use winapi::um::wincon::{ SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD, }; -use super::{csbi, handle, kernel, TerminalOutput}; - -use kernel::windows_kernel::kernel::get_largest_console_window_size; +use super::{csbi, handle, kernel}; use std::io; -use std::sync::Arc; + /// This stores the cursor pos, at program level. So it can be recalled later. static mut SAVED_CURSOR_POS: (u16, u16) = (0, 0); diff --git a/src/kernel/windows_kernel/handle.rs b/src/kernel/windows_kernel/handle.rs index 73fb6bb..6378492 100644 --- a/src/kernel/windows_kernel/handle.rs +++ b/src/kernel/windows_kernel/handle.rs @@ -7,13 +7,10 @@ use winapi::um::fileapi::{CreateFileW, OPEN_EXISTING}; use winapi::um::handleapi::INVALID_HANDLE_VALUE; use winapi::um::processenv::GetStdHandle; use winapi::um::winbase::{STD_INPUT_HANDLE, STD_OUTPUT_HANDLE}; -use winapi::um::winnt::{FILE_SHARE_WRITE, GENERIC_ALL, GENERIC_READ, GENERIC_WRITE}; +use winapi::um::winnt::{FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE}; use std::io::{self, Result}; use std::ptr::null_mut; -use std::sync::Arc; - -use winapi::ctypes::c_void; /// Get the handle of the active screen. pub fn get_current_handle() -> Result { diff --git a/src/kernel/windows_kernel/kernel.rs b/src/kernel/windows_kernel/kernel.rs index dd50bb5..ba55d31 100644 --- a/src/kernel/windows_kernel/kernel.rs +++ b/src/kernel/windows_kernel/kernel.rs @@ -6,7 +6,6 @@ use winapi::um::wincon::{ }; use super::*; -use std::sync::Arc; /// Get the largest console window size possible. pub fn get_largest_console_window_size() -> COORD { diff --git a/src/kernel/windows_kernel/mod.rs b/src/kernel/windows_kernel/mod.rs index e2e2cdf..d6263b5 100644 --- a/src/kernel/windows_kernel/mod.rs +++ b/src/kernel/windows_kernel/mod.rs @@ -11,8 +11,6 @@ pub mod writing; use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT}; use winapi::um::winnt::HANDLE; -use TerminalOutput; - use common::traits::Empty; impl Empty for COORD { diff --git a/src/kernel/windows_kernel/terminal.rs b/src/kernel/windows_kernel/terminal.rs index e7373be..8dce784 100644 --- a/src/kernel/windows_kernel/terminal.rs +++ b/src/kernel/windows_kernel/terminal.rs @@ -1,7 +1,6 @@ //! This module contains terminal specific logic. -use super::{csbi, handle, TerminalOutput}; -use std::sync::Arc; +use super::{csbi, handle}; /// Get the terminal size pub fn terminal_size() -> (u16, u16) { diff --git a/src/kernel/windows_kernel/writing.rs b/src/kernel/windows_kernel/writing.rs index c00f252..ce748c6 100644 --- a/src/kernel/windows_kernel/writing.rs +++ b/src/kernel/windows_kernel/writing.rs @@ -8,11 +8,10 @@ use winapi::um::wincon::{ PSMALL_RECT, }; -use super::{csbi, handle, kernel, TerminalOutput, HANDLE}; +use super::{csbi, handle, kernel, HANDLE}; use std::io::{self, Result}; use std::str; -use std::sync::Arc; /// Fill a certain block with characters. pub fn fill_console_output_character( @@ -108,7 +107,7 @@ pub fn write_char_buffer(handle: &HANDLE, buf: &[u8]) -> ::std::io::Result>) {} + fn blink(&self, _blink: bool, _stdout: &Option<&Arc>) {} } diff --git a/src/modules/output/test.rs b/src/modules/output/test.rs index 496da71..8b9aaed 100644 --- a/src/modules/output/test.rs +++ b/src/modules/output/test.rs @@ -11,7 +11,7 @@ mod winapi_tests { /* ======================== WinApi =========================== */ #[test] fn write_winapi() { - let screen = Screen::default(); + let _screen = Screen::default(); let output = WinApiOutput::new(); let bytes = "test".as_bytes(); @@ -21,7 +21,7 @@ mod winapi_tests { #[test] fn write_str_winapi() { - let screen = Screen::default(); + let _screen = Screen::default(); let output = WinApiOutput::new(); let bytes = "test".as_bytes(); diff --git a/src/modules/output/winapi_output.rs b/src/modules/output/winapi_output.rs index 8b56d79..78ba8d0 100644 --- a/src/modules/output/winapi_output.rs +++ b/src/modules/output/winapi_output.rs @@ -1,12 +1,7 @@ use super::IStdout; -use common::commands::win_commands::RawModeCommand; use kernel::windows_kernel::{handle, writing}; -use common::screen::RawScreen; -use winapi::um::winnt::HANDLE; -use std::any::Any; use std::io; -use std::sync::Mutex; /// This struct is a wrapper for WINAPI `HANDLE` pub struct WinApiOutput; diff --git a/src/modules/style/winapi_color.rs b/src/modules/style/winapi_color.rs index 8111c20..39eff1a 100644 --- a/src/modules/style/winapi_color.rs +++ b/src/modules/style/winapi_color.rs @@ -45,7 +45,7 @@ impl ITerminalColor for WinApiColor { fn set_bg(&self, bg_color: Color, _stdout: &Option<&Arc>) { let color_value = &self.color_value(bg_color, ColorType::Background); - let (csbi, handle) = csbi::get_csbi_and_handle().unwrap(); + let (csbi, _handle) = csbi::get_csbi_and_handle().unwrap(); // Notice that the color values are stored in wAttribute. // So wee need to use bitwise operators to check if the values exists or to get current console colors. @@ -103,8 +103,8 @@ impl ITerminalColor for WinApiColor { Color::White => fg_intensity | fg_red | fg_green | fg_blue, /* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/ - Color::Rgb{ r, g, b } => { 0 } - Color::AnsiValue(val) => { 0 } + Color::Rgb{ r: _, g: _, b: _ } => { 0 } + Color::AnsiValue(_val) => { 0 } }; } ColorType::Background => { @@ -126,8 +126,8 @@ impl ITerminalColor for WinApiColor { Color::White => bg_intensity | bg_red | bg_green | bg_blue, /* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/ - Color::Rgb{ r, g, b } => { 0 } - Color::AnsiValue(val) => { 0 } + Color::Rgb{ r: _, g: _, b: _ } => { 0 } + Color::AnsiValue(_val) => { 0 } }; } }; diff --git a/src/modules/terminal/winapi_terminal.rs b/src/modules/terminal/winapi_terminal.rs index 1650b23..84d0fc8 100644 --- a/src/modules/terminal/winapi_terminal.rs +++ b/src/modules/terminal/winapi_terminal.rs @@ -34,11 +34,11 @@ impl ITerminal for WinApiTerminal { }; } - fn terminal_size(&self, stdout: &Option<&Arc>) -> (u16, u16) { + fn terminal_size(&self, _stdout: &Option<&Arc>) -> (u16, u16) { terminal::terminal_size() } - fn scroll_up(&self, count: i16, stdout: &Option<&Arc>) { + fn scroll_up(&self, count: i16, _stdout: &Option<&Arc>) { let csbi = csbi::get_csbi().unwrap(); // Set srctWindow to the current window size and location. @@ -56,7 +56,7 @@ impl ITerminal for WinApiTerminal { } } - fn scroll_down(&self, count: i16, stdout: &Option<&Arc>) { + fn scroll_down(&self, count: i16, _stdout: &Option<&Arc>) { let csbi = csbi::get_csbi().unwrap(); // Set srctWindow to the current window size and location. let mut srct_window = csbi.srWindow; @@ -74,7 +74,7 @@ impl ITerminal for WinApiTerminal { } /// Set the current terminal size - fn set_size(&self, width: i16, height: i16, stdout: &Option<&Arc>) { + fn set_size(&self, width: i16, height: i16, _stdout: &Option<&Arc>) { if width <= 0 { panic!("Cannot set the terminal width lower than 1"); } @@ -163,7 +163,7 @@ impl ITerminal for WinApiTerminal { pub fn clear_after_cursor( pos: (u16, u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, - stdout: &Option<&Arc>, + _stdout: &Option<&Arc>, ) { let (mut x, mut y) = pos; @@ -187,7 +187,7 @@ pub fn clear_after_cursor( pub fn clear_before_cursor( pos: (u16, u16), csbi: CONSOLE_SCREEN_BUFFER_INFO, - stdout: &Option<&Arc>, + _stdout: &Option<&Arc>, ) { let (xpos, ypos) = pos;