-
+
@@ -537,15 +633,16 @@
-
+
-
+
+
@@ -557,7 +654,6 @@
-
@@ -600,295 +696,401 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -896,116 +1098,18 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/bin.rs b/examples/bin.rs
index 4e2c31f..fa8a2b5 100644
--- a/examples/bin.rs
+++ b/examples/bin.rs
@@ -11,36 +11,18 @@
//!
//! - Run program with: `cargo run`
-// Import crossterm crate.
extern crate crossterm;
-//
-//// Add the usings for the crossterms modules to play with crossterm
-//use self::crossterm::crossterm_style::{paint, Color };
-use self::crossterm::crossterm_cursor::cursor;
-use self::crossterm::crossterm_terminal;
-//
-//// Import the example modules.
-//pub mod color;
-//pub mod cursor;
-//pub mod terminal;
-use std::io::{self, Error, ErrorKind, Write, stdout, stdin, BufRead};
-//use std::{time, thread};
-//
-use crossterm::crossterm_terminal::screen::{AlternateScreen, ToMainScreen, ToAlternateScreen};
-use crossterm::crossterm_terminal::IntoRawMode;
+mod terminal;
+use terminal::alternate_screen;
use crossterm::Context;
+use std::io::{Write, stdout};
-
-use std::{time, thread};
+use crossterm::cursor;
fn main() {
- let mut context = Context::new();
- let mut screen = stdout();
- write!(screen, "{}", ToAlternateScreen);
- write!(screen, "Welcome to the alternate screen.\n\nPlease wait patiently until we arrive back at the main screen in a about three seconds.").unwrap();
- //screen.flush().unwrap();
+ alternate_screen::manually_switch_to_alternate_screen();
+// cursor::cursor().goto(10,10).print("@");
- thread::sleep(time::Duration::from_secs(3));
}
\ No newline at end of file
diff --git a/examples/color/mod.rs b/examples/color/mod.rs
index e7aaf64..0ee49a6 100644
--- a/examples/color/mod.rs
+++ b/examples/color/mod.rs
@@ -4,7 +4,7 @@
extern crate crossterm;
-use self::crossterm::crossterm_style::{paint, Color};
+use self::crossterm::style::{paint, Color};
/// print some red font | demonstration.
pub fn paint_foreground()
@@ -120,14 +120,13 @@ pub fn print_font_with_attributes()
}
/// Print all supported rgb colors | demonstration.
-#[cfg(unix)]#[cfg(unix)]
+#[cfg(unix)]
pub fn print_supported_colors()
{
- let count = crossterm::crossterm_style::color().get_available_color_count().unwrap();
+ let count = crossterm::style::color().get_available_color_count().unwrap();
for i in 0..count
{
println!("{}", paint(format!("Color: {}",i)).with(Color::AnsiValue(i as u8)));
-
}
}
\ No newline at end of file
diff --git a/examples/cursor/mod.rs b/examples/cursor/mod.rs
index 171e507..9e0f949 100644
--- a/examples/cursor/mod.rs
+++ b/examples/cursor/mod.rs
@@ -4,7 +4,7 @@
extern crate crossterm;
-use self::crossterm::crossterm_cursor::{cursor, TerminalCursor};
+use self::crossterm::cursor::{cursor, TerminalCursor};
/// Set the cursor to position X: 10, Y: 5 in the terminal.
pub fn goto()
diff --git a/examples/terminal/alternate_screen.rs b/examples/terminal/alternate_screen.rs
new file mode 100644
index 0000000..f15d274
--- /dev/null
+++ b/examples/terminal/alternate_screen.rs
@@ -0,0 +1,70 @@
+extern crate crossterm;
+
+use crossterm::terminal::screen::{AlternateScreen, ToAlternateScreen, ToMainScreen};
+use crossterm::cursor::cursor;
+use crossterm::terminal::{self, ClearType};
+
+use std::io::{Write, stdout};
+use std::{time, thread};
+
+fn print_wait_screen(screen: &mut Write)
+{
+ terminal::terminal().clear(ClearType::All);
+ write!(screen,
+ "Welcome to the wait screen.\n\
+ Please wait a few seconds until we arrive back at the main screen.\n\
+ Seconds to Go: "
+ );
+
+ let mut counter = 5;
+ // get cursor instance
+ let mut cursor = cursor();
+
+ // loop until the counter hits 0
+ loop
+ {
+ // 1 second delay
+ thread::sleep(time::Duration::from_secs(1));
+ // decrement counter
+ counter -= 1;
+
+ // print the current counter at the line of `Seconds to Go: {counter}`
+ cursor.goto(15,2).print(counter);
+
+ if counter <= 0
+ {
+ break;
+ }
+ }
+}
+
+pub fn with_alternate_screen_instance()
+{
+ // create scope. If this scope ends the screen will be switched back to mainscreen.
+ // becouse `AlternateScreen` switches back to main screen when switching back.
+ {
+ // create new alternate screen instance and switch to the alternate screen.
+ let mut screen = AlternateScreen::from(stdout());
+
+ // Print the wait screen.
+ print_wait_screen(&mut screen);
+ }
+
+ println!("Whe are back at the main screen");
+}
+
+pub fn manually_switch_to_alternate_screen()
+{
+ // You can switch to alternate screen manually but if you forget to switch back your terminal may cause some undefined behavior.
+
+ let mut screen = stdout();
+
+ // switch to alternate screeen
+ write!(screen, "{}", ToAlternateScreen);
+ // load wait screen
+ print_wait_screen(&mut screen);
+ // switch back
+ write!(screen,"{}", ToMainScreen);
+ println!("Whe are back at the main screen");
+
+}
\ No newline at end of file
diff --git a/examples/terminal/mod.rs b/examples/terminal/mod.rs
index 8d50a81..bf3a23a 100644
--- a/examples/terminal/mod.rs
+++ b/examples/terminal/mod.rs
@@ -1,136 +1,3 @@
-//!
-//! Terminal Examples
-//!
-
-extern crate crossterm;
-
-use crossterm::crossterm_terminal::{ Terminal, ClearType, terminal};
-use crossterm::crossterm_cursor;
-
-fn print_test_data()
-{
- for i in 0..100 {
- println!("Test data to test terminal: {}",i);
- }
-}
-
-/// Clear all lines in terminal | demonstration
-pub fn clear_all_lines()
-{
- // Get terminal
- let mut terminal = terminal();
-
- print_test_data();
-
- // Clear all lines in terminal;
- terminal.clear(ClearType::All);
-}
-
-/// Clear all lines from cursor position X:4, Y:4 down | demonstration
-pub fn clear_from_cursor_down()
-{
- // Get terminal
- let mut terminal = terminal();
-
- print_test_data();
-
- // Set terminal cursor position (see example for more info).
- crossterm_cursor::cursor().goto(4,8);
-
- // Clear all cells from current cursor position down.
- terminal.clear(ClearType::FromCursorDown);
-}
-
-/// Clear all lines from cursor position X:4, Y:4 up | demonstration
-pub fn clear_from_cursor_up()
-{
- // Get terminal
- let mut terminal = terminal();
-
- print_test_data();
-
- // Set terminal cursor position (see example for more info).
- crossterm_cursor::cursor().goto(4,4);
-
- // Clear all cells from current cursor position down.
- terminal.clear(ClearType::FromCursorUp);
-}
-
-/// Clear all lines from cursor position X:4, Y:4 up | demonstration
-pub fn clear_current_line()
-{
- // Get terminal
- let mut terminal = terminal();
-
- print_test_data();
-
- // Set terminal cursor position (see example for more info).
- crossterm_cursor::cursor().goto(4,4);
-
- // Clear current line cells.
- terminal.clear(ClearType::CurrentLine);
-}
-
-/// Clear all lines from cursor position X:4, Y:7 up | demonstration
-pub fn clear_until_new_line()
-{
- // Get terminal
- let mut terminal = terminal();
-
- print_test_data();
-
- // Set terminal cursor position (see example for more info).
- crossterm_cursor::cursor().goto(4,20);
-
- // Clear all the cells until next line.
- terminal.clear(ClearType::UntilNewLine);
-}
-
-/// Print the the current terminal size | demonstration.
-pub fn print_terminal_size()
-{
- // Get terminal
- let mut terminal = terminal();
- // Get terminal size
- let terminal_size = terminal.terminal_size();
- // Print results
- print!("X: {}, y: {}", terminal_size.0, terminal_size.1);
-}
-
-/// Set the terminal size to width 10, height: 10 | demonstration.
-pub fn set_terminal_size()
-{
- let mut terminal = terminal();
-
- terminal.set_size(10,10);
-}
-
-/// Scroll down 10 lines | demonstration.
-pub fn scroll_down()
-{
- print_test_data();
- // Get terminal
- let mut terminal = terminal();
- // Scroll down 10 lines.
- terminal.scroll_down(10);
-}
-
-/// Scroll down 10 lines | demonstration.
-pub fn scroll_up()
-{
- print_test_data();
-
- // Get terminal
- let mut terminal = terminal();
- // Scroll up 10 lines.
- terminal.scroll_up(10);
-}
-
-/// Resize the terminal to X: 10, Y: 10 | demonstration.
-pub fn resize_terminal()
-{
- // Get terminal
- let mut terminal = terminal();
- // Get terminal size
- terminal.set_size(10,10);
-}
+pub mod alternate_screen;
+pub mod raw_mode;
+pub mod terminal;
\ No newline at end of file
diff --git a/examples/terminal/raw_mode.rs b/examples/terminal/raw_mode.rs
new file mode 100644
index 0000000..e69de29
diff --git a/examples/terminal/terminal.rs b/examples/terminal/terminal.rs
new file mode 100644
index 0000000..6c7df0a
--- /dev/null
+++ b/examples/terminal/terminal.rs
@@ -0,0 +1,136 @@
+//!
+//! Terminal Examples
+//!
+
+extern crate crossterm;
+
+use crossterm::terminal::{ Terminal, ClearType, terminal};
+use crossterm::cursor;
+
+fn print_test_data()
+{
+ for i in 0..100 {
+ println!("Test data to test terminal: {}",i);
+ }
+}
+
+/// Clear all lines in terminal | demonstration
+pub fn clear_all_lines()
+{
+ // Get terminal
+ let mut terminal = terminal();
+
+ print_test_data();
+
+ // Clear all lines in terminal;
+ terminal.clear(ClearType::All);
+}
+
+/// Clear all lines from cursor position X:4, Y:4 down | demonstration
+pub fn clear_from_cursor_down()
+{
+ // Get terminal
+ let mut terminal = terminal();
+
+ print_test_data();
+
+ // Set terminal cursor position (see example for more info).
+ cursor::cursor().goto(4,8);
+
+ // Clear all cells from current cursor position down.
+ terminal.clear(ClearType::FromCursorDown);
+}
+
+/// Clear all lines from cursor position X:4, Y:4 up | demonstration
+pub fn clear_from_cursor_up()
+{
+ // Get terminal
+ let mut terminal = terminal();
+
+ print_test_data();
+
+ // Set terminal cursor position (see example for more info).
+ cursor::cursor().goto(4,4);
+
+ // Clear all cells from current cursor position down.
+ terminal.clear(ClearType::FromCursorUp);
+}
+
+/// Clear all lines from cursor position X:4, Y:4 up | demonstration
+pub fn clear_current_line()
+{
+ // Get terminal
+ let mut terminal = terminal();
+
+ print_test_data();
+
+ // Set terminal cursor position (see example for more info).
+ cursor::cursor().goto(4,4);
+
+ // Clear current line cells.
+ terminal.clear(ClearType::CurrentLine);
+}
+
+/// Clear all lines from cursor position X:4, Y:7 up | demonstration
+pub fn clear_until_new_line()
+{
+ // Get terminal
+ let mut terminal = terminal();
+
+ print_test_data();
+
+ // Set terminal cursor position (see example for more info).
+ cursor::cursor().goto(4,20);
+
+ // Clear all the cells until next line.
+ terminal.clear(ClearType::UntilNewLine);
+}
+
+/// Print the the current terminal size | demonstration.
+pub fn print_terminal_size()
+{
+ // Get terminal
+ let mut terminal = terminal();
+ // Get terminal size
+ let terminal_size = terminal.terminal_size();
+ // Print results
+ print!("X: {}, y: {}", terminal_size.0, terminal_size.1);
+}
+
+/// Set the terminal size to width 10, height: 10 | demonstration.
+pub fn set_terminal_size()
+{
+ let mut terminal = terminal();
+
+ terminal.set_size(10,10);
+}
+
+/// Scroll down 10 lines | demonstration.
+pub fn scroll_down()
+{
+ print_test_data();
+ // Get terminal
+ let mut terminal = terminal();
+ // Scroll down 10 lines.
+ terminal.scroll_down(10);
+}
+
+/// Scroll down 10 lines | demonstration.
+pub fn scroll_up()
+{
+ print_test_data();
+
+ // Get terminal
+ let mut terminal = terminal();
+ // Scroll up 10 lines.
+ terminal.scroll_up(10);
+}
+
+/// Resize the terminal to X: 10, Y: 10 | demonstration.
+pub fn resize_terminal()
+{
+ // Get terminal
+ let mut terminal = terminal();
+ // Get terminal size
+ terminal.set_size(10,10);
+}
diff --git a/src/crossterm_state/commands/mod.rs b/src/crossterm_state/commands/mod.rs
deleted file mode 100644
index 00921f4..0000000
--- a/src/crossterm_state/commands/mod.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-use rand;
-
-#[cfg(unix)]
-pub mod unix_command;
-#[cfg(windows)]
-pub mod win_commands;
-
-pub mod shared_commands;
-
-#[cfg(unix)]
-pub use self::unix_command::*;
-
-#[cfg(windows)]
-pub use self::win_commands::*;
-
-use super::Context;
-
-pub enum CommandType
-{
- Unix,
- Windows,
-}
-
-pub trait ICommand
-{
- fn new() -> Box where Self: Sized;
- fn execute(&mut self) -> bool;
- fn undo(&mut self) -> bool;
-}
-
-pub trait IContextCommand
-{
- fn new(context: &mut Context) -> (Box, i16) where Self: Sized;
- fn execute(&mut self) -> bool;
- fn undo(&mut self) -> bool;
-}
-
-
-fn generate_key() -> i16 {
-// let mut rng = rand::thread_rng();
-// if rng.gen() { // random bool
-// println!("i32: {}, u32: {}", rng.gen::(), rng.gen::())
-// }
- rand::random::()
-}
\ No newline at end of file
diff --git a/src/crossterm_state/context.rs b/src/crossterm_state/context.rs
deleted file mode 100644
index 222986b..0000000
--- a/src/crossterm_state/context.rs
+++ /dev/null
@@ -1,72 +0,0 @@
-use super::commands::{IContextCommand, ICommand};
-use std::ops::Drop;
-use std::collections::HashMap;
-
-pub struct Context
-{
- changed_states: HashMap>,
-}
-
-impl Context
-{
- pub fn new() -> Context
- {
- Context { changed_states: HashMap::new() }
- }
-
- /// restore to default terminal state
- pub fn restore_changes(&mut self)
- {
-// println!("restore change");
- for (x, state) in self.changed_states.iter_mut()
- {
- state.undo();
-// println!("State is removed, total state");
- }
- }
-
- /// Register new changed state
- pub fn register_change(&mut self, change: Box, key: i16)
- {
-// println!("register change");
- if !self.changed_states.contains_key(&key)
- {
- self.changed_states.insert(key, change);
-// println!("State is registerd, total states: {}", self.changed_states.len());
- }
- }
-
- /// Undo state
- pub fn undo_state(&mut self, state_key: i16)
- {
-// println!("undo specific");
- if self.changed_states.contains_key(&state_key)
- {
- self.changed_states.remove(&state_key);
- }
- }
-}
-//
-//fn state_wrapper() -> Context {
-// // Initialize it to a null value
-// static mut SINGLETON: *const StateWrapper = 0 as *const StateWrapper;
-// static ONCE: Once = ONCE_INIT;
-//
-// unsafe {
-// ONCE.call_once(|| {
-// // Make it
-// let singleton = StateWrapper {
-// state: Arc::new(Mutex::new(State::new())),
-// };
-//
-// // Put it in the heap so it can outlive this call
-// SINGLETON = mem::transmute(Box::new(singleton));
-// });
-//
-// // Now we give out a copy of the data that is safe to use concurrently.
-// (*SINGLETON).clone()
-// }
-//}
-
-
-
diff --git a/src/crossterm_state/mod.rs b/src/crossterm_state/mod.rs
deleted file mode 100644
index f883952..0000000
--- a/src/crossterm_state/mod.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-mod context;
-pub mod commands;
-
-pub use self::context::{Context};
\ No newline at end of file
diff --git a/src/crossterm_style/styles/mod.rs b/src/crossterm_style/styles/mod.rs
deleted file mode 100644
index edefd52..0000000
--- a/src/crossterm_style/styles/mod.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub mod objectstyle;
-pub mod styledobject;
diff --git a/src/crossterm_terminal/raw_terminal.rs b/src/crossterm_terminal/raw_terminal.rs
deleted file mode 100644
index ee43c0a..0000000
--- a/src/crossterm_terminal/raw_terminal.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-#[cfg(not(windows))]
-use crossterm_state::commands::unix_command::EnableRawModeCommand;
-#[cfg(windows)]
-use crossterm_state::commands::win_commands::EnableRawModeCommand;
-
-use { Construct, Context };
-use crossterm_state::commands::{ICommand, IContextCommand};
-
-use std::io::{ self, Write};
-
-
-pub struct RawTerminal<'a, W: Write>
-{
- output: W,
- key: i16,
- context: &'a mut Context
-}
-
-impl<'a, W: Write> Drop for RawTerminal<'a,W> {
- fn drop(&mut self) {
- self.context.undo_state(self.key);
- }
-}
-
-pub trait IntoRawMode: Write + Sized
-{
- fn into_raw_mode<'a>(self, context: &'a mut Context) -> io::Result>;
-}
-
-impl IntoRawMode for W
-{
- fn into_raw_mode<'a>(self, context: &'a mut Context) -> io::Result>
- {
- let (mut command, key) = EnableRawModeCommand::new(context);
- let success = command.execute();
-
- if success
- {
- Ok(RawTerminal {output: self, key: key, context: context})
-
- }else { panic!("cannot move into raw mode") }
- }
-}
-
-impl<'a, W: Write> Write for RawTerminal<'a, W> {
- fn write(&mut self, buf: &[u8]) -> io::Result {
- self.output.write(buf)
- }
-
- fn flush(&mut self) -> io::Result<()> {
- self.output.flush()
- }
-}
\ No newline at end of file
diff --git a/src/crossterm_cursor/ansi_cursor.rs b/src/cursor/ansi_cursor.rs
similarity index 90%
rename from src/crossterm_cursor/ansi_cursor.rs
rename to src/cursor/ansi_cursor.rs
index b2979c3..b78ffda 100644
--- a/src/crossterm_cursor/ansi_cursor.rs
+++ b/src/cursor/ansi_cursor.rs
@@ -1,3 +1,6 @@
+//! This is an ANSI specific implementation for cursor related action.
+//! This module is used for windows 10 terminals and unix terminals by default.
+
use Construct;
use shared::functions;
use super::ITerminalCursor;
diff --git a/src/crossterm_cursor/cursor.rs b/src/cursor/cursor.rs
similarity index 80%
rename from src/crossterm_cursor/cursor.rs
rename to src/cursor/cursor.rs
index 49c5764..cd1df89 100644
--- a/src/crossterm_cursor/cursor.rs
+++ b/src/cursor/cursor.rs
@@ -1,6 +1,8 @@
//! With this module you can perform actions that are cursor related.
//! Like changing and displaying the position of the cursor in terminal.
//!
+//! 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};
@@ -11,22 +13,19 @@ use std::ops::Drop;
/// Struct that stores an specific platform implementation for cursor related actions.
pub struct TerminalCursor {
terminal_cursor: Option>,
- context: Context
}
impl TerminalCursor
{
/// Create new cursor instance whereon cursor related actions can be performed.
pub fn new() -> TerminalCursor {
- let mut context = Context::new();
-
#[cfg(target_os = "windows")]
- let cursor = get_module::>(WinApiCursor::new(), AnsiCursor::new(), &mut context);
+ let cursor = functions::get_module::>(WinApiCursor::new(), AnsiCursor::new());
#[cfg(not(target_os = "windows"))]
let cursor = Some(AnsiCursor::new() as Box);
- TerminalCursor { terminal_cursor: cursor, context: context }
+ TerminalCursor { terminal_cursor: cursor }
}
/// Goto some position (x,y) in the terminal.
@@ -37,9 +36,9 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
///
- /// crossterm_cursor::cursor().goto(10,10);
+ /// cursor::cursor().goto(10,10);
///
/// ```
pub fn goto(&mut self, x: u16, y: u16) -> &mut TerminalCursor {
@@ -57,9 +56,9 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
///
- /// let pos = crossterm_cursor::cursor().pos();
+ /// let pos = cursor::cursor().pos();
/// println!("{:?}", pos);
///
/// ```
@@ -79,13 +78,13 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
///
/// // Move 1 time up
- /// crossterm_cursor::cursor().move_up(1);
+ /// cursor::cursor().move_up(1);
///
/// // Move 2 times up
- /// crossterm_cursor::cursor().move_up(2);
+ /// cursor::cursor().move_up(2);
///
/// ```
pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor {
@@ -103,14 +102,14 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
///
///
/// // move 1 time right
- /// crossterm_cursor::cursor().move_right(1);
+ /// cursor::cursor().move_right(1);
///
/// // move 2 times right
- /// crossterm_cursor::cursor().move_right(2);
+ /// cursor::cursor().move_right(2);
///
/// ```
pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor {
@@ -128,13 +127,13 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
///
/// // move 1 time down
- /// crossterm_cursor::cursor().move_down(1);
+ /// cursor::cursor().move_down(1);
///
/// // move 2 times down
- /// crossterm_cursor::cursor().move_down(2);
+ /// cursor::cursor().move_down(2);
///
/// ```
pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor {
@@ -152,13 +151,13 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
- ///
+ /// use self::crossterm::cursor;
+ ///
/// // move 1 time left
- /// crossterm_cursor::cursor().move_left(1);
+ /// cursor::cursor().move_left(1);
///
/// // move 2 time left
- /// crossterm_cursor::cursor().move_left(2);
+ /// cursor::cursor().move_left(2);
///
/// ```
pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor {
@@ -185,17 +184,17 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor;
+ /// use self::crossterm::cursor;
/// use std;
/// use std::io::Write;
///
/// // of course we can just do this.
- /// crossterm_cursor::cursor().goto(10,10);
+ /// cursor::cursor().goto(10,10);
/// print!("@");
/// std::io::stdout().flush();
///
/// // but now we can chain the methods so it looks cleaner and it automatically flushes the buffer.
- /// crossterm_cursor::cursor()
+ /// cursor::cursor()
/// .goto(10,10)
/// .print("@");
///
@@ -219,9 +218,9 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor::cursor;
+ /// use self::crossterm::cursor;
///
- /// cursor().safe_position();
+ /// cursor::cursor().safe_position();
///
/// ```
pub fn save_position(&mut self)
@@ -241,7 +240,7 @@ impl TerminalCursor
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_cursor::cursor;
+ /// use self::crossterm::cursor::cursor;
///
/// cursor().reset_position();
///
@@ -254,14 +253,6 @@ impl TerminalCursor
}
}
-impl Drop for TerminalCursor
-{
- fn drop(&mut self)
- {
- self.context.restore_changes();
- }
-}
-
/// Get an TerminalCursor implementation whereon cursor related actions can be performed.
///
/// Check `/examples/cursor` in the libary for more spesific examples.
@@ -272,14 +263,14 @@ impl Drop for TerminalCursor
///
/// extern crate crossterm;
///
-/// use self::crossterm::crossterm_cursor;
+/// use self::crossterm::cursor;
///
/// // Get cursor and goto pos X: 5, Y: 10
-/// let mut cursor = crossterm_cursor::cursor();
+/// let mut cursor = cursor::cursor();
/// cursor.goto(5,10);
///
/// //Or you can do it in one line.
-/// crossterm_cursor::cursor().goto(5,10);
+/// cursor::cursor().goto(5,10);
///
/// ```
pub fn cursor() -> Box {
diff --git a/src/crossterm_cursor/mod.rs b/src/cursor/mod.rs
similarity index 64%
rename from src/crossterm_cursor/mod.rs
rename to src/cursor/mod.rs
index e332799..e52a9cd 100644
--- a/src/crossterm_cursor/mod.rs
+++ b/src/cursor/mod.rs
@@ -1,10 +1,10 @@
-//! This trait defines the actions that can be preformed with the termial cursor.
-//! This trait can be inplemented so that an concrete inplementation of the ITerminalCursor can forfill
+//! 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 for fill
//! the wishes to work on an specific platform.
//!
//! ## For example:
//!
-//! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
+//! This trait is implemented to work with WINAPI (Windows specific) and ANSI (Unix specific),
//! so that the cursor related actions can be preformed on both unix and windows systems.
//!
@@ -19,6 +19,14 @@ use self::ansi_cursor::AnsiCursor;
pub use self::cursor::{ cursor, TerminalCursor };
+///! 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.
+///!
+///! ## For example:
+///!
+///! This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
+///! so that cursor related actions can be preformed on both unix and windows systems.
pub trait ITerminalCursor {
/// Goto some location (x,y) in the terminal.
fn goto(&self, x: u16, y: u16);
diff --git a/src/crossterm_cursor/winapi_cursor.rs b/src/cursor/winapi_cursor.rs
similarity index 88%
rename from src/crossterm_cursor/winapi_cursor.rs
rename to src/cursor/winapi_cursor.rs
index 4acb15a..436ad06 100644
--- a/src/crossterm_cursor/winapi_cursor.rs
+++ b/src/cursor/winapi_cursor.rs
@@ -1,3 +1,6 @@
+//! This is an WINAPI specific implementation for cursor related action.
+//! This module is used for windows terminals that do not support ANSI escape codes.
+
use Construct;
use super::ITerminalCursor;
use kernel::windows_kernel::{kernel, cursor};
@@ -13,12 +16,10 @@ impl Construct for WinApiCursor {
impl ITerminalCursor for WinApiCursor {
- /// Set the current cursor position to X and Y
fn goto(&self, x: u16, y: u16) {
kernel::set_console_cursor_position(x as i16, y as i16);
}
- /// Get current cursor position (X,Y)
fn pos(&self) -> (u16, u16) {
cursor::pos()
}
diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs
index 84589de..cb60b57 100644
--- a/src/kernel/mod.rs
+++ b/src/kernel/mod.rs
@@ -1,3 +1,5 @@
+//! All platform specific (unsafe) code will be handled in this module.
+
#[cfg(unix)]
pub mod unix_kernel;
#[cfg(windows)]
diff --git a/src/kernel/unix_kernel/mod.rs b/src/kernel/unix_kernel/mod.rs
index 79479c3..b95c5d9 100644
--- a/src/kernel/unix_kernel/mod.rs
+++ b/src/kernel/unix_kernel/mod.rs
@@ -1,2 +1,4 @@
+//! This module contains all the specific `unix` code.
+
pub mod terminal;
diff --git a/src/kernel/unix_kernel/terminal.rs b/src/kernel/unix_kernel/terminal.rs
index 625fde2..97edbc4 100644
--- a/src/kernel/unix_kernel/terminal.rs
+++ b/src/kernel/unix_kernel/terminal.rs
@@ -1,13 +1,15 @@
+//! This module contains all `unix` specific terminal related logic.
+
use { libc, Context };
use termios::Termios;
pub use self::libc::{termios};
use self::libc::{STDOUT_FILENO, TIOCGWINSZ, c_ushort, ioctl, c_int};
-use crossterm_state::commands::{ NoncanonicalModeCommand, IContextCommand} ;
+use state::commands::{ NoncanonicalModeCommand, IContextCommand} ;
use std::{ io, mem };
use std::io::Error;
-/// A representation of the size of the current terminal
+/// A representation of the size of the current terminal.
#[repr(C)]
#[derive(Debug)]
pub struct UnixSize {
@@ -19,7 +21,7 @@ pub struct UnixSize {
y: c_ushort,
}
-/// Gets the current terminal size
+/// Get the current terminal size.
pub fn terminal_size() -> (u16,u16) {
// http://rosettacode.org/wiki/Terminal_control/Dimensions#Library:_BSD_libc
let us = UnixSize {
@@ -37,7 +39,7 @@ pub fn terminal_size() -> (u16,u16) {
}
}
-/// Get the current cursor position
+/// Get the current cursor position.
pub fn pos() -> (u16,u16)
{
use std::io::Error;
@@ -100,6 +102,7 @@ pub fn pos() -> (u16,u16)
}
}
+/// Set the terminal mode to the given mode.
pub fn set_terminal_mode(termios: &Termios) -> io::Result<()>
{
extern "C" {
@@ -108,6 +111,7 @@ pub fn set_terminal_mode(termios: &Termios) -> io::Result<()>
is_true(unsafe { tcsetattr(0, 0, termios) }).and(Ok(()))
}
+/// Transform the given mode into an raw mode (non-canonical) mode.
pub fn make_raw(termios: &mut Termios) {
extern "C" {
pub fn cfmakeraw(termptr: *mut Termios);
@@ -115,6 +119,7 @@ pub fn make_raw(termios: &mut Termios) {
unsafe { cfmakeraw(termios) }
}
+/// Get the current terminal mode.
pub fn get_terminal_mode() -> io::Result
{
extern "C" {
@@ -127,6 +132,7 @@ pub fn get_terminal_mode() -> io::Result
}
}
+/// Is the return value true?
fn is_true(value: i32) -> Result<(), Error>
{
match value
diff --git a/src/kernel/windows_kernel/ansi_support.rs b/src/kernel/windows_kernel/ansi_support.rs
index d49d115..47ab3ac 100644
--- a/src/kernel/windows_kernel/ansi_support.rs
+++ b/src/kernel/windows_kernel/ansi_support.rs
@@ -1,15 +1,17 @@
-use { Context, Contstruct };
-use crossterm_state::commands::IContextCommand;
+//! This module handles the enabling `ANSI escape codes` for windows terminals.
+
+use Context;
+use state::commands::ICommand;
static mut HAS_BEEN_TRYED_TO_ENABLE: bool = false;
static mut IS_ANSI_ON_WINDOWS_ENABLED: Option = None;
static mut DOES_WINDOWS_SUPPORT_ANSI: Option = None;
-/// Try enable ANSI escape codes and return the result.
-pub fn try_enable_ansi_support(context: &mut Context) -> bool
+/// Try enable `ANSI escape codes` and return the result.
+pub fn try_enable_ansi_support() -> bool
{
- use crossterm_state::commands::win_commands::EnableAnsiCommand;
- let (mut command, key) = EnableAnsiCommand::new(context);
+ use state::commands::win_commands::EnableAnsiCommand;
+ let mut command = EnableAnsiCommand::new();
let success = command.execute();
set_is_windows_ansi_supportable(success);
diff --git a/src/kernel/windows_kernel/cursor.rs b/src/kernel/windows_kernel/cursor.rs
index f3fbfa3..9f8c434 100644
--- a/src/kernel/windows_kernel/cursor.rs
+++ b/src/kernel/windows_kernel/cursor.rs
@@ -1,4 +1,6 @@
-use super::{ kernel, cursor };
+//! This module handles some logic for cursor interaction in the windows console.
+
+use super::kernel;
/// This stores the cursor pos, at program level. So it can be recalled later.
static mut SAVED_CURSOR_POS:(u16,u16) = (0,0);
diff --git a/src/kernel/windows_kernel/kernel.rs b/src/kernel/windows_kernel/kernel.rs
index 4343915..bfb4829 100644
--- a/src/kernel/windows_kernel/kernel.rs
+++ b/src/kernel/windows_kernel/kernel.rs
@@ -1,3 +1,5 @@
+//! This module is the core of all the `WINAPI` actions. All unsafe `WINAPI` function call are done here.
+
use winapi::um::winnt::HANDLE;
use winapi::um::winbase::{STD_OUTPUT_HANDLE, STD_INPUT_HANDLE };
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
diff --git a/src/kernel/windows_kernel/mod.rs b/src/kernel/windows_kernel/mod.rs
index 1ed2d77..2d73681 100644
--- a/src/kernel/windows_kernel/mod.rs
+++ b/src/kernel/windows_kernel/mod.rs
@@ -1,3 +1,5 @@
+//! This module contains the `windows` specific (unsafe) logic.
+
pub mod kernel;
pub mod cursor;
pub mod terminal;
diff --git a/src/lib.rs b/src/lib.rs
index a86a414..45658d0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,14 +1,19 @@
+//! Crossterm provides the same core functionalities for both windows and unix systems.
+//! Crossterm aims to be simple and easy to call in code.
+//! True the simplicity of Crossterm you do not have to worry about the platform your working with.
+//! You can just call the action you want to preform and under water it will check what to do based on the current platform.
+
#[macro_use]
mod shared;
mod kernel;
-mod crossterm_state;
+mod state;
-pub mod crossterm_cursor;
-pub mod crossterm_style;
-pub mod crossterm_terminal;
+pub mod cursor;
+pub mod style;
+pub mod terminal;
use shared::traits::{Construct};
-pub use crossterm_state::{ Context};
+pub use state::{ Context};
#[cfg(windows)]
extern crate winapi;
@@ -17,15 +22,4 @@ extern crate libc;
#[cfg(unix)]
extern crate termios;
-extern crate rand;
-
-
-// private mod
-//
-// public mod
-//
-// own usings
-//
-// std usings
-//
-// extern crate
\ No newline at end of file
+extern crate rand;
\ No newline at end of file
diff --git a/src/shared/functions.rs b/src/shared/functions.rs
index 26edb7d..31755aa 100644
--- a/src/shared/functions.rs
+++ b/src/shared/functions.rs
@@ -1,6 +1,6 @@
-//! Some actions need to preformed platform independently.
-//!
-use {Context, Construct};
+//! Some actions need to preformed platform independently since they can not be solved `ANSI escape codes`.
+
+use {Context};
#[cfg(windows)]
use kernel::windows_kernel::terminal::terminal_size;
@@ -12,20 +12,21 @@ use kernel::windows_kernel::cursor::pos;
#[cfg(unix)]
use kernel::unix_kernel::terminal::pos;
-
+/// Get the terminal size based on the current platform.
pub fn get_terminal_size() -> (u16, u16)
{
terminal_size()
}
+/// Get the cursor position based on the current platform.
pub fn get_cursor_position() -> (u16,u16)
{
pos()
}
#[cfg(windows)]
-/// Get the module specific implementation based on the current platform
-pub fn get_module(winapi_impl: T, unix_impl: T, context: &mut Context) -> Option
+/// Get an module specific implementation based on the current platform.
+pub fn get_module(winapi_impl: T, unix_impl: T) -> Option
{
let mut term: Option = None;
let mut does_support = true;
@@ -35,9 +36,9 @@ pub fn get_module(winapi_impl: T, unix_impl: T, context: &mut Context) -> Opt
use kernel::windows_kernel::ansi_support::try_enable_ansi_support;
// Try to enable ansi on windows if not than use WINAPI.
- #[cfg(windows)]
- does_support = try_enable_ansi_support(context);
+ does_support = try_enable_ansi_support();
+// println!("does support = {}", does_support);
if !does_support
{
term = Some(winapi_impl);
diff --git a/src/shared/mod.rs b/src/shared/mod.rs
index e9ee529..0a69324 100644
--- a/src/shared/mod.rs
+++ b/src/shared/mod.rs
@@ -1,3 +1,5 @@
+//! This module contains some code that can be used for all module in this library.
+
#[macro_use]
pub mod macros;
pub mod traits;
diff --git a/src/state/commands/mod.rs b/src/state/commands/mod.rs
new file mode 100644
index 0000000..a72ef73
--- /dev/null
+++ b/src/state/commands/mod.rs
@@ -0,0 +1,50 @@
+//! In this module I make use of the command pattern to wrap state changes.
+//!
+//! The `command pattern` is an OOP concept but what it does is very handy.
+//! Shortly said what this pattern can do is having an command (struct) like `EnableRawModeCommand` this command has two methods one to `execute` that command and one to `undo`.
+//! Every time you preform some action you can push it into an list and at the end when you want to revert all the commands you have executed than you can loop true that loop true that list and `undo` the actions.
+//!
+//! So where do whe use the `Commands` for? This is so that we can push all or terminal state changes into list.
+//! When we do not need those changes we can revert all the changes by looping true the list and undo all the action.
+//!
+//! See the `Context` struct where we store the commands for more info.
+
+use rand;
+
+#[cfg(unix)]
+pub mod unix_command;
+#[cfg(windows)]
+pub mod win_commands;
+
+pub mod shared_commands;
+
+#[cfg(unix)]
+pub use self::unix_command::*;
+
+#[cfg(windows)]
+pub use self::win_commands::*;
+
+use super::Context;
+
+/// This command can be used for simple commands witch just have an `undo()` and an `execute()`
+pub trait ICommand
+{
+ fn new() -> Box where Self: Sized;
+ fn execute(&mut self) -> bool;
+ fn undo(&mut self) -> bool;
+}
+
+/// This command is used for complex commands whits change the terminal state.
+/// By passing an `Context` instance this command will register it self to notify the terminal state change.
+pub trait IContextCommand
+{
+ fn new(context: &mut Context) -> (Box, i16) where Self: Sized;
+ fn execute(&mut self) -> bool;
+ fn undo(&mut self) -> bool;
+}
+
+/// This generates an random key for the `ContextCommand`.
+/// So that we can identify the `ContextCommand` in an list of commands.
+fn generate_key() -> i16 {
+ rand::random::()
+}
\ No newline at end of file
diff --git a/src/crossterm_state/commands/shared_commands.rs b/src/state/commands/shared_commands.rs
similarity index 83%
rename from src/crossterm_state/commands/shared_commands.rs
rename to src/state/commands/shared_commands.rs
index 5b4f451..3f0ec89 100644
--- a/src/crossterm_state/commands/shared_commands.rs
+++ b/src/state/commands/shared_commands.rs
@@ -1,7 +1,10 @@
+//! This module contains the commands that can be used for both unix and windows systems.
+
use super::ICommand;
use std::io;
use std::io::Write;
+/// This command is used for switching to alternate screen and back to main screen.
#[derive(Clone, Copy)]
pub struct ToAlternateScreenBufferCommand;
diff --git a/src/crossterm_state/commands/unix_command.rs b/src/state/commands/unix_command.rs
similarity index 93%
rename from src/crossterm_state/commands/unix_command.rs
rename to src/state/commands/unix_command.rs
index 0ba355c..903f07b 100644
--- a/src/crossterm_state/commands/unix_command.rs
+++ b/src/state/commands/unix_command.rs
@@ -1,10 +1,13 @@
-use crossterm_state::{Context};
+//! This module contains the commands that can be used for unix systems.
+
+use Context;
use super::IContextCommand;
use kernel::unix_kernel::terminal;
use termios::{Termios, tcsetattr, TCSAFLUSH, ICANON, ECHO, CREAD};
const FD_STDIN: ::std::os::unix::io::RawFd = 1;
+/// This command is used for switching to NoncanonicalMode.
#[derive(Clone, Copy)]
pub struct NoncanonicalModeCommand
{
@@ -64,6 +67,7 @@ impl IContextCommand for NoncanonicalModeCommand
}
}
+/// This command is used for enabling and disabling raw mode for the terminal.
#[derive(Clone, Copy)]
pub struct EnableRawModeCommand
{
diff --git a/src/crossterm_state/commands/win_commands.rs b/src/state/commands/win_commands.rs
similarity index 90%
rename from src/crossterm_state/commands/win_commands.rs
rename to src/state/commands/win_commands.rs
index 7c62f28..0aaa080 100644
--- a/src/crossterm_state/commands/win_commands.rs
+++ b/src/state/commands/win_commands.rs
@@ -1,29 +1,29 @@
+//! This module contains the commands that can be used for windows systems.
+
use super::{ICommand, IContextCommand};
use super::super::Context;
use kernel::windows_kernel::{kernel, ansi_support};
-use winapi::um::winnt::{HANDLE};
use winapi::shared::minwindef::DWORD;
use winapi::um::wincon;
use winapi::um::wincon::{ENABLE_VIRTUAL_TERMINAL_PROCESSING ,SMALL_RECT, COORD, CHAR_INFO};
use std::mem;
-use std::fmt::Write;
-/// check https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences for more info.
+
+/// 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.
#[derive(Clone, Copy)]
pub struct EnableAnsiCommand
{
mask: DWORD,
- key: i16
}
-impl IContextCommand for EnableAnsiCommand
+impl ICommand for EnableAnsiCommand
{
- fn new(context: &mut Context) -> (Box, i16) {
+ fn new() -> Box {
// println!("new EnableRawModeCommand winapi");
let key = super::generate_key();
- let command = EnableAnsiCommand { mask: ENABLE_VIRTUAL_TERMINAL_PROCESSING, key: key };
- context.register_change(Box::from(command), key);
- (Box::from(command),key)
+ let command = EnableAnsiCommand { mask: ENABLE_VIRTUAL_TERMINAL_PROCESSING };
+ Box::from(command)
}
fn execute(&mut self) -> bool
@@ -80,6 +80,8 @@ impl IContextCommand for EnableAnsiCommand
}
}
+/// This command is used for enabling and disabling raw mode for windows systems.
+/// For more info check: https://docs.microsoft.com/en-us/windows/console/high-level-console-modes.
#[derive(Clone, Copy)]
pub struct EnableRawModeCommand
{
@@ -144,6 +146,7 @@ impl IContextCommand for EnableRawModeCommand
}
}
+/// This command is used for switching to alternate screen and back to main screen.
/// check https://docs.microsoft.com/en-us/windows/console/reading-and-writing-blocks-of-characters-and-attributes for more info
#[derive(Clone, Copy)]
pub struct ToAlternateScreenBufferCommand;
diff --git a/src/state/context.rs b/src/state/context.rs
new file mode 100644
index 0000000..dcd6dff
--- /dev/null
+++ b/src/state/context.rs
@@ -0,0 +1,51 @@
+//! This module is used for registering, storing an restoring the terminal state changes.
+
+use std::ops::Drop;
+use std::collections::HashMap;
+use super::commands::IContextCommand;
+
+/// Struct that stores the changed states of the terminal.
+pub struct Context
+{
+ changed_states: HashMap) >,
+}
+
+impl Context
+{
+ /// Create new Context where the terminals states can be handled.
+ pub fn new() -> Context
+ {
+ println!("Context has been created");
+ Context { changed_states: HashMap::new() }
+ }
+
+ /// Restore all changes that are made to the terminal.
+ pub fn restore_changes(&mut self)
+ {
+ for (x, state) in self.changed_states.iter_mut()
+ {
+ state.undo();
+ }
+ }
+
+ /// Register new changed state with the given key.
+ pub fn register_change(&mut self, change: Box, key: i16)
+ {
+ if !self.changed_states.contains_key(&key)
+ {
+ self.changed_states.insert(key, change);
+ }
+ }
+
+ /// Undo an specific state by the given state key.
+ pub fn undo_state(&mut self, state_key: i16)
+ {
+ if self.changed_states.contains_key(&state_key)
+ {
+ self.changed_states.remove(&state_key);
+ }
+ }
+}
+
+
+
diff --git a/src/state/mod.rs b/src/state/mod.rs
new file mode 100644
index 0000000..2c4cc7d
--- /dev/null
+++ b/src/state/mod.rs
@@ -0,0 +1,9 @@
+//! This module is used for managing the state changes of the terminal.
+//!
+//! If `crossterm` changes some core state of the terminal like: enabling ANSI or enabling raw mode it should be reverted when the current process ends.
+//! It would be a little lame to let the terminal in raw mode after the the current process ends for the user of this library.
+
+mod context;
+pub mod commands;
+
+pub use self::context::{Context};
\ No newline at end of file
diff --git a/src/crossterm_style/color/ansi_color.rs b/src/style/color/ansi_color.rs
similarity index 93%
rename from src/crossterm_style/color/ansi_color.rs
rename to src/style/color/ansi_color.rs
index d7e68d6..a372b39 100644
--- a/src/crossterm_style/color/ansi_color.rs
+++ b/src/style/color/ansi_color.rs
@@ -1,3 +1,6 @@
+//! 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;
use super::ITerminalColor;
use super::super::{Color, ColorType};
diff --git a/src/crossterm_style/color/color.rs b/src/style/color/color.rs
similarity index 86%
rename from src/crossterm_style/color/color.rs
rename to src/style/color/color.rs
index 90d2252..45ffc2f 100644
--- a/src/crossterm_style/color/color.rs
+++ b/src/style/color/color.rs
@@ -1,9 +1,10 @@
//! With this module you can perform actions that are color related.
-//! Like styling the font, foreground color and background color.
+//! Like styling the font, foreground color and background.
+
use super::*;
use shared::functions;
use { Construct, Context };
-use crossterm_style::{Color, ObjectStyle, StyledObject};
+use style::{Color, ObjectStyle, StyledObject};
use std::ops::Drop;
use std::{ fmt, io };
@@ -11,21 +12,18 @@ use std::{ fmt, io };
/// Struct that stores an specific platform implementation for color related actions.
pub struct TerminalColor {
terminal_color: Option>,
- context: Context
}
impl TerminalColor {
/// Create new instance whereon color related actions can be performed.
pub fn new() -> TerminalColor {
- let mut context = Context::new();
-
#[cfg(target_os = "windows")]
- let color = functions::get_module::>(WinApiColor::new(), AnsiColor::new(), &mut context);
+ let color = functions::get_module::>(WinApiColor::new(), AnsiColor::new());
#[cfg(not(target_os = "windows"))]
let color = Some(AnsiColor::new() as Box);
- TerminalColor { terminal_color: color, context: context}
+ TerminalColor { terminal_color: color }
}
/// Set the foreground color to the given color.
@@ -35,7 +33,7 @@ impl TerminalColor {
/// ```rust
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_style::{ color, Color};
+ /// use self::crossterm::style::{ color, Color};
///
/// // Get colored terminal instance
/// let mut colored_terminal = color();
@@ -60,7 +58,7 @@ impl TerminalColor {
///
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_style::{ color, Color};
+ /// use self::crossterm::style::{ color, Color};
///
/// // Get colored terminal instance
/// let mut colored_terminal = color();
@@ -83,7 +81,7 @@ impl TerminalColor {
/// ```rust
/// extern crate crossterm;
///
- /// use self::crossterm::crossterm_style::color;
+ /// use self::crossterm::style::color;
///
/// // Get colored terminal instance
/// let mut colored_terminal = color();
@@ -115,14 +113,6 @@ impl TerminalColor {
}
}
-impl Drop for TerminalColor
-{
- fn drop(&mut self)
- {
- self.context.restore_changes();
- }
-}
-
/// Get an TerminalColor implementation whereon color related actions can be performed.
///
/// # Example
@@ -130,7 +120,7 @@ impl Drop for TerminalColor
/// ```rust
/// extern crate crossterm;
///
-/// use self::crossterm::crossterm_style::{color, Color};
+/// use self::crossterm::style::{color, Color};
///
/// // Get colored terminal instance
/// let mut colored_terminal = color();
@@ -153,7 +143,7 @@ pub fn color() -> Box {
/// ```rust
/// extern crate crossterm;
///
-/// use self::crossterm::crossterm_style::{paint,Color};
+/// use self::crossterm::style::{paint,Color};
///
/// fn main()
/// {
diff --git a/src/crossterm_style/color/mod.rs b/src/style/color/mod.rs
similarity index 70%
rename from src/crossterm_style/color/mod.rs
rename to src/style/color/mod.rs
index 6a338b2..8ffcf36 100644
--- a/src/crossterm_style/color/mod.rs
+++ b/src/style/color/mod.rs
@@ -7,22 +7,18 @@ mod ansi_color;
#[cfg(target_os = "windows")]
use self::winapi_color::WinApiColor;
use self::ansi_color::AnsiColor;
+use super::{Color, ColorType};
-///!
-///! This trait defines the actions that can be preformed with the termial color.
-///! This trait can be inplemented so that an concrete inplementation of the ITerminalColor can forfill
+///! 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
///! the wishes to work on an specific platform.
///!
///! ## For example:
///!
-///! This trait is inplemented for winapi (Windows specific) and ansi (Unix specific),
-///! so that the color related actions can be preformed on both unix and windows systems.
-///!
-
-use super::{Color, ColorType};
-
+///! This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
+///! so that color related actions can be preformed on both unix and windows systems.
pub trait ITerminalColor {
- /// Set the forground color to the given color.
+ /// Set the foreground color to the given color.
fn set_fg(&self, fg_color: Color);
/// Set the background color to the given color.
fn set_bg(&self, fg_color: Color);
diff --git a/src/crossterm_style/color/winapi_color.rs b/src/style/color/winapi_color.rs
similarity index 93%
rename from src/crossterm_style/color/winapi_color.rs
rename to src/style/color/winapi_color.rs
index 6a4a466..46fa897 100644
--- a/src/crossterm_style/color/winapi_color.rs
+++ b/src/style/color/winapi_color.rs
@@ -18,10 +18,8 @@ impl Construct for WinApiColor {
}
}
-
impl ITerminalColor for WinApiColor {
- /// This will set the foreground color by the given winapi color.
fn set_fg(&self, fg_color: Color) {
let color_value = &self.color_value(fg_color, ColorType::Foreground);
@@ -34,7 +32,7 @@ impl ITerminalColor for WinApiColor {
let bg_color = attrs & 0x0070;
color = color_value.parse::().unwrap() | bg_color;
- // background intensity is a seperate value in attrs,
+ // background intensity is a separate value in attrs,
// wee need to check if this was applied to the current bg color.
if (attrs & wincon::BACKGROUND_INTENSITY as u16) != 0 {
color = color | wincon::BACKGROUND_INTENSITY as u16;
@@ -43,7 +41,6 @@ impl ITerminalColor for WinApiColor {
kernel::set_console_text_attribute(color);
}
- /// This will set the background color by the given winapi color value.
fn set_bg(&self, bg_color: Color) {
let color_value = &self.color_value(bg_color, ColorType::Background);
@@ -64,7 +61,6 @@ impl ITerminalColor for WinApiColor {
kernel::set_console_text_attribute(color);
}
- /// This will reset the colors to the given winapi color value.
fn reset(&self) {
kernel::set_console_text_attribute(self.original_console_color);
}
@@ -72,7 +68,7 @@ impl ITerminalColor for WinApiColor {
/// This will get the winapi color value from the Color and ColorType struct
fn color_value(&self, color: Color, color_type: ColorType) -> String {
- use crossterm_style::{Color, ColorType};
+ use style::{Color, ColorType};
let winapi_color: u16;
diff --git a/src/crossterm_style/mod.rs b/src/style/mod.rs
similarity index 93%
rename from src/crossterm_style/mod.rs
rename to src/style/mod.rs
index bd8d852..31fadd4 100644
--- a/src/crossterm_style/mod.rs
+++ b/src/style/mod.rs
@@ -1,3 +1,6 @@
+//! This module is used for styling the terminal text.
+//! Under styling we can think of coloring the font and applying attributes to it.
+
mod color;
mod styles;
diff --git a/src/style/styles/mod.rs b/src/style/styles/mod.rs
new file mode 100644
index 0000000..cd40b69
--- /dev/null
+++ b/src/style/styles/mod.rs
@@ -0,0 +1,4 @@
+//! This module contains the modules that are responsible for storing the styling displayable objects or simply set text.
+
+pub mod objectstyle;
+pub mod styledobject;
diff --git a/src/crossterm_style/styles/objectstyle.rs b/src/style/styles/objectstyle.rs
similarity index 92%
rename from src/crossterm_style/styles/objectstyle.rs
rename to src/style/styles/objectstyle.rs
index 2950826..3d6df81 100644
--- a/src/crossterm_style/styles/objectstyle.rs
+++ b/src/style/styles/objectstyle.rs
@@ -1,5 +1,7 @@
+//! This module contains the `object style` that can be applied to an `styled object`.
+
use std::fmt::Display;
-use crossterm_style::{Color, StyledObject};
+use style::{Color, StyledObject};
#[cfg(unix)]
use super::super::Attribute;
diff --git a/src/crossterm_style/styles/styledobject.rs b/src/style/styles/styledobject.rs
similarity index 92%
rename from src/crossterm_style/styles/styledobject.rs
rename to src/style/styles/styledobject.rs
index 426a2d6..11aab45 100644
--- a/src/crossterm_style/styles/styledobject.rs
+++ b/src/style/styles/styledobject.rs
@@ -1,12 +1,14 @@
-use std::{ fmt, self };
+//! This module contains the logic to style an object that contains some context witch can be styled.
+
+use std::{ self, fmt };
use std::io::Write;
#[cfg(unix)]
use super::super::Attribute;
-use crossterm_style::{Color, ObjectStyle};
+use style::{Color, ObjectStyle};
-/// Struct that contains both the style and the content wits will be styled.
+/// Struct that contains both the style and the content wits can be styled.
pub struct StyledObject {
pub object_style: ObjectStyle,
pub content: D,
@@ -19,7 +21,7 @@ impl StyledObject {
///
/// ```rust
/// extern crate crossterm;
- /// use self::crossterm::crossterm_style::{paint,Color};
+ /// use self::crossterm::style::{paint,Color};
///
/// // create an styled object with the foreground color red.
/// let styledobject = paint("I am colored red").with(Color::Red);
@@ -44,7 +46,7 @@ impl StyledObject {
///
/// ```rust
/// extern crate crossterm;
- /// use self::crossterm::crossterm_style::{paint,Color};
+ /// use self::crossterm::style::{paint,Color};
///
/// // create an styled object with the background color red.
/// let styledobject = paint("I am colored red").on(Color::Red);
@@ -70,7 +72,7 @@ impl StyledObject {
/// ```rust
///
/// extern crate crossterm;
- /// use self::crossterm::crossterm_style::{paint,Attribute};
+ /// use self::crossterm::style::{paint,Attribute};
///
/// println!("{}", paint("Bold").attr(Attribute::Bold));
///
diff --git a/src/crossterm_terminal/ansi_terminal.rs b/src/terminal/ansi_terminal.rs
similarity index 90%
rename from src/crossterm_terminal/ansi_terminal.rs
rename to src/terminal/ansi_terminal.rs
index a29cd0e..0b7b7b9 100644
--- a/src/crossterm_terminal/ansi_terminal.rs
+++ b/src/terminal/ansi_terminal.rs
@@ -1,3 +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 Construct;
use shared::functions;
use super::{ClearType, ITerminal};
diff --git a/src/crossterm_terminal/mod.rs b/src/terminal/mod.rs
similarity index 58%
rename from src/crossterm_terminal/mod.rs
rename to src/terminal/mod.rs
index db82e9f..f3a93eb 100644
--- a/src/crossterm_terminal/mod.rs
+++ b/src/terminal/mod.rs
@@ -1,4 +1,10 @@
-mod raw_terminal;
+//! Module that contains all the actions related to the terminal.
+//!
+//! We can think of:
+//! - alternate screen
+//! - raw mode
+//! - clearing resizing scrolling the terminal.
+
mod terminal;
#[cfg(target_os = "windows")]
@@ -6,13 +12,13 @@ mod winapi_terminal;
mod ansi_terminal;
pub mod screen;
+pub mod raw;
#[cfg(target_os = "windows")]
use self::winapi_terminal::WinApiTerminal;
use self::ansi_terminal::AnsiTerminal;
pub use self::terminal::{ Terminal, terminal};
-pub use self::raw_terminal::{RawTerminal, IntoRawMode};
/// Enum that can be used for the kind of clearing that can be done in the terminal.
pub enum ClearType {
@@ -23,7 +29,15 @@ pub enum ClearType {
UntilNewLine,
}
-pub trait ITerminal{
+///! This trait defines the actions that can be preformed with the terminal.
+///! This trait can be implemented so that an concrete implementation of the ITerminal can forfill
+///! the wishes to work on an specific platform.
+///!
+///! ## For example:
+///!
+///! This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
+///! so that cursor related actions can be preformed on both unix and windows systems.
+pub trait ITerminal {
/// Clear the current cursor by specifying the clear type
fn clear(&self, clear_type: ClearType);
/// Get the terminal size (x,y)
diff --git a/src/terminal/raw.rs b/src/terminal/raw.rs
new file mode 100644
index 0000000..48daba8
--- /dev/null
+++ b/src/terminal/raw.rs
@@ -0,0 +1,82 @@
+//! This module is used for enabling and disabling raw mode for the terminal.
+//!
+//! What exactly is raw state:
+//! - No line buffering.
+//! Normally the terminals uses line buffering. This means that the input will be send to the terminal line by line.
+//! With raw mode the input will be send one byte at a time.
+//! - Input
+//! All input has to be written manually by the programmer.
+//! - Characters
+//! The characters are not processed by the terminal driver, but are sent straight through.
+//! Special character have no meaning, like backspace will not be interpret as backspace but instead will be directly send to the terminal.
+//!
+//! With these modes you can easier design the terminal screen.
+//!
+//! # Example
+//!
+//! ```rust
+//! to be implemented
+//!
+//! ```
+
+#[cfg(not(windows))]
+use state::commands::unix_command::EnableRawModeCommand;
+#[cfg(windows)]
+use state::commands::win_commands::EnableRawModeCommand;
+
+use Context;
+use state::commands::IContextCommand;
+
+use std::io::{ self, Write};
+
+/// A wrapper for the raw terminal state. Which can be used to write to.
+pub struct RawTerminal<'a, W: Write>
+{
+ output: W,
+ context : &'a mut Context
+}
+
+/// Trait withs contains a method for switching into raw mode.
+pub trait IntoRawMode: Write + Sized
+{
+ fn into_raw_mode<'a>(self, context: &'a mut Context) -> io::Result>;
+}
+
+impl IntoRawMode for W
+{
+ /// Switch to raw mode.
+ ///
+ /// Raw mode means that input (stdin) won't be printed it will instead have to be written manually by
+ /// the program. The input isn't canonicalised or line buffered (that is, you can
+ /// read from input(stdin) one byte of a time).
+ fn into_raw_mode<'a>(self, context: &'a mut Context) -> io::Result>
+ {
+ let (mut command, _) = EnableRawModeCommand::new(context);
+ let success = command.execute();
+
+ if success
+ {
+ Ok(RawTerminal { output: self, context: context})
+
+ }else { panic!("cannot move into raw mode") }
+ }
+}
+
+impl<'a, W: Write> Write for RawTerminal<'a, W> {
+ fn write(&mut self, buf: &[u8]) -> io::Result {
+ self.output.write(buf)
+ }
+
+ fn flush(&mut self) -> io::Result<()> {
+ self.output.flush()
+ }
+}
+
+/// If an instance of `RawTerminal` will be dropped all terminal changes that are made will be undone.
+impl <'a, W: Write> Drop for RawTerminal<'a, W>
+{
+ fn drop(&mut self)
+ {
+ self.context.restore_changes();
+ }
+}
\ No newline at end of file
diff --git a/src/crossterm_terminal/screen/mod.rs b/src/terminal/screen.rs
similarity index 60%
rename from src/crossterm_terminal/screen/mod.rs
rename to src/terminal/screen.rs
index 5ab9f94..ad6989b 100644
--- a/src/crossterm_terminal/screen/mod.rs
+++ b/src/terminal/screen.rs
@@ -1,23 +1,12 @@
+//! This module contains all the logic for switching between alternate screen and main screen.
+
use shared::functions;
-use { Context, Construct };
-use crossterm_state::commands::*;
+use Context;
+use state::commands::*;
use std::{ fmt, ops };
use std::io::{self, Write};
-/// let context = ScreenContext::new();
-/// ToMainScreen {}.execute(&mut context);
-/// ToAlternateScreen {}.execute(context);
-///
-///
-/// ToMainScreen {}.execute(&mut context);
-///
-/// context.to_main();
-/// let alternate_screen = context.to_alternate(stdout());
-///
-/// let alternate = AlternateScreen::from(stdout, context);
-/// ToMainScreen [} .execute(ScreenContext::new()))
-/// ToAlternateScreen {}. execute(ScreenContext::new());
pub struct ToMainScreen;
impl fmt::Display for ToMainScreen
@@ -28,7 +17,7 @@ impl fmt::Display for ToMainScreen
}
}
-/// Switch to the alternate screen buffer of the terminal.
+/// Struct that switches to alternate screen buffer on display.
pub struct ToAlternateScreen;
impl fmt::Display for ToAlternateScreen
@@ -39,13 +28,36 @@ impl fmt::Display for ToAlternateScreen
}
}
+/// Struct that can be used for writing to an alternate screen.
+///
+/// #Example
+///
+/// ```rust
+/// extern crate crossterm;
+/// use self::crossterm::terminal::screen;
+/// use std::{time, thread};
+/// ...
+///
+/// // Initialize and switch to the alternate screen from an std output handle.
+/// // Now you can write to this screen.
+/// let mut screen = screen::AlternateScreen::from(stdout());
+/// // Write some text to the alternate screen.
+/// write!(screen, "Welcome to the alternate screen. Wait 4 seconds to switch back").unwrap();
+/// thread::sleep(time::Duration::from_secs(4));
+/// // switch back to main screen.
+/// write!(screen, "{}", screen::ToMainScreen);
+/// write!(screen, "{}", "We are back again at the main screen");
+///
+/// ...
+///
+/// ```
pub struct AlternateScreen {
/// The output target.
output: W,
context: Context
}
-impl AlternateScreen< W> {
+impl AlternateScreen {
pub fn from(mut output: W) -> Self {
write!(output, "{}", ToAlternateScreen);
AlternateScreen { output: output, context: Context::new()}
@@ -84,12 +96,11 @@ impl Drop for AlternateScreen
}
}
+/// Get the alternate screen command to enable and disable alternate screen based on the current platform
fn get_to_alternate_screen_command() -> Box
{
- let mut context = Context::new();
-
#[cfg(target_os = "windows")]
- let command = functions::get_module::>(win_commands::ToAlternateScreenBufferCommand::new(), shared_commands::ToAlternateScreenBufferCommand::new(), &mut context).unwrap();
+ let command = functions::get_module::>(win_commands::ToAlternateScreenBufferCommand::new(), shared_commands::ToAlternateScreenBufferCommand::new()).unwrap();
#[cfg(not(target_os = "windows"))]
let command = shared_commands::ToAlternateScreenBufferCommand::new();
diff --git a/src/crossterm_terminal/terminal.rs b/src/terminal/terminal.rs
similarity index 74%
rename from src/crossterm_terminal/terminal.rs
rename to src/terminal/terminal.rs
index bd00967..a32129f 100644
--- a/src/crossterm_terminal/terminal.rs
+++ b/src/terminal/terminal.rs
@@ -1,5 +1,6 @@
//! With this module you can perform actions that are terminal related.
//! Like clearing and scrolling in the terminal or getting the size of the terminal.
+
use super::*;
use shared::functions;
use {Construct, Context};
@@ -9,21 +10,18 @@ use std::ops::Drop;
/// Struct that stores an specific platform implementation for terminal related actions.
pub struct Terminal {
terminal: Option>,
- context: Context
}
impl Terminal {
/// Create new terminal instance whereon terminal related actions can be performed.
pub fn new() -> Terminal {
-
- let mut context = Context::new();
#[cfg(target_os = "windows")]
- let terminal = functions::get_module::>(WinApiTerminal::new(), AnsiTerminal::new(), &mut context);
+ let terminal = functions::get_module::>(WinApiTerminal::new(), AnsiTerminal::new());
#[cfg(not(target_os = "windows"))]
let terminal = Some(AnsiTerminal::new() as Box);
- Terminal { terminal: terminal, context: context }
+ Terminal { terminal: terminal }
}
/// Clear the current cursor by specifying the clear type
@@ -33,20 +31,20 @@ impl Terminal {
/// ```rust
///
/// extern crate crossterm;
- /// use crossterm::crossterm_terminal;
+ /// use crossterm::terminal;
///
- /// let mut term = crossterm_terminal::terminal();
+ /// let mut term = terminal::terminal();
///
/// // clear all cells in terminal.
- /// term.clear(crossterm_terminal::ClearType::All);
+ /// term.clear(terminal::ClearType::All);
/// // clear all cells from the cursor position downwards in terminal.
- /// term.clear(crossterm_terminal::ClearType::FromCursorDown);
+ /// term.clear(terminal::ClearType::FromCursorDown);
/// // clear all cells from the cursor position upwards in terminal.
- /// term.clear(crossterm_terminal::ClearType::FromCursorUp);
+ /// term.clear(terminal::ClearType::FromCursorUp);
/// // clear current line cells in terminal.
- /// term.clear(crossterm_terminal::ClearType::CurrentLine);
+ /// term.clear(terminal::ClearType::CurrentLine);
/// // clear all cells from cursor position until new line in terminal.
- /// term.clear(crossterm_terminal::ClearType::UntilNewLine);
+ /// term.clear(terminal::ClearType::UntilNewLine);
///
/// ```
pub fn clear(&mut self, clear_type: ClearType) {
@@ -62,10 +60,10 @@ impl Terminal {
/// ```rust
///
/// extern crate crossterm;
- /// use crossterm::crossterm_terminal;
+ /// use crossterm::terminal;
+ ///
+ /// let mut term = terminal::terminal();
///
- /// let mut term = crossterm_terminal::terminal();
- ///
/// let size = term.terminal_size();
/// println!("{:?}", size);
///
@@ -84,9 +82,9 @@ impl Terminal {
/// ```rust
///
/// extern crate crossterm;
- /// use crossterm::crossterm_terminal;
+ /// use crossterm::terminal;
///
- /// let mut term = crossterm_terminal::terminal();
+ /// let mut term = terminal::terminal();
///
/// // scroll up by 5 lines
/// let size = term.scroll_up(5);
@@ -105,9 +103,9 @@ impl Terminal {
/// ```rust
///
/// extern crate crossterm;
- /// use crossterm::crossterm_terminal;
+ /// use crossterm::terminal;
///
- /// let mut term = crossterm_terminal::terminal();
+ /// let mut term = terminal::terminal();
///
/// // scroll down by 5 lines
/// let size = term.scroll_down(5);
@@ -126,9 +124,9 @@ impl Terminal {
/// ```rust
///
/// extern crate crossterm;
- /// use crossterm::crossterm_terminal;
+ /// use crossterm::terminal;
///
- /// let mut term = crossterm_terminal::terminal();
+ /// let mut term = terminal::terminal();
///
/// // Set of the size to X: 10 and Y: 10
/// let size = term.set_size(10,10);
@@ -142,14 +140,6 @@ impl Terminal {
}
}
-impl Drop for Terminal
-{
- fn drop(&mut self)
- {
- self.context.restore_changes();
- }
-}
-
/// Get an Terminal implementation whereon terminal related actions can be performed.
///
/// Check `/examples/terminal` in the libary for more spesific examples.
@@ -159,9 +149,9 @@ impl Drop for Terminal
/// ```rust
///
/// extern crate crossterm;
-/// use crossterm::crossterm_terminal;
+/// use crossterm::terminal;
///
-/// let mut term = crossterm_terminal::terminal();
+/// let mut term = terminal::terminal();
///
/// // scroll down by 5 lines
/// let size = term.scroll_down(5);
diff --git a/src/crossterm_terminal/winapi_terminal.rs b/src/terminal/winapi_terminal.rs
similarity index 97%
rename from src/crossterm_terminal/winapi_terminal.rs
rename to src/terminal/winapi_terminal.rs
index 3f8420e..c4ffcb0 100644
--- a/src/crossterm_terminal/winapi_terminal.rs
+++ b/src/terminal/winapi_terminal.rs
@@ -1,6 +1,9 @@
+//! This is an `WINAPI` specific implementation for terminal related action.
+//! This module is used for windows 10 terminals and unix terminals by default.
+
use {Construct};
-use crossterm_cursor::cursor;
-use super::base_terminal::{ClearType, ITerminal};
+use cursor::cursor;
+use super::{ClearType, ITerminal};
use winapi::um::wincon::{SMALL_RECT, COORD, CONSOLE_SCREEN_BUFFER_INFO,};
use kernel::windows_kernel::{kernel, terminal};
@@ -14,7 +17,7 @@ impl Construct for WinApiTerminal {
}
impl ITerminal for WinApiTerminal {
- /// Clear the screen to the given cleartype.
+
fn clear(&self, clear_type: ClearType) {
let csbi = kernel::get_console_screen_buffer_info();
let pos = cursor().pos();
@@ -29,17 +32,14 @@ impl ITerminal for WinApiTerminal {
};
}
- /// Get the terminal size
fn terminal_size(&self) -> (u16, u16) {
terminal::terminal_size()
}
- /// Scroll up n` rows
fn scroll_up(&self, count: i16) {
// yet to be inplemented
}
- /// Scroll down `n` rows
fn scroll_down(&self, count: i16) {
let csbi = kernel::get_console_screen_buffer_info();
let mut srct_window;