Wildcard import cleanup (#224)

This commit is contained in:
Zrzka 2019-09-16 18:15:56 +02:00 committed by Timon
parent 5494525d89
commit 77b61d1f6f
22 changed files with 207 additions and 192 deletions

View File

@ -5,19 +5,13 @@
use crossterm_utils::Result; use crossterm_utils::Result;
use self::ansi_cursor::AnsiCursor;
pub use self::cursor::{ pub use self::cursor::{
cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show, cursor, BlinkOff, BlinkOn, Down, Goto, Hide, Left, ResetPos, Right, SavePos, Show,
TerminalCursor, Up, TerminalCursor, Up,
}; };
#[cfg(windows)]
use self::winapi_cursor::WinApiCursor;
mod cursor; mod cursor;
#[cfg(test)]
mod test;
mod ansi_cursor; mod ansi_cursor;
#[cfg(windows)] #[cfg(windows)]
mod winapi_cursor; mod winapi_cursor;

View File

@ -104,3 +104,62 @@ impl ITerminalCursor for AnsiCursor {
Ok(()) 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
}
}

View File

@ -5,7 +5,10 @@
use crossterm_utils::supports_ansi; use crossterm_utils::supports_ansi;
use crossterm_utils::{impl_display, Command, Result}; 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. /// Allows you to preform actions with the terminal cursor.
/// ///

View File

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

View File

@ -77,3 +77,34 @@ impl ITerminalCursor for WinApiCursor {
Ok(()) 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);
}
}

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
pub use crossterm_utils::{ pub use crossterm_utils::{
execute, queue, Command, ErrorKind, ExecutableCommand, Output, QueueableCommand, Result, execute, queue, Command, ErrorKind, ExecutableCommand, Output, QueueableCommand, Result,
}; };

View File

@ -2,10 +2,6 @@
//! Like reading a line, reading a character and reading asynchronously. //! Like reading a line, reading a character and reading asynchronously.
use std::io; use std::io;
use std::sync::{
mpsc::{Receiver, Sender},
Arc,
};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -14,17 +10,9 @@ use crossterm_utils::Result;
pub use self::input::{input, TerminalInput}; pub use self::input::{input, TerminalInput};
#[cfg(unix)] #[cfg(unix)]
pub use self::unix_input::AsyncReader; pub use self::unix_input::{AsyncReader, SyncReader};
#[cfg(unix)]
pub use self::unix_input::SyncReader;
#[cfg(unix)]
use self::unix_input::UnixInput;
#[cfg(windows)] #[cfg(windows)]
pub use self::windows_input::AsyncReader; pub use self::windows_input::{AsyncReader, SyncReader};
#[cfg(windows)]
pub use self::windows_input::SyncReader;
#[cfg(windows)]
use self::windows_input::WindowsInput;
mod input; mod input;

View File

@ -3,7 +3,13 @@
use std::io; 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. /// Allows you to read user input.
/// ///

View File

@ -1,15 +1,21 @@
//! This is a UNIX specific implementation for input related action. //! This is a UNIX specific implementation for input related action.
use std::char; use std::char;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{
use std::{io::Read, str}; atomic::{AtomicBool, Ordering},
use std::{sync::mpsc, thread}; mpsc::{self, Receiver, Sender},
Arc,
};
use std::{
io::{self, Read},
str, thread,
};
use crossterm_utils::{csi, write_cout, ErrorKind, Result}; use crossterm_utils::{csi, write_cout, ErrorKind, Result};
use crate::sys::unix::{get_tty, read_char_raw}; use crate::sys::unix::{get_tty, read_char_raw};
use super::*; use super::{ITerminalInput, InputEvent, KeyEvent, MouseButton, MouseEvent};
pub struct UnixInput; pub struct UnixInput;

View File

