From 77b61d1f6fca95aa0bbc729fa534773c94c26feb Mon Sep 17 00:00:00 2001 From: Zrzka Date: Mon, 16 Sep 2019 18:15:56 +0200 Subject: [PATCH] Wildcard import cleanup (#224) --- crossterm_cursor/src/cursor.rs | 6 -- crossterm_cursor/src/cursor/ansi_cursor.rs | 59 ++++++++++++ crossterm_cursor/src/cursor/cursor.rs | 5 +- crossterm_cursor/src/cursor/test.rs | 92 ------------------- crossterm_cursor/src/cursor/winapi_cursor.rs | 31 +++++++ crossterm_cursor/src/lib.rs | 2 + crossterm_input/src/input.rs | 16 +--- crossterm_input/src/input/input.rs | 8 +- crossterm_input/src/input/unix_input.rs | 14 ++- crossterm_input/src/input/windows_input.rs | 10 +- crossterm_input/src/lib.rs | 2 + crossterm_input/src/sys/unix.rs | 3 +- crossterm_screen/src/lib.rs | 2 + crossterm_style/src/color.rs | 10 +- crossterm_style/src/lib.rs | 2 +- crossterm_terminal/src/lib.rs | 2 + crossterm_terminal/src/terminal.rs | 3 - .../src/terminal/ansi_terminal.rs | 49 +++++++++- crossterm_terminal/src/terminal/test.rs | 58 ------------ .../src/terminal/winapi_terminal.rs | 21 ++++- crossterm_utils/src/lib.rs | 2 + crossterm_winapi/src/lib.rs | 2 + 22 files changed, 207 insertions(+), 192 deletions(-) delete mode 100644 crossterm_cursor/src/cursor/test.rs delete mode 100644 crossterm_terminal/src/terminal/test.rs diff --git a/crossterm_cursor/src/cursor.rs b/crossterm_cursor/src/cursor.rs index a21c84d..8a76028 100644 --- a/crossterm_cursor/src/cursor.rs +++ b/crossterm_cursor/src/cursor.rs @@ -5,19 +5,13 @@ use crossterm_utils::Result; -use self::ansi_cursor::AnsiCursor; pub use self::cursor::{ cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show, TerminalCursor, Up, }; -#[cfg(windows)] -use self::winapi_cursor::WinApiCursor; mod cursor; -#[cfg(test)] -mod test; - mod ansi_cursor; #[cfg(windows)] mod winapi_cursor; diff --git a/crossterm_cursor/src/cursor/ansi_cursor.rs b/crossterm_cursor/src/cursor/ansi_cursor.rs index c4683e7..d19c370 100644 --- a/crossterm_cursor/src/cursor/ansi_cursor.rs +++ b/crossterm_cursor/src/cursor/ansi_cursor.rs @@ -104,3 +104,62 @@ impl ITerminalCursor for AnsiCursor { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::{AnsiCursor, ITerminalCursor}; + + // TODO - Test is ingored, because it's stalled on Travis CI + #[test] + #[ignore] + fn reset_safe_ansi() { + if try_enable_ansi() { + let cursor = AnsiCursor::new(); + let (x, y) = cursor.pos(); + + assert!(cursor.save_position().is_ok()); + assert!(cursor.goto(5, 5).is_ok()); + assert!(cursor.reset_position().is_ok()); + + let (x_saved, y_saved) = cursor.pos(); + + assert_eq!(x, x_saved); + assert_eq!(y, y_saved); + } + } + + // TODO - Test is ingored, because it's stalled on Travis CI + #[test] + #[ignore] + fn goto_ansi() { + if try_enable_ansi() { + let cursor = AnsiCursor::new(); + let (x_saved, y_saved) = cursor.pos(); + + assert!(cursor.goto(5, 5).is_ok()); + let (x, y) = cursor.pos(); + + assert!(cursor.goto(x_saved, y_saved).is_ok()); + + assert_eq!(x, 5); + assert_eq!(y, 5); + } + } + + fn try_enable_ansi() -> bool { + #[cfg(windows)] + { + if cfg!(target_os = "windows") { + use crossterm_utils::sys::winapi::ansi::set_virtual_terminal_processing; + + // if it is not listed we should try with WinApi to check if we do support ANSI-codes. + match set_virtual_terminal_processing(true) { + Ok(_) => return true, + Err(_) => return false, + } + } + } + + true + } +} diff --git a/crossterm_cursor/src/cursor/cursor.rs b/crossterm_cursor/src/cursor/cursor.rs index 755e1e2..7783fe9 100644 --- a/crossterm_cursor/src/cursor/cursor.rs +++ b/crossterm_cursor/src/cursor/cursor.rs @@ -5,7 +5,10 @@ use crossterm_utils::supports_ansi; use crossterm_utils::{impl_display, Command, Result}; -use super::*; +use super::ansi_cursor::{self, AnsiCursor}; +#[cfg(windows)] +use super::winapi_cursor::WinApiCursor; +use super::ITerminalCursor; /// Allows you to preform actions with the terminal cursor. /// diff --git a/crossterm_cursor/src/cursor/test.rs b/crossterm_cursor/src/cursor/test.rs deleted file mode 100644 index ae1b6b2..0000000 --- a/crossterm_cursor/src/cursor/test.rs +++ /dev/null @@ -1,92 +0,0 @@ -#![allow(unused_must_use)] - -use super::AnsiCursor; -use super::ITerminalCursor; - -/* ======================== WinApi =========================== */ -#[cfg(windows)] -mod winapi_tests { - use super::super::WinApiCursor; - use super::*; - - #[test] - fn goto_winapi() { - let cursor = WinApiCursor::new(); - - cursor.goto(5, 5); - let (x, y) = cursor.pos(); - - assert_eq!(x, 5); - assert_eq!(y, 5); - } - - #[test] - fn reset_safe_winapi() { - let cursor = WinApiCursor::new(); - let (x, y) = cursor.pos(); - - cursor.save_position(); - cursor.goto(5, 5); - cursor.reset_position(); - - let (x_saved, y_saved) = cursor.pos(); - - assert_eq!(x, x_saved); - assert_eq!(y, y_saved); - } -} - -/* ======================== ANSI =========================== */ -// TODO - Test is ingored, because it's stalled on Travis CI -#[test] -#[ignore] -fn reset_safe_ansi() { - if try_enable_ansi() { - let cursor = AnsiCursor::new(); - let (x, y) = cursor.pos(); - - cursor.save_position(); - cursor.goto(5, 5); - cursor.reset_position(); - - let (x_saved, y_saved) = cursor.pos(); - - assert_eq!(x, x_saved); - assert_eq!(y, y_saved); - } -} - -// TODO - Test is ingored, because it's stalled on Travis CI -#[test] -#[ignore] -fn goto_ansi() { - if try_enable_ansi() { - let cursor = AnsiCursor::new(); - let (x_saved, y_saved) = cursor.pos(); - - cursor.goto(5, 5); - let (x, y) = cursor.pos(); - - cursor.goto(x_saved, y_saved); - - assert_eq!(x, 5); - assert_eq!(y, 5); - } -} - -fn try_enable_ansi() -> bool { - #[cfg(windows)] - { - if cfg!(target_os = "windows") { - use crossterm_utils::sys::winapi::ansi::set_virtual_terminal_processing; - - // if it is not listed we should try with WinApi to check if we do support ANSI-codes. - match set_virtual_terminal_processing(true) { - Ok(_) => return true, - Err(_) => return false, - } - } - } - - true -} diff --git a/crossterm_cursor/src/cursor/winapi_cursor.rs b/crossterm_cursor/src/cursor/winapi_cursor.rs index 6c1f399..d95f9a9 100644 --- a/crossterm_cursor/src/cursor/winapi_cursor.rs +++ b/crossterm_cursor/src/cursor/winapi_cursor.rs @@ -77,3 +77,34 @@ impl ITerminalCursor for WinApiCursor { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::{ITerminalCursor, WinApiCursor}; + + #[test] + fn goto_winapi() { + let cursor = WinApiCursor::new(); + + assert!(cursor.goto(5, 5).is_ok()); + let (x, y) = cursor.pos(); + + assert_eq!(x, 5); + assert_eq!(y, 5); + } + + #[test] + fn reset_safe_winapi() { + let cursor = WinApiCursor::new(); + let (x, y) = cursor.pos(); + + assert!(cursor.save_position().is_ok()); + assert!(cursor.goto(5, 5).is_ok()); + assert!(cursor.reset_position().is_ok()); + + let (x_saved, y_saved) = cursor.pos(); + + assert_eq!(x, x_saved); + assert_eq!(y, y_saved); + } +} diff --git a/crossterm_cursor/src/lib.rs b/crossterm_cursor/src/lib.rs index e592e84..a267434 100644 --- a/crossterm_cursor/src/lib.rs +++ b/crossterm_cursor/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + pub use crossterm_utils::{ execute, queue, Command, ErrorKind, ExecutableCommand, Output, QueueableCommand, Result, }; diff --git a/crossterm_input/src/input.rs b/crossterm_input/src/input.rs index 426fb6a..aa347f5 100644 --- a/crossterm_input/src/input.rs +++ b/crossterm_input/src/input.rs @@ -2,10 +2,6 @@ //! Like reading a line, reading a character and reading asynchronously. use std::io; -use std::sync::{ - mpsc::{Receiver, Sender}, - Arc, -}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -14,17 +10,9 @@ use crossterm_utils::Result; pub use self::input::{input, TerminalInput}; #[cfg(unix)] -pub use self::unix_input::AsyncReader; -#[cfg(unix)] -pub use self::unix_input::SyncReader; -#[cfg(unix)] -use self::unix_input::UnixInput; +pub use self::unix_input::{AsyncReader, SyncReader}; #[cfg(windows)] -pub use self::windows_input::AsyncReader; -#[cfg(windows)] -pub use self::windows_input::SyncReader; -#[cfg(windows)] -use self::windows_input::WindowsInput; +pub use self::windows_input::{AsyncReader, SyncReader}; mod input; diff --git a/crossterm_input/src/input/input.rs b/crossterm_input/src/input/input.rs index 3f80e77..89870d9 100644 --- a/crossterm_input/src/input/input.rs +++ b/crossterm_input/src/input/input.rs @@ -3,7 +3,13 @@ use std::io; -use super::*; +use crossterm_utils::Result; + +#[cfg(unix)] +use super::unix_input::{AsyncReader, SyncReader, UnixInput}; +#[cfg(windows)] +use super::windows_input::{AsyncReader, SyncReader, WindowsInput}; +use super::ITerminalInput; /// Allows you to read user input. /// diff --git a/crossterm_input/src/input/unix_input.rs b/crossterm_input/src/input/unix_input.rs index fda8079..07186a2 100644 --- a/crossterm_input/src/input/unix_input.rs +++ b/crossterm_input/src/input/unix_input.rs @@ -1,15 +1,21 @@ //! This is a UNIX specific implementation for input related action. use std::char; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::{io::Read, str}; -use std::{sync::mpsc, thread}; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::{self, Receiver, Sender}, + Arc, +}; +use std::{ + io::{self, Read}, + str, thread, +}; use crossterm_utils::{csi, write_cout, ErrorKind, Result}; use crate::sys::unix::{get_tty, read_char_raw}; -use super::*; +use super::{ITerminalInput, InputEvent, KeyEvent, MouseButton, MouseEvent}; pub struct UnixInput; diff --git a/crossterm_input/src/input/windows_input.rs b/crossterm_input/src/input/windows_input.rs index 91447cd..88a8744 100644 --- a/crossterm_input/src/input/windows_input.rs +++ b/crossterm_input/src/input/windows_input.rs @@ -1,7 +1,10 @@ //! This is a WINDOWS specific implementation for input related action. -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + mpsc::{self, Receiver, Sender}, + Arc, +}; use std::time::Duration; use std::{char, io, thread}; @@ -17,12 +20,13 @@ use winapi::um::{ }, }; +use crossterm_utils::Result; use crossterm_winapi::{ ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord, MouseEvent, }; -use super::*; +use super::{ITerminalInput, InputEvent, KeyEvent, MouseButton}; pub struct WindowsInput; diff --git a/crossterm_input/src/lib.rs b/crossterm_input/src/lib.rs index 199df39..059c3c3 100644 --- a/crossterm_input/src/lib.rs +++ b/crossterm_input/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + pub use crossterm_screen::{IntoRawMode, RawScreen}; pub use self::input::{ diff --git a/crossterm_input/src/sys/unix.rs b/crossterm_input/src/sys/unix.rs index 1f26522..22ab810 100644 --- a/crossterm_input/src/sys/unix.rs +++ b/crossterm_input/src/sys/unix.rs @@ -1,6 +1,5 @@ -use std::fs; -use std::io; use std::os::unix::io::AsRawFd; +use std::{fs, io}; /// Get the TTY device. /// diff --git a/crossterm_screen/src/lib.rs b/crossterm_screen/src/lib.rs index f173678..2298100 100644 --- a/crossterm_screen/src/lib.rs +++ b/crossterm_screen/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + //! A module which provides some functionalities to work with the terminal screen. //! Like allowing you to switch between the main and alternate screen or putting the terminal into raw mode. pub use self::screen::{AlternateScreen, IntoRawMode, RawScreen}; diff --git a/crossterm_style/src/color.rs b/crossterm_style/src/color.rs index cf22604..e19c54f 100644 --- a/crossterm_style/src/color.rs +++ b/crossterm_style/src/color.rs @@ -2,17 +2,19 @@ //! Like applying attributes to text and changing the foreground and background. use std::clone::Clone; +use std::fmt::Display; use std::io; #[cfg(windows)] use crossterm_utils::supports_ansi; use crossterm_utils::{impl_display, Command, Result}; +use super::ansi_color::{self, AnsiColor}; +use super::enums::{Attribute, Color}; +use super::styledobject::StyledObject; #[cfg(windows)] -use crate::winapi_color::WinApiColor; -use crate::{Color, ITerminalColor}; - -use super::*; +use super::winapi_color::WinApiColor; +use super::ITerminalColor; /// Allows you to style the terminal. /// diff --git a/crossterm_style/src/lib.rs b/crossterm_style/src/lib.rs index 1f642f8..cf8fbb5 100644 --- a/crossterm_style/src/lib.rs +++ b/crossterm_style/src/lib.rs @@ -1,11 +1,11 @@ //! A module that contains all the actions related to the styling of the terminal. //! Like applying attributes to text and changing the foreground and background. +#![deny(unused_imports)] use std::fmt::Display; pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; -use self::ansi_color::AnsiColor; pub use self::color::{color, PrintStyledFont, SetAttr, SetBg, SetFg, TerminalColor}; pub use self::enums::{Attribute, Color, Colored}; pub use self::objectstyle::ObjectStyle; diff --git a/crossterm_terminal/src/lib.rs b/crossterm_terminal/src/lib.rs index 3b207ff..c8582bb 100644 --- a/crossterm_terminal/src/lib.rs +++ b/crossterm_terminal/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; pub use self::terminal::{terminal, Clear, ClearType, ScrollDown, ScrollUp, SetSize, Terminal}; diff --git a/crossterm_terminal/src/terminal.rs b/crossterm_terminal/src/terminal.rs index 43d217b..30e27f9 100644 --- a/crossterm_terminal/src/terminal.rs +++ b/crossterm_terminal/src/terminal.rs @@ -9,9 +9,6 @@ pub use self::terminal::{terminal, Clear, ScrollDown, ScrollUp, SetSize, Termina #[cfg(windows)] use self::winapi_terminal::WinApiTerminal; -#[cfg(test)] -mod test; - mod terminal; mod ansi_terminal; diff --git a/crossterm_terminal/src/terminal/ansi_terminal.rs b/crossterm_terminal/src/terminal/ansi_terminal.rs index eddc324..2a93b7c 100644 --- a/crossterm_terminal/src/terminal/ansi_terminal.rs +++ b/crossterm_terminal/src/terminal/ansi_terminal.rs @@ -4,9 +4,9 @@ use crossterm_cursor::TerminalCursor; use crossterm_utils::{csi, write_cout, Result}; -use crate::{sys::get_terminal_size, ClearType}; +use crate::sys::get_terminal_size; -use super::ITerminal; +use super::{ClearType, ITerminal}; pub static CLEAR_ALL: &'static str = csi!("2J"); pub static CLEAR_FROM_CURSOR_DOWN: &'static str = csi!("J"); @@ -80,3 +80,48 @@ impl ITerminal for AnsiTerminal { Ok(()) } } + +#[cfg(test)] +mod tests { + use std::{thread, time}; + + use super::{AnsiTerminal, ITerminal}; + + /* ======================== ANSI =========================== */ + // TODO - Test is disabled, because it's failing on Travis CI + #[test] + #[ignore] + fn resize_ansi() { + if try_enable_ansi() { + let terminal = AnsiTerminal::new(); + + assert!(terminal.set_size(50, 50).is_ok()); + + // see issue: https://github.com/eminence/terminal-size/issues/11 + thread::sleep(time::Duration::from_millis(30)); + + let (x, y) = terminal.terminal_size(); + + assert_eq!(x, 50); + assert_eq!(y, 50); + } + } + + fn try_enable_ansi() -> bool { + #[cfg(windows)] + { + if cfg!(target_os = "windows") { + use crossterm_utils::sys::winapi::ansi::set_virtual_terminal_processing; + + // if it is not listed we should try with WinApi to check if we do support ANSI-codes. + match set_virtual_terminal_processing(true) { + Ok(_) => return true, + Err(_) => return false, + } + } + } + + true + } + +} diff --git a/crossterm_terminal/src/terminal/test.rs b/crossterm_terminal/src/terminal/test.rs deleted file mode 100644 index 91d6a56..0000000 --- a/crossterm_terminal/src/terminal/test.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* ======================== WinApi =========================== */ -#[cfg(windows)] -mod winapi_tests { - use super::super::*; - - // TODO - Test is ignored, because it returns wrong result (31 != 30) - #[test] - #[ignore] - fn resize_winapi() { - let terminal = WinApiTerminal::new(); - - terminal.set_size(30, 30).unwrap(); - - let (x, y) = terminal.terminal_size(); - - assert_eq!(x, 30); - assert_eq!(y, 30); - } -} - -/* ======================== ANSI =========================== */ -// TODO - Test is disabled, because it's failing on Travis CI -#[test] -#[ignore] -fn resize_ansi() { - use super::*; - use std::{thread, time}; - if try_enable_ansi() { - let terminal = AnsiTerminal::new(); - - terminal.set_size(50, 50).unwrap(); - - // see issue: https://github.com/eminence/terminal-size/issues/11 - thread::sleep(time::Duration::from_millis(30)); - - let (x, y) = terminal.terminal_size(); - - assert_eq!(x, 50); - assert_eq!(y, 50); - } -} - -fn try_enable_ansi() -> bool { - #[cfg(windows)] - { - if cfg!(target_os = "windows") { - use crossterm_utils::sys::winapi::ansi::set_virtual_terminal_processing; - - // if it is not listed we should try with WinApi to check if we do support ANSI-codes. - match set_virtual_terminal_processing(true) { - Ok(_) => return true, - Err(_) => return false, - } - } - } - - true -} diff --git a/crossterm_terminal/src/terminal/winapi_terminal.rs b/crossterm_terminal/src/terminal/winapi_terminal.rs index d38a086..86ff1c0 100644 --- a/crossterm_terminal/src/terminal/winapi_terminal.rs +++ b/crossterm_terminal/src/terminal/winapi_terminal.rs @@ -9,7 +9,7 @@ use crossterm_winapi::{Console, Coord, Handle, ScreenBuffer, Size}; use crate::sys::winapi::get_terminal_size; -use super::*; +use super::{ClearType, ITerminal}; /// This struct is a winapi implementation for terminal related actions. pub struct WinApiTerminal; @@ -271,3 +271,22 @@ fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) -> Ok(()) } + +#[cfg(test)] +mod tests { + use super::{ITerminal, WinApiTerminal}; + + // TODO - Test is ignored, because it returns wrong result (31 != 30) + #[test] + #[ignore] + fn resize_winapi() { + let terminal = WinApiTerminal::new(); + + assert!(terminal.set_size(30, 30).is_ok()); + + let (x, y) = terminal.terminal_size(); + + assert_eq!(x, 30); + assert_eq!(y, 30); + } +} diff --git a/crossterm_utils/src/lib.rs b/crossterm_utils/src/lib.rs index 499be96..8d47582 100644 --- a/crossterm_utils/src/lib.rs +++ b/crossterm_utils/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + pub use self::command::{Command, ExecutableCommand, Output, QueueableCommand}; pub use self::error::{ErrorKind, Result}; #[cfg(windows)] diff --git a/crossterm_winapi/src/lib.rs b/crossterm_winapi/src/lib.rs index 2b41e33..af65941 100644 --- a/crossterm_winapi/src/lib.rs +++ b/crossterm_winapi/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(unused_imports)] + pub use self::{ console::Console, console_mode::ConsoleMode,