Cleanup windows (#52)

* Removed unused imports and ran 'cargo fix'
This commit is contained in:
Timon 2018-11-25 06:16:02 -08:00 committed by GitHub
parent ee782cc7a6
commit 572e842253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 30 additions and 48 deletions

View File

@ -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<Mutex<String>>, screen: &Screen) -> Vec<thread::JoinHandle
for i in 0..1 {
let input_buffer = input_buf.clone();
let clone_stdout = screen.stdout.clone();
let _clone_stdout = screen.stdout.clone();
let crossterm = Crossterm::from(screen.stdout.clone());

View File

@ -88,13 +88,13 @@ fn new_sync_flag(initial_state: bool) -> (SyncFlagTx, SyncFlagRx) {
fn main() {
let (_results_tx, _results_rx): (Sender<String>, Receiver<String>) = 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<String>) {
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() {

View File

@ -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);

View File

@ -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(())

View File

@ -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.

View File

@ -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);

View File

@ -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<HANDLE> {

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {

View File

@ -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<usize
let csbi = csbi::get_csbi_by_handle(handle)?;
// get current position
let current_pos = COORD {
let _current_pos = COORD {
X: csbi.dwCursorPosition.X,
Y: csbi.dwCursorPosition.Y,
};

View File

@ -60,5 +60,5 @@ impl ITerminalCursor for WinApiCursor {
cursor::cursor_visibility(true);
}
fn blink(&self, blink: bool, _stdout: &Option<&Arc<TerminalOutput>>) {}
fn blink(&self, _blink: bool, _stdout: &Option<&Arc<TerminalOutput>>) {}
}

View File

@ -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();

View File

@ -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;

View File

@ -45,7 +45,7 @@ impl ITerminalColor for WinApiColor {
fn set_bg(&self, bg_color: Color, _stdout: &Option<&Arc<TerminalOutput>>) {
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 }
};
}
};

View File

@ -34,11 +34,11 @@ impl ITerminal for WinApiTerminal {
};
}
fn terminal_size(&self, stdout: &Option<&Arc<TerminalOutput>>) -> (u16, u16) {
fn terminal_size(&self, _stdout: &Option<&Arc<TerminalOutput>>) -> (u16, u16) {
terminal::terminal_size()
}
fn scroll_up(&self, count: i16, stdout: &Option<&Arc<TerminalOutput>>) {
fn scroll_up(&self, count: i16, _stdout: &Option<&Arc<TerminalOutput>>) {
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<TerminalOutput>>) {
fn scroll_down(&self, count: i16, _stdout: &Option<&Arc<TerminalOutput>>) {
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<TerminalOutput>>) {
fn set_size(&self, width: i16, height: i16, _stdout: &Option<&Arc<TerminalOutput>>) {
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<TerminalOutput>>,
_stdout: &Option<&Arc<TerminalOutput>>,
) {
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<TerminalOutput>>,
_stdout: &Option<&Arc<TerminalOutput>>,
) {
let (xpos, ypos) = pos;