diff --git a/src/common/commands/mod.rs b/src/common/commands/mod.rs index cb5fb45..20567cd 100644 --- a/src/common/commands/mod.rs +++ b/src/common/commands/mod.rs @@ -2,10 +2,8 @@ use super::super::output::TerminalOutput; use std::io; -use std::sync::Mutex; pub mod shared_commands; -use common::screen::Screen; #[cfg(not(target_os = "windows"))] pub mod unix_command; @@ -26,8 +24,8 @@ pub trait IEnableAnsiCommand { // This trait provides an interface for switching to alternate screen and back. pub trait IAlternateScreenCommand: Send { - fn enable(&self, screen_manager: &mut TerminalOutput) -> io::Result<()>; - fn disable(&self, screen_manager: &TerminalOutput) -> io::Result<()>; + fn enable(&self, stdout: &mut TerminalOutput) -> io::Result<()>; + fn disable(&self, stdout: &TerminalOutput) -> io::Result<()>; } // This trait provides an interface for switching to raw mode and back. diff --git a/src/common/commands/shared_commands.rs b/src/common/commands/shared_commands.rs index 000dc6f..c1e1c7f 100644 --- a/src/common/commands/shared_commands.rs +++ b/src/common/commands/shared_commands.rs @@ -2,8 +2,7 @@ use super::{IAlternateScreenCommand, TerminalOutput}; -use std::sync::Mutex; -use std::io::{ Result, stdout, Write}; +use std::io::{ Result}; /// This command is used for switching to alternate screen and back to main screen. pub struct ToAlternateScreenCommand; @@ -17,14 +16,14 @@ impl ToAlternateScreenCommand { impl IAlternateScreenCommand for ToAlternateScreenCommand { /// enable alternate screen. - fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> { - screen_manager.write_str(csi!("?1049h")); + fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> { + stdout.write_str(csi!("?1049h")); Ok(()) } /// disable alternate screen. - fn disable(&self, screen_manager: &TerminalOutput) -> Result<()> { - screen_manager.write_str(csi!("?1049l")); + fn disable(&self, stdout: &TerminalOutput) -> Result<()> { + stdout.write_str(csi!("?1049l")); Ok(()) } } diff --git a/src/common/commands/unix_command.rs b/src/common/commands/unix_command.rs index 053e493..62cdc26 100644 --- a/src/common/commands/unix_command.rs +++ b/src/common/commands/unix_command.rs @@ -1,6 +1,6 @@ //! This module contains the commands that can be used for unix systems. -use super::{ IStateCommand, IRawScreenCommand}; +use super::{ IStateCommand}; use kernel::unix_kernel::terminal; use termios::{tcsetattr, Termios, CREAD, ECHO, ICANON, TCSAFLUSH}; @@ -55,9 +55,3 @@ impl NoncanonicalModeCommand { } } -/// This command is used for enabling and disabling raw mode for the terminal. -pub struct RawModeCommand { - original_mode: Result, -} - - diff --git a/src/common/commands/win_commands.rs b/src/common/commands/win_commands.rs index f0c79b6..3cabe94 100644 --- a/src/common/commands/win_commands.rs +++ b/src/common/commands/win_commands.rs @@ -1,16 +1,13 @@ //! This module contains the commands that can be used for windows systems. -use super::{IAlternateScreenCommand, IEnableAnsiCommand, IRawScreenCommand, TerminalOutput}; +use super::{IAlternateScreenCommand, IEnableAnsiCommand, TerminalOutput}; use kernel::windows_kernel::{ansi_support, csbi, handle, kernel}; -use modules::output::IStdout; -use std::mem; -use winapi::shared::minwindef::DWORD; use winapi::um::wincon; -use winapi::um::wincon::{CHAR_INFO, COORD, ENABLE_VIRTUAL_TERMINAL_PROCESSING, SMALL_RECT}; +use winapi::shared::minwindef::DWORD; +use winapi::um::wincon::{ENABLE_VIRTUAL_TERMINAL_PROCESSING}; use std::io::{Error, ErrorKind, Result}; -use std::sync::Mutex; /// 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. @@ -148,7 +145,7 @@ impl ToAlternateScreenCommand { } impl IAlternateScreenCommand for ToAlternateScreenCommand { - fn enable(&self, screen_manager: &mut TerminalOutput) -> Result<()> { + fn enable(&self, stdout: &mut TerminalOutput) -> Result<()> { use super::super::super::modules::output::WinApiOutput; let handle = handle::get_output_handle()?; @@ -159,7 +156,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand { // Make the new screen buffer the active screen buffer. csbi::set_active_screen_buffer(new_handle)?; - let b: &mut WinApiOutput = match screen_manager + let b: &mut WinApiOutput = match stdout .as_any_mut() .downcast_mut::() { @@ -172,7 +169,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand { Ok(()) } - fn disable(&self, screen_manager: &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/crossterm.rs b/src/common/crossterm.rs index 1eb62a7..240b172 100644 --- a/src/common/crossterm.rs +++ b/src/common/crossterm.rs @@ -1,27 +1,13 @@ -use super::commands::{IAlternateScreenCommand}; - -use super::screen::{AlternateScreen, Screen}; +use {Screen, TerminalOutput}; use super::super::cursor; use super::super::input; -use super::super::output; use super::super::style; use super::super::terminal; use std::fmt::Display; -use std::io::Write; -use std::sync::RwLock; -use std::io::Result; use std::sync::Arc; -#[cfg(not(windows))] -use common::commands::unix_command; - -#[cfg(windows)] -use common::commands::win_commands; - -use output::TerminalOutput; - /// This type could be used to access the `cursor, terminal, color, input, styling` module more easily. /// You need to pass a reference to the screen where on you want to perform the actions to the `Crossterm` type. /// diff --git a/src/common/functions.rs b/src/common/functions.rs index e9be014..bd8b15d 100644 --- a/src/common/functions.rs +++ b/src/common/functions.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use kernel::windows_kernel::ansi_support::{try_enable_ansi_support, windows_supportable}; #[cfg(windows)] -use kernel::windows_kernel::terminal::{buffer_size, exit, terminal_size}; +use kernel::windows_kernel::terminal::{ exit, terminal_size}; #[cfg(windows)] use kernel::windows_kernel::cursor::pos; diff --git a/src/common/screen/alternate.rs b/src/common/screen/alternate.rs index 18a664c..609254d 100644 --- a/src/common/screen/alternate.rs +++ b/src/common/screen/alternate.rs @@ -7,11 +7,10 @@ //! Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged. use super::commands::{self, IAlternateScreenCommand}; -use super::{functions, Screen, TerminalOutput, RawScreen}; +use super::{functions, Screen, TerminalOutput}; +use std::io; use std::convert::From; -use std::io::{self, Write}; -use std::sync::Mutex; /// With this type you will be able to switch to alternate screen and back to main screen. pub struct AlternateScreen diff --git a/src/common/screen/raw.rs b/src/common/screen/raw.rs index 2a39650..8f901ef 100644 --- a/src/common/screen/raw.rs +++ b/src/common/screen/raw.rs @@ -15,9 +15,8 @@ //! With these modes you can easier design the terminal screen. use super::commands::*; -use super::{functions, Screen, TerminalOutput}; -use std::io::{self, Write}; +use std::io; /// A wrapper for the raw terminal state. Which can be used to write to. pub struct RawScreen; @@ -39,9 +38,9 @@ impl RawScreen { pub fn disable_raw_modes() -> io::Result<()> { #[cfg(not(target_os = "windows"))] - let mut command = unix_command::NoncanonicalModeCommand::new(); + let command = unix_command::NoncanonicalModeCommand::new(); #[cfg(target_os = "windows")] - let mut command = win_commands::RawModeCommand::new(); + let command = win_commands::RawModeCommand::new(); command.disable()?; return Ok(()) diff --git a/src/common/screen/screen.rs b/src/common/screen/screen.rs index 44d3685..b064d33 100644 --- a/src/common/screen/screen.rs +++ b/src/common/screen/screen.rs @@ -1,11 +1,3 @@ -#[cfg(not(windows))] -use common::commands::unix_command; - -#[cfg(windows)] -use common::commands::win_commands; - -use common::commands::IAlternateScreenCommand; - use super::{AlternateScreen,RawScreen}; use TerminalOutput; @@ -98,7 +90,7 @@ impl Screen /// For an example of this behavior, consider when vim is launched from bash. /// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged. pub fn enable_alternate_modes(&self, raw_mode: bool) -> Result { - let mut stdout = TerminalOutput::new(raw_mode); + let stdout = TerminalOutput::new(raw_mode); if raw_mode { diff --git a/src/kernel/windows_kernel/ansi_support.rs b/src/kernel/windows_kernel/ansi_support.rs index 896a341..8e6f6f5 100644 --- a/src/kernel/windows_kernel/ansi_support.rs +++ b/src/kernel/windows_kernel/ansi_support.rs @@ -13,7 +13,7 @@ use common::commands::IEnableAnsiCommand; /// Try enable `ANSI escape codes` and return the result. pub fn try_enable_ansi_support() -> bool { ENABLE_ANSI.call_once(|| { - let mut command = EnableAnsiCommand::new(); + let command = EnableAnsiCommand::new(); let success = command.enable(); set_is_windows_ansi_supportable(success); diff --git a/src/kernel/windows_kernel/csbi.rs b/src/kernel/windows_kernel/csbi.rs index 4b0a5a3..abddc31 100644 --- a/src/kernel/windows_kernel/csbi.rs +++ b/src/kernel/windows_kernel/csbi.rs @@ -1,6 +1,6 @@ //! This contains the logic for working with the console buffer. -use winapi::shared::minwindef::{FALSE, TRUE}; +use winapi::shared::minwindef::TRUE; use winapi::shared::ntdef::NULL; use winapi::um::minwinbase::SECURITY_ATTRIBUTES; use winapi::um::wincon::{ @@ -12,18 +12,18 @@ use winapi::um::winnt::{FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC use super::{handle, kernel, Empty, TerminalOutput, HANDLE}; -use std::io::{self, ErrorKind, Result}; +use std::io::{self, Result}; use std::sync::{Once, ONCE_INIT}; use std::mem::size_of; use std::sync::Arc; /// Create a new console screen buffer info struct. -pub fn get_csbi(screen_manager: &Arc) -> Result { +pub fn get_csbi(stdout: &Arc) -> Result { let mut csbi = CONSOLE_SCREEN_BUFFER_INFO::empty(); let success; unsafe { - success = GetConsoleScreenBufferInfo(handle::get_current_handle(screen_manager)?, &mut csbi) + success = GetConsoleScreenBufferInfo(handle::get_current_handle(stdout)?, &mut csbi) } if success == 0 { @@ -38,9 +38,9 @@ pub fn get_csbi(screen_manager: &Arc) -> Result, + stdout: &Arc, ) -> Result<(CONSOLE_SCREEN_BUFFER_INFO, HANDLE)> { - let handle = handle::get_current_handle(screen_manager)?; + let handle = handle::get_current_handle(stdout)?; let csbi = get_csbi_by_handle(&handle)?; return Ok((csbi, handle)); @@ -63,8 +63,8 @@ pub fn get_csbi_by_handle(handle: &HANDLE) -> Result } /// Set the console screen buffer size -pub fn set_console_screen_buffer_size(size: COORD, screen_manager: &Arc) -> bool { - let handle = handle::get_current_handle(screen_manager).unwrap(); +pub fn set_console_screen_buffer_size(size: COORD, stdout: &Arc) -> bool { + let handle = handle::get_current_handle(stdout).unwrap(); unsafe { if !kernel::is_true(SetConsoleScreenBufferSize(handle, size)) { diff --git a/src/kernel/windows_kernel/cursor.rs b/src/kernel/windows_kernel/cursor.rs index e8e9b5e..80d03df 100644 --- a/src/kernel/windows_kernel/cursor.rs +++ b/src/kernel/windows_kernel/cursor.rs @@ -5,7 +5,7 @@ use winapi::um::wincon::{ SetConsoleCursorInfo, SetConsoleCursorPosition, CONSOLE_CURSOR_INFO, COORD, }; -use super::{csbi, handle, kernel, TerminalOutput, WinApiOutput}; +use super::{csbi, handle, kernel, TerminalOutput}; use std::io; use std::sync::Arc; diff --git a/src/kernel/windows_kernel/handle.rs b/src/kernel/windows_kernel/handle.rs index b9873f1..a0fc6d9 100644 --- a/src/kernel/windows_kernel/handle.rs +++ b/src/kernel/windows_kernel/handle.rs @@ -6,14 +6,13 @@ use winapi::um::winbase::{STD_INPUT_HANDLE, STD_OUTPUT_HANDLE}; use super::*; use std::sync::Arc; +use std::io::{self, Result}; /// Get the global stored handle whits provides access to the current screen. -pub fn get_current_handle(screen_manager: &Arc) -> Result { - let mut mutex = screen_manager; - +pub fn get_current_handle(stdout: &Arc) -> Result { let handle: Result; - let winapi_screen_manager: &WinApiOutput = match screen_manager + let winapi_stdout: &WinApiOutput = match stdout .as_any() .downcast_ref::() { @@ -22,13 +21,11 @@ pub fn get_current_handle(screen_manager: &Arc) -> Result Result { unsafe { diff --git a/src/kernel/windows_kernel/kernel.rs b/src/kernel/windows_kernel/kernel.rs index f93f1e2..1e3d348 100644 --- a/src/kernel/windows_kernel/kernel.rs +++ b/src/kernel/windows_kernel/kernel.rs @@ -6,8 +6,6 @@ use winapi::um::wincon::{ }; use super::*; - -use std::io::{ErrorKind, Result}; use std::sync::Arc; /// Get the largest console window size possible. diff --git a/src/kernel/windows_kernel/terminal.rs b/src/kernel/windows_kernel/terminal.rs index ce6d3e6..964eeb2 100644 --- a/src/kernel/windows_kernel/terminal.rs +++ b/src/kernel/windows_kernel/terminal.rs @@ -17,7 +17,7 @@ pub fn terminal_size() -> (u16, u16) { } } -pub fn buffer_size(screen_manager: &Arc) -> (u16, u16) { +pub fn buffer_size(stdout: &Arc) -> (u16, u16) { let handle = handle::get_output_handle().unwrap(); if let Ok(csbi) = csbi::get_csbi_by_handle(&handle) { diff --git a/src/kernel/windows_kernel/writing.rs b/src/kernel/windows_kernel/writing.rs index e986fa7..43a089d 100644 --- a/src/kernel/windows_kernel/writing.rs +++ b/src/kernel/windows_kernel/writing.rs @@ -4,13 +4,13 @@ use winapi::ctypes::c_void; use winapi::shared::ntdef::NULL; use winapi::um::consoleapi::WriteConsoleW; use winapi::um::wincon::{ - self, FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO, + FillConsoleOutputAttribute, FillConsoleOutputCharacterA, WriteConsoleOutputA, CHAR_INFO, COORD, PSMALL_RECT, }; use super::{csbi, handle, kernel, TerminalOutput, HANDLE}; -use std::io::{self, ErrorKind, Result}; +use std::io::{self, Result}; use std::str; use std::sync::Arc; @@ -19,9 +19,9 @@ pub fn fill_console_output_character( cells_written: &mut u32, start_location: COORD, cells_to_write: u32, - screen_manager: &Arc, + stdout: &Arc, ) -> bool { - let handle = handle::get_current_handle(screen_manager).unwrap(); + let handle = handle::get_current_handle(stdout).unwrap(); unsafe { // fill the cells in console with blanks @@ -41,11 +41,11 @@ pub fn fill_console_output_attribute( cells_written: &mut u32, start_location: COORD, cells_to_write: u32, - screen_manager: &Arc, + stdout: &Arc, ) -> bool { // Get the position of the current console window - let (csbi, mut handle) = csbi::get_csbi_and_handle(screen_manager).unwrap(); + let (csbi, handle) = csbi::get_csbi_and_handle(stdout).unwrap(); let success; @@ -93,7 +93,7 @@ pub fn write_console_output( /// Write utf8 buffer to console. pub fn write_char_buffer(handle: &HANDLE, buf: &[u8]) -> ::std::io::Result { // get string from u8[] and parse it to an c_str - let mut utf8 = match str::from_utf8(buf) { + let utf8 = match str::from_utf8(buf) { Ok(string) => string, Err(_) => { return Err(io::Error::new( diff --git a/src/modules/cursor/ansi_cursor.rs b/src/modules/cursor/ansi_cursor.rs index 5aa749b..38b8610 100644 --- a/src/modules/cursor/ansi_cursor.rs +++ b/src/modules/cursor/ansi_cursor.rs @@ -27,39 +27,39 @@ impl ITerminalCursor for AnsiCursor { stdout.write_string(format!(csi!("{}A"), count)); } - fn move_right(&self, count: u16, screen_manager: &Arc) { - screen_manager.write_string(format!(csi!("{}C"), count)); + fn move_right(&self, count: u16, stdout: &Arc) { + stdout.write_string(format!(csi!("{}C"), count)); } - fn move_down(&self, count: u16, screen_manager: &Arc) { - screen_manager.write_string(format!(csi!("{}B"), count)); + fn move_down(&self, count: u16, stdout: &Arc) { + stdout.write_string(format!(csi!("{}B"), count)); } - fn move_left(&self, count: u16, screen_manager: &Arc) { - screen_manager.write_string(format!(csi!("{}D"), count)); + fn move_left(&self, count: u16, stdout: &Arc) { + stdout.write_string(format!(csi!("{}D"), count)); } - fn save_position(&self, screen_manager: &Arc) { - screen_manager.write_str(csi!("s")); + fn save_position(&self, stdout: &Arc) { + stdout.write_str(csi!("s")); } - fn reset_position(&self, screen_manager: &Arc) { - screen_manager.write_str(csi!("u")); + fn reset_position(&self, stdout: &Arc) { + stdout.write_str(csi!("u")); } - fn hide(&self, screen_manager: &Arc) { - screen_manager.write_str(csi!("?25l")); + fn hide(&self, stdout: &Arc) { + stdout.write_str(csi!("?25l")); } - fn show(&self, screen_manager: &Arc) { - screen_manager.write_str(csi!("?25h")); + fn show(&self, stdout: &Arc) { + stdout.write_str(csi!("?25h")); } - fn blink(&self, blink: bool, screen_manager: &Arc) { + fn blink(&self, blink: bool, stdout: &Arc) { if blink { - screen_manager.write_str(csi!("?12h")); + stdout.write_str(csi!("?12h")); } else { - screen_manager.write_str(csi!("?12l")); + stdout.write_str(csi!("?12l")); } } } diff --git a/src/modules/cursor/cursor.rs b/src/modules/cursor/cursor.rs index 457495b..aef10db 100644 --- a/src/modules/cursor/cursor.rs +++ b/src/modules/cursor/cursor.rs @@ -6,9 +6,6 @@ use super::*; use Screen; -use std::fmt::Display; -use std::io::Write; - /// Struct that stores an specific platform implementation for cursor related actions. /// /// Check `/examples/cursor` in the library for more specific examples. diff --git a/src/modules/cursor/mod.rs b/src/modules/cursor/mod.rs index 9fb526b..647d7a2 100644 --- a/src/modules/cursor/mod.rs +++ b/src/modules/cursor/mod.rs @@ -27,25 +27,25 @@ use std::sync::Arc; ///! so that cursor related actions can be preformed on both unix and windows systems. trait ITerminalCursor { /// Goto some location (x,y) in the context. - fn goto(&self, x: u16, y: u16, screen_manager: &Arc); + fn goto(&self, x: u16, y: u16, stdout: &Arc); /// Get the location (x,y) of the current cusror in the context - fn pos(&self, screen_manager: &Arc) -> (u16, u16); + fn pos(&self, stdout: &Arc) -> (u16, u16); /// Move cursor n times up - fn move_up(&self, count: u16, screen_manager: &Arc); + fn move_up(&self, count: u16, stdout: &Arc); /// Move the cursor `n` times to the right. - fn move_right(&self, count: u16, screen_manager: &Arc); + fn move_right(&self, count: u16, stdout: &Arc); /// Move the cursor `n` times down. - fn move_down(&self, count: u16, screen_manager: &Arc); + fn move_down(&self, count: u16, stdout: &Arc); /// Move the cursor `n` times left. - fn move_left(&self, count: u16, screen_manager: &Arc); + fn move_left(&self, count: u16, stdout: &Arc); /// Save cursor position so that its saved position can be recalled later. Note that this position is stored program based not per instance of the cursor struct. - fn save_position(&self, screen_manager: &Arc); + fn save_position(&self, stdout: &Arc); /// Return to saved cursor position - fn reset_position(&self, screen_manager: &Arc); + fn reset_position(&self, stdout: &Arc); /// Hide the terminal cursor. - fn hide(&self, screen_manager: &Arc); + fn hide(&self, stdout: &Arc); /// Show the terminal cursor - fn show(&self, screen_manager: &Arc); + fn show(&self, stdout: &Arc); /// Enable or disable the blinking of the cursor. - fn blink(&self, blink: bool, screen_manager: &Arc); + fn blink(&self, blink: bool, stdout: &Arc); } diff --git a/src/modules/cursor/winapi_cursor.rs b/src/modules/cursor/winapi_cursor.rs index 8dbcf80..08fef74 100644 --- a/src/modules/cursor/winapi_cursor.rs +++ b/src/modules/cursor/winapi_cursor.rs @@ -2,8 +2,7 @@ //! This module is used for windows terminals that do not support ANSI escape codes. //! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position ect. -use super::super::super::output::WinApiOutput; -use kernel::windows_kernel::{cursor, kernel}; +use kernel::windows_kernel::cursor; use super::*; @@ -17,48 +16,48 @@ impl WinApiCursor { } impl ITerminalCursor for WinApiCursor { - fn goto(&self, x: u16, y: u16, screen_manager: &Arc) { - cursor::set_console_cursor_position(x as i16, y as i16, screen_manager); + fn goto(&self, x: u16, y: u16, stdout: &Arc) { + cursor::set_console_cursor_position(x as i16, y as i16, stdout); } - fn pos(&self, screen_manager: &Arc) -> (u16, u16) { - cursor::pos(screen_manager) + fn pos(&self, stdout: &Arc) -> (u16, u16) { + cursor::pos(stdout) } - fn move_up(&self, count: u16, screen_manager: &Arc) { - let (xpos, ypos) = self.pos(screen_manager); - self.goto(xpos, ypos - count, screen_manager); + fn move_up(&self, count: u16, stdout: &Arc) { + let (xpos, ypos) = self.pos(stdout); + self.goto(xpos, ypos - count, stdout); } - fn move_right(&self, count: u16, screen_manager: &Arc) { - let (xpos, ypos) = self.pos(screen_manager); - self.goto(xpos + count, ypos, screen_manager); + fn move_right(&self, count: u16, stdout: &Arc) { + let (xpos, ypos) = self.pos(stdout); + self.goto(xpos + count, ypos, stdout); } - fn move_down(&self, count: u16, screen_manager: &Arc) { - let (xpos, ypos) = self.pos(screen_manager); - self.goto(xpos, ypos + count, screen_manager); + fn move_down(&self, count: u16, stdout: &Arc) { + let (xpos, ypos) = self.pos(stdout); + self.goto(xpos, ypos + count, stdout); } - fn move_left(&self, count: u16, screen_manager: &Arc) { - let (xpos, ypos) = self.pos(screen_manager); - self.goto(xpos - count, ypos, screen_manager); + fn move_left(&self, count: u16, stdout: &Arc) { + let (xpos, ypos) = self.pos(stdout); + self.goto(xpos - count, ypos, stdout); } - fn save_position(&self, screen_manager: &Arc) { - cursor::save_cursor_pos(screen_manager); + fn save_position(&self, stdout: &Arc) { + cursor::save_cursor_pos(stdout); } - fn reset_position(&self, screen_manager: &Arc) { - cursor::reset_to_saved_position(screen_manager); + fn reset_position(&self, stdout: &Arc) { + cursor::reset_to_saved_position(stdout); } - fn hide(&self, screen_manager: &Arc) { - cursor::cursor_visibility(false, screen_manager); + fn hide(&self, stdout: &Arc) { + cursor::cursor_visibility(false, stdout); } - fn show(&self, screen_manager: &Arc) { - cursor::cursor_visibility(true, screen_manager); + fn show(&self, stdout: &Arc) { + cursor::cursor_visibility(true, stdout); } - fn blink(&self, blink: bool, screen_manager: &Arc) {} + fn blink(&self, blink: bool, stdout: &Arc) {} } diff --git a/src/modules/input/windows_input.rs b/src/modules/input/windows_input.rs index 1a57780..7faa366 100644 --- a/src/modules/input/windows_input.rs +++ b/src/modules/input/windows_input.rs @@ -3,7 +3,6 @@ use super::*; use winapi::um::winnt::INT; -use winapi::um::winuser; use std::char; use std::thread; @@ -129,7 +128,7 @@ impl ITerminalInput for WindowsInput { } } as u8; - let end_of_stream = (pressed_char == delimiter); + let end_of_stream = pressed_char == delimiter; // we could return error but maybe option to keep listening until valid character is inputted. if pressed_char == 0 || pressed_char == 0xe0 || end_of_stream { diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 1cd5b96..298f842 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -6,4 +6,3 @@ pub mod terminal; use super::common::commands; use super::common::functions; -use super::common::traits; diff --git a/src/modules/output/ansi_output.rs b/src/modules/output/ansi_output.rs index 26a32ba..7f1a3e1 100644 --- a/src/modules/output/ansi_output.rs +++ b/src/modules/output/ansi_output.rs @@ -5,10 +5,7 @@ use super::IStdout; use std::any::Any; -use std::cell::RefCell; -use std::sync::{Arc,Mutex}; -use std::io::{self, Read, Write,Stdout, stdout}; -use std::str::from_utf8; +use std::io::{self, Write,Stdout, stdout}; /// This struct is a wrapper for `Stdout` pub struct AnsiOutput { diff --git a/src/modules/output/output.rs b/src/modules/output/output.rs index 98297e0..3cdb7ce 100644 --- a/src/modules/output/output.rs +++ b/src/modules/output/output.rs @@ -21,15 +21,8 @@ use super::*; use std::any::Any; -use std::fmt::Display; -use std::io::{self, Write}; use std::default::Default; -#[cfg(target_os = "windows")] -use winapi::um::winnt::HANDLE; - -use std::sync::Arc; - /// Struct that is an handle to an terminal screen. /// This handle could be used to write to the current screen /// diff --git a/src/modules/output/winapi_output.rs b/src/modules/output/winapi_output.rs index a059c1e..09d4954 100644 --- a/src/modules/output/winapi_output.rs +++ b/src/modules/output/winapi_output.rs @@ -1,14 +1,11 @@ use super::IStdout; -use kernel::windows_kernel::{handle, kernel, writing}; -use winapi::um::wincon::ENABLE_PROCESSED_OUTPUT; +use kernel::windows_kernel::{handle, writing}; use winapi::um::winnt::HANDLE; use std::sync::Mutex; -use std::ptr::NonNull; use std::any::Any; use std::io; - /// This struct is a wrapper for WINAPI `HANDLE` pub struct WinApiOutput { pub handle: Mutex, @@ -24,6 +21,7 @@ impl IStdout for WinApiOutput { writing::write_char_buffer(&self.handle.lock().unwrap(), buf) } + fn flush(&self) -> io::Result<()> { Ok(()) } diff --git a/src/modules/style/objectstyle.rs b/src/modules/style/objectstyle.rs index 0b676f3..753d4b3 100644 --- a/src/modules/style/objectstyle.rs +++ b/src/modules/style/objectstyle.rs @@ -1,9 +1,8 @@ //! This module contains the `object style` that can be applied to an `styled object`. -use super::{Color, TerminalOutput, StyledObject}; +use super::{Color, StyledObject}; use std::fmt::Display; -use std::sync::Arc; #[cfg(unix)] use super::Attribute; diff --git a/src/modules/style/styledobject.rs b/src/modules/style/styledobject.rs index f3d2716..52aa87e 100644 --- a/src/modules/style/styledobject.rs +++ b/src/modules/style/styledobject.rs @@ -1,17 +1,13 @@ //! This module contains the logic to style an object that contains some state witch can be styled. -use super::{Color, ObjectStyle, TerminalOutput}; +use super::{Color, ObjectStyle}; use Screen; -use std::fmt::{self, Display}; -use std::io::Write; +use std::fmt::Display; #[cfg(unix)] use super::Attribute; -#[cfg(windows)] -use super::super::super::output::WinApiOutput; - /// Struct that contains both the style and the content wits can be styled. pub struct StyledObject { pub object_style: ObjectStyle, @@ -154,7 +150,7 @@ impl StyledObject { /// ``` pub fn paint(&self, screen: &Screen) { - let mut colored_terminal = super::super::super::style::color::color(&screen); + let colored_terminal = ::color(&screen); let mut reset = true; if let Some(bg) = self.object_style.bg_color { diff --git a/src/modules/terminal/ansi_terminal.rs b/src/modules/terminal/ansi_terminal.rs index d173176..a2cdbbe 100644 --- a/src/modules/terminal/ansi_terminal.rs +++ b/src/modules/terminal/ansi_terminal.rs @@ -1,7 +1,6 @@ //! This is an `ANSI escape code` specific implementation for terminal related action. //! This module is used for windows 10 terminals and unix terminals by default. -use cursor::cursor; use super::*; /// This struct is an ansi escape code implementation for terminal related actions. @@ -52,7 +51,7 @@ impl ITerminal for AnsiTerminal { fn exit(&self,stdout: &Arc) { // drop the screen with the current stdout. This will make sure when in raw mode this will be disabled first. - let mut screen = Screen::from(stdout.clone()); + let screen = Screen::from(stdout.clone()); drop(screen); functions::exit_terminal(); } diff --git a/src/modules/terminal/terminal.rs b/src/modules/terminal/terminal.rs index 09984cb..bf9de8b 100644 --- a/src/modules/terminal/terminal.rs +++ b/src/modules/terminal/terminal.rs @@ -4,7 +4,6 @@ use super::*; use std::fmt; -use std::io::Write; /// Struct that stores an specific platform implementation for terminal related actions. /// diff --git a/src/modules/terminal/winapi_terminal.rs b/src/modules/terminal/winapi_terminal.rs index 4192f0a..ecd77a6 100644 --- a/src/modules/terminal/winapi_terminal.rs +++ b/src/modules/terminal/winapi_terminal.rs @@ -61,9 +61,6 @@ impl ITerminal for WinApiTerminal { // Set srctWindow to the current window size and location. let mut srct_window = csbi.srWindow; - // Set srctWindow to the current window size and location. - srct_window = csbi.srWindow; - // Check whether the window is too close to the screen buffer top if srct_window.Bottom < csbi.dwSize.Y - count { srct_window.Top += count; // move top down