@ -1,7 +1,10 @@
//! This is a WINDOWS specific implementation for input related action. //! This is a WINDOWS specific implementation for input related action.
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{
use std::sync::mpsc; atomic::{AtomicBool, Ordering},
mpsc::{self, Receiver, Sender},
Arc,
};
use std::time::Duration; use std::time::Duration;
use std::{char, io, thread}; use std::{char, io, thread};
@ -17,12 +20,13 @@ use winapi::um::{
}, },
}; };
use crossterm_utils::Result;
use crossterm_winapi::{ use crossterm_winapi::{
ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord, ButtonState, Console, ConsoleMode, EventFlags, Handle, InputEventType, KeyEventRecord,
MouseEvent, MouseEvent,
}; };
use super::*; use super::{ITerminalInput, InputEvent, KeyEvent, MouseButton};
pub struct WindowsInput; pub struct WindowsInput;

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
pub use crossterm_screen::{IntoRawMode, RawScreen}; pub use crossterm_screen::{IntoRawMode, RawScreen};
pub use self::input::{ pub use self::input::{

View File

@ -1,6 +1,5 @@
use std::fs;
use std::io;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::{fs, io};
/// Get the TTY device. /// Get the TTY device.
/// ///

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
//! A module which provides some functionalities to work with the terminal screen. //! 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. //! 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}; pub use self::screen::{AlternateScreen, IntoRawMode, RawScreen};

View File

@ -2,17 +2,19 @@
//! Like applying attributes to text and changing the foreground and background. //! Like applying attributes to text and changing the foreground and background.
use std::clone::Clone; use std::clone::Clone;
use std::fmt::Display;
use std::io; use std::io;
#[cfg(windows)] #[cfg(windows)]
use crossterm_utils::supports_ansi; use crossterm_utils::supports_ansi;
use crossterm_utils::{impl_display, Command, Result}; use crossterm_utils::{impl_display, Command, Result};
use super::ansi_color::{self, AnsiColor};
use super::enums::{Attribute, Color};
use super::styledobject::StyledObject;
#[cfg(windows)] #[cfg(windows)]
use crate::winapi_color::WinApiColor; use super::winapi_color::WinApiColor;
use crate::{Color, ITerminalColor}; use super::ITerminalColor;
use super::*;
/// Allows you to style the terminal. /// Allows you to style the terminal.
/// ///

View File

@ -1,11 +1,11 @@
//! A module that contains all the actions related to the styling of the terminal. //! 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. //! Like applying attributes to text and changing the foreground and background.
#![deny(unused_imports)]
use std::fmt::Display; use std::fmt::Display;
pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; 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::color::{color, PrintStyledFont, SetAttr, SetBg, SetFg, TerminalColor};
pub use self::enums::{Attribute, Color, Colored}; pub use self::enums::{Attribute, Color, Colored};
pub use self::objectstyle::ObjectStyle; pub use self::objectstyle::ObjectStyle;

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result}; pub use crossterm_utils::{execute, queue, Command, ExecutableCommand, QueueableCommand, Result};
pub use self::terminal::{terminal, Clear, ClearType, ScrollDown, ScrollUp, SetSize, Terminal}; pub use self::terminal::{terminal, Clear, ClearType, ScrollDown, ScrollUp, SetSize, Terminal};

View File

@ -9,9 +9,6 @@ pub use self::terminal::{terminal, Clear, ScrollDown, ScrollUp, SetSize, Termina
#[cfg(windows)] #[cfg(windows)]
use self::winapi_terminal::WinApiTerminal; use self::winapi_terminal::WinApiTerminal;
#[cfg(test)]
mod test;
mod terminal; mod terminal;
mod ansi_terminal; mod ansi_terminal;

View File

@ -4,9 +4,9 @@
use crossterm_cursor::TerminalCursor; use crossterm_cursor::TerminalCursor;
use crossterm_utils::{csi, write_cout, Result}; 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_ALL: &'static str = csi!("2J");
pub static CLEAR_FROM_CURSOR_DOWN: &'static str = csi!("J"); pub static CLEAR_FROM_CURSOR_DOWN: &'static str = csi!("J");
@ -80,3 +80,48 @@ impl ITerminal for AnsiTerminal {
Ok(()) 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
}
}

View File

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

View File

@ -9,7 +9,7 @@ use crossterm_winapi::{Console, Coord, Handle, ScreenBuffer, Size};
use crate::sys::winapi::get_terminal_size; use crate::sys::winapi::get_terminal_size;
use super::*; use super::{ClearType, ITerminal};
/// This struct is a winapi implementation for terminal related actions. /// This struct is a winapi implementation for terminal related actions.
pub struct WinApiTerminal; pub struct WinApiTerminal;
@ -271,3 +271,22 @@ fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) ->
Ok(()) 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);
}
}

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
pub use self::command::{Command, ExecutableCommand, Output, QueueableCommand}; pub use self::command::{Command, ExecutableCommand, Output, QueueableCommand};
pub use self::error::{ErrorKind, Result}; pub use self::error::{ErrorKind, Result};
#[cfg(windows)] #[cfg(windows)]

View File

@ -1,3 +1,5 @@
#![deny(unused_imports)]
pub use self::{ pub use self::{
console::Console, console::Console,
console_mode::ConsoleMode, console_mode::ConsoleMode,