From 3878993459e41cedbaf373ba255a3aa7ad8e5a6e Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Jun 2018 23:19:02 +0200 Subject: [PATCH] Removed all unused namespaces --- .idea/workspace.xml | 621 +++++++++--------- Cargo.toml | 2 +- .../terminal/alternate_screen.rs | 131 ---- examples/Crossterm 0.2.1/terminal/raw_mode.rs | 1 - .../color/mod.rs | 2 +- src/cursor/ansi_cursor.rs | 12 +- src/cursor/cursor.rs | 6 +- src/cursor/mod.rs | 6 +- src/kernel/unix_kernel/terminal.rs | 3 +- src/manager/ansi_manager.rs | 4 +- src/manager/manager.rs | 1 - src/manager/mod.rs | 1 - src/manager/terminal.rs | 7 +- src/shared/functions.rs | 3 +- src/state/commands/shared_commands.rs | 6 +- src/state/context.rs | 7 +- src/style/color/ansi_color.rs | 3 +- src/style/color/color.rs | 8 +- src/style/color/mod.rs | 2 +- src/style/styles/objectstyle.rs | 2 +- src/style/styles/styledobject.rs | 6 +- src/terminal/ansi_terminal.rs | 7 +- src/terminal/mod.rs | 6 +- src/terminal/screen.rs | 4 +- src/terminal/terminal.rs | 5 +- 25 files changed, 325 insertions(+), 531 deletions(-) delete mode 100644 examples/Crossterm 0.2.1/terminal/alternate_screen.rs delete mode 100644 examples/Crossterm 0.2.1/terminal/raw_mode.rs diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 28791c7..4fc1481 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,41 +2,29 @@ - - - - - - - - - - + + + - - - + + + + - - - - - - @@ -48,28 +36,7 @@ - - - - - - - - - - - - - - - - - - - - - - + - write set make get @@ -110,6 +76,7 @@ termina screen colored_terminal + ObjectStyle crossterm_cursor @@ -135,7 +102,6 @@ @@ -249,24 +216,6 @@ - - - - - - - - - - - - - - - - - - @@ -555,16 +504,15 @@ - + - - @@ -579,7 +527,7 @@ - + @@ -636,41 +584,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -727,13 +640,6 @@ - - - - - - - @@ -748,13 +654,6 @@ - - - - - - - @@ -762,13 +661,6 @@ - - - - - - - @@ -777,29 +669,11 @@ - - - - - - - - - - - - - - - - - - - + @@ -827,22 +701,6 @@ - - - - - - - - - - - - - - - - @@ -851,14 +709,6 @@ - - - - - - - - @@ -867,75 +717,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -952,78 +733,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1034,12 +743,268 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Cargo.toml b/Cargo.toml index f3c4c1c..48a5a9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,4 +26,4 @@ path = "src/lib.rs" [[bin]] name = "a" -path = "examples/bin.rs" +path = "examples/Crossterm 0.2.2 - New Version (Not finished)/bin.rs" diff --git a/examples/Crossterm 0.2.1/terminal/alternate_screen.rs b/examples/Crossterm 0.2.1/terminal/alternate_screen.rs deleted file mode 100644 index f41e734..0000000 --- a/examples/Crossterm 0.2.1/terminal/alternate_screen.rs +++ /dev/null @@ -1,131 +0,0 @@ - //alternate screen is not working correctly currently - - -extern crate crossterm; - - use self::crossterm::{ Context, Terminal }; -use self::crossterm::cursor::cursor; -use self::crossterm::terminal::{self, ClearType}; -use self::crossterm::terminal::screen; - -use std::io::{Write, stdout}; -use std::{time, thread}; - -/// this will print an example wait screen. -fn print_wait_screen(terminal: &Terminal) - { - // clear the screen and reset the cursor pos - terminal::terminal(&terminal).clear(ClearType::All); - let mut cursor = cursor(&terminal); - cursor.goto(0, 0); - - // we need to create a scope so that or mutex gueard will be dropped. we need the output also some lines future from here. - let mut screen_manager = &terminal.screen_manager; - { - let mut output = screen_manager.lock().unwrap(); - { - write!(output.stdout(), - "Welcome to the wait screen.\n\ - Please wait a few seconds until we arrive back at the main screen.\n\n - Possessing: " - ); - } - } - - for i in 0..5 - { - // 1 second delay - thread::sleep(time::Duration::from_secs(1)); - - // print the current counter at the line of `Seconds to Go: {counter}` - cursor.goto(11, 5).print(format!("{} of the 5 items initialized!", i)); - } - } - - /// this will switch the to alternate modes for 3 seconds after that it wil stitch back to main screen. -pub fn switch_to_alternate_screen_and_back() -{ - // create scope for the alternate screen when the scope ends the screen will be switched back to mainscreen. - let terminal = Terminal::new(); - { - let alternate_screen = screen::AlternateScreen::from(&terminal); - - // Print the wait screen. - print_wait_screen(&terminal); - } - - terminal::terminal(&terminal).clear(ClearType::All); - cursor::cursor(&terminal).goto(0,0); - println!("Whe are back at the main screen"); -} - - /// This demonstrates how to switch to alternate screen and main screen. - pub fn stress_test() - { - let terminal = Terminal::new(); - { - // clear main screen - terminal::terminal(&terminal).clear(ClearType::All); - - // create alternate screen and switch into that mode. - let mut alternate_screen = screen::AlternateScreen::from(&terminal); - - // clear the alternate screen. - terminal::terminal(&terminal).clear(ClearType::All); - - // switch to alternate screen and back to main after three seconds - write!(alternate_screen, "{}", "We are at the alternatescreen \n"); - thread::sleep(time::Duration::from_secs(3)); - alternate_screen.to_main(); - write!(alternate_screen, "{}", "We are back at the main screen 1\n"); - - // switch to alternate screen and back to main after three seconds - thread::sleep(time::Duration::from_secs(3)); - alternate_screen.to_alternate(); - write!(alternate_screen, "{}", "We are at the alternatescreen 2\n"); - thread::sleep(time::Duration::from_secs(3)); - alternate_screen.to_main(); - write!(alternate_screen, "{}", "We are back at the main screen 2\n"); - - // switch to alternate screen and back to main after three seconds - thread::sleep(time::Duration::from_secs(3)); - alternate_screen.to_alternate(); - write!(alternate_screen, "{}", "We are at the alternatescreen 3\n"); - thread::sleep(time::Duration::from_secs(3)); - alternate_screen.to_main(); - write!(alternate_screen, "{}", "We are back at the main screen 3\n"); - } - } - - pub fn t() - { - use self::crossterm::cursor::cursor; - use self::crossterm::style::Color; - use std::io; - let terminal = Terminal::new(); - { - let mut alternate_screen = screen::AlternateScreen::from(&terminal); - terminal::terminal(&terminal).clear(ClearType::All); - write!(alternate_screen, "{}", "We are at the alternatescreen \n"); - - - // Goto X: 5 Y: 5 - cursor(&terminal).goto(5,5); - // Safe cursor position: X: 5 Y: 5 - cursor(&terminal).save_position(); - // Goto X: 5 Y: 20 - cursor(&terminal).goto(5,20); - // Print at X: 5 Y: 20. - write!(io::stdout(), "{}", terminal.paint("Yea").with(Color::Blue)); - // Reset back to X: 5 Y: 5. - cursor(&terminal).reset_position(); - // Print Back at X: 5 Y: 5. - write!(io::stdout(), "{}", terminal.paint("Back").with(Color::Red)); - - println!(); - - thread::sleep(time::Duration::from_secs(3)); - } - terminal::terminal(&terminal).clear(ClearType::All); - println!("Back at the main screen"); - } \ No newline at end of file diff --git a/examples/Crossterm 0.2.1/terminal/raw_mode.rs b/examples/Crossterm 0.2.1/terminal/raw_mode.rs deleted file mode 100644 index d0454d2..0000000 --- a/examples/Crossterm 0.2.1/terminal/raw_mode.rs +++ /dev/null @@ -1 +0,0 @@ -// raw screen is not working correctly currently diff --git a/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs b/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs index 0ee49a6..e07c49b 100644 --- a/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs +++ b/examples/Crossterm 0.2.2 - New Version (Not finished)/color/mod.rs @@ -4,7 +4,7 @@ extern crate crossterm; -use self::crossterm::style::{paint, Color}; +use self::crossterm::style::{ Color }; /// print some red font | demonstration. pub fn paint_foreground() diff --git a/src/cursor/ansi_cursor.rs b/src/cursor/ansi_cursor.rs index 2481fee..9d47468 100644 --- a/src/cursor/ansi_cursor.rs +++ b/src/cursor/ansi_cursor.rs @@ -1,11 +1,9 @@ //! This is an ANSI specific implementation for cursor related action. //! This module is used for windows 10 terminals and unix terminals by default. -use std::sync::Mutex; -use { Context, ScreenManager, Terminal }; +use Terminal ; use shared::functions; use super::ITerminalCursor; -use std::io::{ self, Write }; /// This struct is an ansi implementation for cursor related actions. @@ -37,28 +35,28 @@ impl<'term> ITerminalCursor for AnsiCursor { fn move_up(&self, count: u16, terminal: &Terminal) { let mut screen = terminal.screen_manager.lock().unwrap(); { - screen.write_ansi_str(csi!("{}A")); + screen.write_ansi(format!(csi!("{}A"), count)); } } fn move_right(&self, count: u16, terminal: &Terminal) { let mut screen = terminal.screen_manager.lock().unwrap(); { - screen.write_ansi_str(csi!("{}C")); + screen.write_ansi(format!(csi!("{}C"), count)); } } fn move_down(&self, count: u16, terminal: &Terminal) { let mut screen = terminal.screen_manager.lock().unwrap(); { - screen.write_ansi_str(csi!("{}B")); + screen.write_ansi(format!(csi!("{}B"), count)); } } fn move_left(&self, count: u16, terminal: &Terminal) { let mut screen = terminal.screen_manager.lock().unwrap(); { - screen.write_ansi_str(csi!("{}D")); + screen.write_ansi(format!(csi!("{}D"), count)); } } diff --git a/src/cursor/cursor.rs b/src/cursor/cursor.rs index 6f24d99..f12e923 100644 --- a/src/cursor/cursor.rs +++ b/src/cursor/cursor.rs @@ -4,13 +4,9 @@ //! Note that positions of the cursor are 0 -based witch means that the coordinates starts counting from 0 use super::*; -use shared::functions; -use { Construct, Context, ScreenManager, Terminal }; +use Terminal; use std::fmt::Display; -use std::ops::Drop; - -use std; use std::io::Write; /// Struct that stores an specific platform implementation for cursor related actions. diff --git a/src/cursor/mod.rs b/src/cursor/mod.rs index 49b8813..8389102 100644 --- a/src/cursor/mod.rs +++ b/src/cursor/mod.rs @@ -17,13 +17,9 @@ mod ansi_cursor; use self::winapi_cursor::WinApiCursor; use self::ansi_cursor::AnsiCursor; -use { Context, Terminal }; +use Terminal; pub use self::cursor::{ cursor, TerminalCursor }; -use std::sync::Mutex; - -use ScreenManager; - ///! This trait defines the actions that can be preformed with the terminal cursor. ///! This trait can be implemented so that an concrete implementation of the ITerminalCursor can forfill ///! the wishes to work on an specific platform. diff --git a/src/kernel/unix_kernel/terminal.rs b/src/kernel/unix_kernel/terminal.rs index 5f1be00..6655e53 100644 --- a/src/kernel/unix_kernel/terminal.rs +++ b/src/kernel/unix_kernel/terminal.rs @@ -6,8 +6,8 @@ pub use self::libc::{termios}; use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl, c_int}; use state::commands::{ NoncanonicalModeCommand, IContextCommand} ; -use std::{ io, mem }; use std::io::Error; +use std::{ io, mem }; /// A representation of the size of the current terminal. #[repr(C)] @@ -42,7 +42,6 @@ pub fn terminal_size() -> (u16,u16) { /// Get the current cursor position. pub fn pos(terminal: &Terminal) -> (u16,u16) { - use std::io::Error; use std::io::{ Write,Read }; let mut context = Context::new(); diff --git a/src/manager/ansi_manager.rs b/src/manager/ansi_manager.rs index 691ed5c..3248184 100644 --- a/src/manager/ansi_manager.rs +++ b/src/manager/ansi_manager.rs @@ -1,8 +1,6 @@ use std::io::{self, Write}; -use { Context, Terminal }; + use super::IScreenManager; -use super::super::state::commands::ICommand; -use super::super::state::commands::shared_commands::ToAlternateScreenBufferCommand; pub struct AnsiScreenManager { diff --git a/src/manager/manager.rs b/src/manager/manager.rs index e9eb468..a9b07bd 100644 --- a/src/manager/manager.rs +++ b/src/manager/manager.rs @@ -1,6 +1,5 @@ use std::io::Write; -use { Context, Terminal }; use super::IScreenManager; use super::ansi_manager::AnsiScreenManager; diff --git a/src/manager/mod.rs b/src/manager/mod.rs index 0c12f45..15035f3 100644 --- a/src/manager/mod.rs +++ b/src/manager/mod.rs @@ -9,7 +9,6 @@ mod ansi_manager; use self::win_manager::WinApiScreenManager; use self::ansi_manager::AnsiScreenManager; -use { Context, Terminal }; pub use self::manager::{ ScreenManager }; pub trait IScreenManager diff --git a/src/manager/terminal.rs b/src/manager/terminal.rs index 21e39d0..120a9af 100644 --- a/src/manager/terminal.rs +++ b/src/manager/terminal.rs @@ -1,14 +1,11 @@ -use std::io::Write; -use std::io; use std::sync::Mutex; -use std::cell::RefCell; use std::rc::Rc; use { Context }; use super::super::manager::ScreenManager; -use super::super::terminal; -use super::super::cursor; +//use super::super::terminal; +//use super::super::cursor; use super::super::style; use std::fmt; diff --git a/src/shared/functions.rs b/src/shared/functions.rs index eeb5d61..7335674 100644 --- a/src/shared/functions.rs +++ b/src/shared/functions.rs @@ -1,7 +1,6 @@ //! Some actions need to preformed platform independently since they can not be solved `ANSI escape codes`. -use std::sync::Mutex; -use {Context, ScreenManager, Terminal}; +use Terminal; #[cfg(windows)] use kernel::windows_kernel::terminal::terminal_size; diff --git a/src/state/commands/shared_commands.rs b/src/state/commands/shared_commands.rs index 1d341b5..c332b82 100644 --- a/src/state/commands/shared_commands.rs +++ b/src/state/commands/shared_commands.rs @@ -1,8 +1,6 @@ //! This module contains the commands that can be used for both unix and windows systems. -use { Context, Terminal }; -use super::{ ICommand, IContextCommand }; -use std::io; -use std::io::Write; +use Terminal ; +use super::ICommand; /// This command is used for switching to alternate screen and back to main screen. #[derive(Clone, Copy)] diff --git a/src/state/context.rs b/src/state/context.rs index 8329967..78609a7 100644 --- a/src/state/context.rs +++ b/src/state/context.rs @@ -1,12 +1,7 @@ //! This module is used for registering, storing an restoring the terminal state changes. -use std::ops::Drop; use std::collections::HashMap; -use std::io::Write; -use std::sync::Mutex; - -use super::commands::{ ICommand, IContextCommand}; -use super::super::manager::ScreenManager; +use super::commands::IContextCommand; /// Struct that stores the changed states of the terminal. pub struct Context diff --git a/src/style/color/ansi_color.rs b/src/style/color/ansi_color.rs index 545c269..072823c 100644 --- a/src/style/color/ansi_color.rs +++ b/src/style/color/ansi_color.rs @@ -1,11 +1,10 @@ //! This is an ANSI specific implementation for styling related action. //! This module is used for windows 10 terminals and unix terminals by default. -use { Construct, Terminal, ScreenManager }; +use { Construct, ScreenManager }; use super::ITerminalColor; use super::super::{Color, ColorType}; -use std::io::{self, Write}; use std::rc::Rc; use std::sync::Mutex; diff --git a/src/style/color/color.rs b/src/style/color/color.rs index 083d34e..0f60821 100644 --- a/src/style/color/color.rs +++ b/src/style/color/color.rs @@ -2,12 +2,10 @@ //! Like styling the font, foreground color and background. use super::*; -use shared::functions; -use { Construct, Context, Terminal }; -use style::{Color, ObjectStyle, StyledObject}; +use Construct; +use style::Color; -use std::ops::Drop; -use std::{ fmt, io }; +use std::{ io }; use std::rc::Rc; use std::sync::Mutex; diff --git a/src/style/color/mod.rs b/src/style/color/mod.rs index 7e20bc7..435e43c 100644 --- a/src/style/color/mod.rs +++ b/src/style/color/mod.rs @@ -12,7 +12,7 @@ use super::{Color, ColorType}; use std::rc::Rc; use std::sync::Mutex; -use { Terminal, ScreenManager }; +use { ScreenManager }; ///! This trait defines the actions that can be preformed with the terminal color. ///! This trait can be implemented so that an concrete implementation of the ITerminalColor can forfill diff --git a/src/style/styles/objectstyle.rs b/src/style/styles/objectstyle.rs index 49dc3f7..52edd5f 100644 --- a/src/style/styles/objectstyle.rs +++ b/src/style/styles/objectstyle.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use style::{Color, StyledObject}; -use { Terminal, ScreenManager }; +use ScreenManager; use std::sync::Mutex; use std::rc::Rc; #[cfg(unix)] diff --git a/src/style/styles/styledobject.rs b/src/style/styles/styledobject.rs index 0703556..fc6681c 100644 --- a/src/style/styles/styledobject.rs +++ b/src/style/styles/styledobject.rs @@ -1,10 +1,10 @@ //! This module contains the logic to style an object that contains some context witch can be styled. -use std::{ self, fmt }; +use std::fmt; use std::io::Write; use std::sync::Mutex; use std::rc::Rc; -use { Terminal, ScreenManager }; +use ScreenManager; #[cfg(unix)] use super::super::Attribute; @@ -138,7 +138,7 @@ macro_rules! impl_fmt fmt::$name::fmt(&self.content, f)?; - let mut mutex = &self.screen_manager; + let mutex = &self.screen_manager; { let mut screen = mutex.lock().unwrap(); screen.stdout().flush().expect("Flush stdout failed"); diff --git a/src/terminal/ansi_terminal.rs b/src/terminal/ansi_terminal.rs index ec72d4a..f5c4b40 100644 --- a/src/terminal/ansi_terminal.rs +++ b/src/terminal/ansi_terminal.rs @@ -5,12 +5,7 @@ use {Construct, Terminal}; use shared::functions; use super::{ClearType, ITerminal}; -use std::io; use std::io::Write; -use std::sync::Mutex; -use std::cell::RefCell; - -use ScreenManager; /// This struct is an ansi implementation for terminal related actions. pub struct AnsiTerminal; @@ -26,7 +21,7 @@ impl ITerminal for AnsiTerminal { let mut screen_manager = terminal.screen_manager.lock().unwrap(); { - let mut stdout = screen_manager.stdout(); + let stdout = screen_manager.stdout(); match clear_type { ClearType::All => { diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index 2e5c74e..9b6bf8c 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -5,13 +5,13 @@ //! - raw mode //! - clearing resizing scrolling the terminal. -use {Context, ScreenManager, Terminal}; +use Terminal; use self::ansi_terminal::AnsiTerminal; + pub use self::terminal::{ terminal}; #[cfg(target_os = "windows")] use self::winapi_terminal::WinApiTerminal; -use std::cell::RefCell; -use std::sync::Mutex; + pub mod terminal; diff --git a/src/terminal/screen.rs b/src/terminal/screen.rs index e4f3878..f3e6fdc 100644 --- a/src/terminal/screen.rs +++ b/src/terminal/screen.rs @@ -1,10 +1,8 @@ //! This module contains all the logic for switching between alternate screen and main screen. -use shared::functions; -use { Context, Terminal }; +use Terminal; use state::commands::*; -use std::{ fmt, ops }; use std::io::{self, Write}; //pub struct ToMainScreen; diff --git a/src/terminal/terminal.rs b/src/terminal/terminal.rs index 9261d84..e876f08 100644 --- a/src/terminal/terminal.rs +++ b/src/terminal/terminal.rs @@ -2,12 +2,9 @@ //! Like clearing and scrolling in the terminal or getting the size of the terminal. use super::*; -use shared::functions; -use { Construct, Context }; +use Construct; use super::super::manager::terminal; -use std::ops::Drop; - /// Struct that stores an specific platform implementation for terminal related actions. pub struct Terminal<'terminal> { terminal: Option>,