Overall commend improvement

This commit is contained in:
TimonPost 2018-08-14 23:02:25 +02:00
parent 4005634086
commit bb39591150
14 changed files with 46 additions and 166 deletions

View File

@ -54,8 +54,6 @@ use self::crossterm::cursor::*;
use self::crossterm::terminal::*; use self::crossterm::terminal::*;
// this mudule is used for input related actions // this mudule is used for input related actions
use self::crossterm::terminal::*; use self::crossterm::terminal::*;
// this type could be used to access the above modules.
use self::crossterm::Crossterm;
``` ```
@ -131,7 +129,7 @@ let style2 = style("Some Red font on Yellow background").with(Color::Red).on(Col
let screen = Screen::default(); let screen = Screen::default();
/// ! The following code only works for unix based systems. /// !! The following code only works for unix based systems !!
// some attributes // some attributes
let normal = style("Normal text"); let normal = style("Normal text");
let bold = style("Bold text").bold(); let bold = style("Bold text").bold();

View File

@ -23,36 +23,31 @@ use common::commands::win_commands;
use write::Stdout; use write::Stdout;
/// This type could be used to access the `cursor, terminal, color, input, styling` module more easily. /// This type could be used to access the `cursor, terminal, color, input, styling` module more easily.
/// You need to pass a reference to the screen where on you want to perform the actions. /// You need to pass a reference to the screen where on you want to perform the actions to the `Crossterm` type.
/// ///
///
/// #Example
/// If you want to use the default screen you could do it like this: /// If you want to use the default screen you could do it like this:
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// ///
/// let crossterm = Crossterm::new(); /// let crossterm = Crossterm::new(&Screen::default());
/// let cursor = crossterm.cursor(&Screen::default()); /// let cursor = crossterm.cursor();
///
/// ``` /// ```
/// ///
/// If you want to perform actions on the `AlternateScreen` make sure to pass a refrence to the screen of the `AlternateScreen`. /// If you want to perform actions on the `AlternateScreen` make sure to pass a reference to the screen of the `AlternateScreen`.
/// ///
/// ``` /// ```
/// /// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// ///
/// let main_screen = Screen::default(); /// let main_screen = Screen::default();
/// ///
/// if let Ok(alternate_srceen) = main_screen.enable_alternate_modes(false) /// if let Ok(alternate_srceen) = main_screen.enable_alternate_modes(false)
/// { /// {
/// let crossterm = Crossterm::new(); /// let crossterm = Crossterm::new(&alternate_screen.screen);
/// let cursor = crossterm.cursor(&alternate_screen.screen); /// let cursor = crossterm.cursor();
/// } /// }
///
/// ``` /// ```
pub struct Crossterm { pub struct Crossterm {
stdout: Arc<Stdout> stdout: Arc<Stdout>
@ -64,85 +59,68 @@ impl<'crossterm> Crossterm {
Crossterm { stdout: screen.stdout.clone() } Crossterm { stdout: screen.stdout.clone() }
} }
/// Get an TerminalCursor implementation whereon cursor related actions can be performed. /// Get an `TerminalCursor` implementation whereon cursor related actions can be performed.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// ///
/// let crossterm = Crossterm::new(&Screen::default()); /// let crossterm = Crossterm::new(&Screen::default());
/// let cursor = crossterm.cursor(); /// let cursor = crossterm.cursor();
///
/// ``` /// ```
pub fn cursor(&self) -> cursor::TerminalCursor { pub fn cursor(&self) -> cursor::TerminalCursor {
cursor::TerminalCursor::new(&self.stdout) cursor::TerminalCursor::new(&self.stdout)
} }
/// Get an TerminalInput implementation whereon terminal related actions can be performed. /// Get an `TerminalInput` implementation whereon terminal related actions can be performed.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// use crossterm::terminal; /// use crossterm::terminal;
/// ///
/// let crossterm = Crossterm::new(&Screen::default()); /// let crossterm = Crossterm::new(&Screen::default());
/// let input = crossterm.input(); /// let input = crossterm.input();
///
/// ``` /// ```
pub fn input(&self) -> input::TerminalInput { pub fn input(&self) -> input::TerminalInput {
return input::TerminalInput::new(&self.stdout); return input::TerminalInput::new(&self.stdout);
} }
/// Get an Terminal implementation whereon terminal related actions can be performed. /// Get an `Terminal` implementation whereon terminal related actions can be performed.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// ///
/// let crossterm = Crossterm::new(&Screen::default()); /// let crossterm = Crossterm::new(&Screen::default());
/// let mut terminal = crossterm.terminal(); /// let mut terminal = crossterm.terminal();
///
/// ``` /// ```
pub fn terminal(&self) -> terminal::Terminal { pub fn terminal(&self) -> terminal::Terminal {
return terminal::Terminal::new(&self.stdout); return terminal::Terminal::new(&self.stdout);
} }
/// Get an TerminalColor implementation whereon color related actions can be performed. /// Get an `TerminalColor` implementation whereon color related actions can be performed.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use crossterm::{Crossterm, Screen}; /// use crossterm::{Crossterm, Screen};
/// ///
/// let crossterm = Crossterm::new(&Screen::default()); /// let crossterm = Crossterm::new(&Screen::default());
/// let mut terminal = crossterm.terminal(); /// let mut terminal = crossterm.terminal();
///
/// ``` /// ```
pub fn color(&self) -> style::TerminalColor { pub fn color(&self) -> style::TerminalColor {
return style::TerminalColor::new(&self.stdout); return style::TerminalColor::new(&self.stdout);
} }
/// This could be used to style an Displayable with colors and attributes. /// This could be used to style an `Displayable` type with colors and attributes.
///
/// #Example
/// ///
/// ```rust /// ```rust
/// /// use crossterm::Screen ;
/// use crossterm::{ Screen };
/// ///
/// // get an styled object which could be painted to the terminal. /// // get an styled object which could be painted to the terminal.
/// let styled_object = style("Some Blue colored text on black background").with(Color::Blue).on(Color::Black); /// let styled_object = style("Some Blue colored text on black background")
/// .with(Color::Blue)
/// .on(Color::Black);
/// ///
/// // create an default screen. /// // create an default screen.
/// let screen = Screen::default(); /// let screen = Screen::default();

View File

@ -3,6 +3,9 @@
use super::Stdout; use super::Stdout;
use std::sync::Arc; use std::sync::Arc;
#[cfg(windows)]
use kernel::windows_kernel::ansi_support::{try_enable_ansi_support, windows_supportable};
#[cfg(windows)] #[cfg(windows)]
use kernel::windows_kernel::terminal::{buffer_size, exit, terminal_size}; use kernel::windows_kernel::terminal::{buffer_size, exit, terminal_size};
@ -47,22 +50,17 @@ pub fn get_module<T>(winapi_impl: T, unix_impl: T) -> Option<T> {
let mut term: Option<T> = None; let mut term: Option<T> = None;
let mut does_support = true; let mut does_support = true;
if cfg!(target_os = "windows") { if !windows_supportable()
#[cfg(windows)] {
use kernel::windows_kernel::ansi_support::{try_enable_ansi_support, windows_supportable}; // Try to enable ansi on windows if not than use WINAPI.
does_support = try_enable_ansi_support();
if !windows_supportable() // uncomment this line when you want to use the winapi implementation.
{ does_support = false;
// Try to enable ansi on windows if not than use WINAPI. if !does_support {
does_support = try_enable_ansi_support(); term = Some(winapi_impl);
// uncomment this line when you want to use the winapi implementation.
// does_support = false;
if !does_support {
term = Some(winapi_impl);
}
} }
} }
if does_support { if does_support {
term = Some(unix_impl); term = Some(unix_impl);

View File

@ -37,15 +37,15 @@ use std::sync::Arc;
/// // write the above text by flushing the internal buffer of this type. /// // write the above text by flushing the internal buffer of this type.
/// screen.flush(); /// screen.flush();
/// ///
/// // create raw alternate screen from normal screen. /// let screen = Screen::new(false);
/// let screen = Screen::new();
/// ///
/// // create raw alternate screen from normal screen.
/// if let Ok(alternate_screen) = screen.enable_alternate_modes(true) /// if let Ok(alternate_screen) = screen.enable_alternate_modes(true)
/// { /// {
/// let crossterm = Crossterm::new(); /// let crossterm = Crossterm::new(&alternate_screen.screen);
/// ///
/// // make sure to pass in the screen of the AlternateScreen. /// // make sure to pass in the screen of the AlternateScreen.
/// crossterm.cursor(&alternate_screen.screen); /// crossterm.cursor();
/// } /// }
/// ``` /// ```
/// ///

View File

@ -4,7 +4,7 @@
//! You can just call the action you want to perform and under water it will check what to do based on the current platform. //! You can just call the action you want to perform and under water it will check what to do based on the current platform.
#[macro_use] #[macro_use]
pub mod common; mod common;
mod kernel; mod kernel;
mod modules; mod modules;
@ -14,11 +14,13 @@ pub use modules::cursor;
pub use modules::input; pub use modules::input;
pub use modules::write; pub use modules::write;
pub use modules::style; pub use modules::style;
pub use modules::terminal; pub use modules::terminal;
pub use common::Crossterm;
pub use write::{IStdout, Stdout};
pub use common::screen::Screen; pub use common::screen::Screen;
pub use common::Crossterm;
pub use write::{Stdout};
use write::IStdout;
#[cfg(unix)] #[cfg(unix)]
extern crate libc; extern crate libc;
#[cfg(unix)] #[cfg(unix)]

View File

@ -12,12 +12,9 @@ use std::sync::Arc;
/// Struct that stores an specific platform implementation for cursor related actions. /// Struct that stores an specific platform implementation for cursor related actions.
/// ///
/// Check `/examples/version/cursor` in the library for more specific examples. /// Check `/examples/cursor` in the library for more specific examples.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use self::crossterm::cursor::cursor; /// use self::crossterm::cursor::cursor;
/// use self::crossterm::Screen; /// use self::crossterm::Screen;
@ -32,7 +29,6 @@ use std::sync::Arc;
/// cursor.hide(); /// cursor.hide();
/// cursor.blink(true); /// cursor.blink(true);
/// cursor.move_left(2); /// cursor.move_left(2);
///
/// ``` /// ```
pub struct TerminalCursor<'stdout> { pub struct TerminalCursor<'stdout> {
screen: &'stdout Arc<Stdout>, screen: &'stdout Arc<Stdout>,
@ -58,8 +54,6 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Goto some position (x,y) in the terminal. /// Goto some position (x,y) in the terminal.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
@ -74,32 +68,25 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Get current cursor position (x,y) in the terminal. /// Get current cursor position (x,y) in the terminal.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// // get the current cursor pos /// // get the current cursor pos
/// let (x,y) = cursor.pos(); /// let (x,y) = cursor.pos();
///
/// ``` /// ```
pub fn pos(&self) -> (u16, u16) { pub fn pos(&self) -> (u16, u16) {
self.terminal_cursor.pos(&self.screen) self.terminal_cursor.pos(&self.screen)
} }
/// Move the current cursor position `n` times up. /// Move the current cursor position `n` times up.
/// #Example
/// ///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// // Move the cursor to position 3 times to the up in the terminal /// // Move the cursor to position 3 times to the up in the terminal
/// cursor.move_up(3); /// cursor.move_up(3);
///
/// ``` /// ```
pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { pub fn move_up(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_up(count, &self.screen); self.terminal_cursor.move_up(count, &self.screen);
@ -108,16 +95,12 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Move the current cursor position `n` times right. /// Move the current cursor position `n` times right.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// // Move the cursor to position 3 times to the right in the terminal /// // Move the cursor to position 3 times to the right in the terminal
/// cursor.move_right(3); /// cursor.move_right(3);
///
/// ``` /// ```
pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_right(count, &self.screen); self.terminal_cursor.move_right(count, &self.screen);
@ -126,16 +109,12 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Move the current cursor position `n` times down. /// Move the current cursor position `n` times down.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// // Move the cursor to position 3 times to the down in the terminal /// // Move the cursor to position 3 times to the down in the terminal
/// cursor.move_down(3); /// cursor.move_down(3);
///
/// ``` /// ```
pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { pub fn move_down(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_down(count, &self.screen); self.terminal_cursor.move_down(count, &self.screen);
@ -144,16 +123,12 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Move the current cursor position `n` times left. /// Move the current cursor position `n` times left.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// // Move the cursor to position 3 times to the left in the terminal /// // Move the cursor to position 3 times to the left in the terminal
/// cursor.move_left(3); /// cursor.move_left(3);
///
/// ``` /// ```
pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { pub fn move_left(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_left(count, &self.screen); self.terminal_cursor.move_left(count, &self.screen);
@ -164,15 +139,11 @@ impl<'stdout> TerminalCursor<'stdout> {
/// ///
/// Note that this position is stored program based not per instance of the `Cursor` struct. /// Note that this position is stored program based not per instance of the `Cursor` struct.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// cursor.safe_position(); /// cursor.safe_position();
///
/// ``` /// ```
pub fn save_position(&self) { pub fn save_position(&self) {
self.terminal_cursor.save_position(&self.screen); self.terminal_cursor.save_position(&self.screen);
@ -182,15 +153,11 @@ impl<'stdout> TerminalCursor<'stdout> {
/// ///
/// Note that this method reset to the position set by `save_position()` and that this position is stored program based not per instance of the `Cursor` struct. /// Note that this method reset to the position set by `save_position()` and that this position is stored program based not per instance of the `Cursor` struct.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// ///
/// cursor.reset_position(); /// cursor.reset_position();
///
/// ``` /// ```
pub fn reset_position(&self) { pub fn reset_position(&self) {
self.terminal_cursor.reset_position(&self.screen); self.terminal_cursor.reset_position(&self.screen);
@ -198,13 +165,9 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Hide de cursor in the console. /// Hide de cursor in the console.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let cursor = cursor(&Screen::default()); /// let cursor = cursor(&Screen::default());
/// cursor.hide(); /// cursor.hide();
///
/// ``` /// ```
pub fn hide(&self) { pub fn hide(&self) {
self.terminal_cursor.hide(&self.screen); self.terminal_cursor.hide(&self.screen);
@ -212,8 +175,6 @@ impl<'stdout> TerminalCursor<'stdout> {
/// Show the cursor in the console. /// Show the cursor in the console.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// ///
/// let screen = Screen::default(); /// let screen = Screen::default();
@ -229,15 +190,11 @@ impl<'stdout> TerminalCursor<'stdout> {
/// ///
/// Not all terminals are supporting this functionality. Windows versions lower than windows 10 also are not supporting this version. /// Not all terminals are supporting this functionality. Windows versions lower than windows 10 also are not supporting this version.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let cursor = cursor(&screen); /// let cursor = cursor(&screen);
/// cursor.blink(true); /// cursor.blink(true);
/// cursor.blink(false); /// cursor.blink(false);
///
/// ``` /// ```
pub fn blink(&self, blink: bool) { pub fn blink(&self, blink: bool) {
self.terminal_cursor.blink(blink, &self.screen); self.terminal_cursor.blink(blink, &self.screen);

View File

@ -24,7 +24,7 @@ use std::sync::Arc;
///! ///!
///! This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific), ///! 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. ///! so that cursor related actions can be preformed on both unix and windows systems.
pub trait ITerminalCursor { trait ITerminalCursor {
/// Goto some location (x,y) in the context. /// Goto some location (x,y) in the context.
fn goto(&self, x: u16, y: u16, screen_manager: &Arc<Stdout>); fn goto(&self, x: u16, y: u16, screen_manager: &Arc<Stdout>);
/// Get the location (x,y) of the current cusror in the context /// Get the location (x,y) of the current cusror in the context

View File

@ -9,10 +9,7 @@ use super::*;
/// ///
/// Check `/examples/input` the examples folder on github for more info. /// Check `/examples/input` the examples folder on github for more info.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// extern crate crossterm; /// extern crate crossterm;
/// use self::crossterm::Screen; /// use self::crossterm::Screen;
/// use self::crossterm::input::input; /// use self::crossterm::input::input;
@ -45,17 +42,13 @@ impl<'stdout> TerminalInput<'stdout> {
/// Read one line from the user input. /// Read one line from the user input.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let input = input(&screen); /// let input = input(&screen);
/// match input.read_line() { /// match input.read_line() {
/// Ok(s) => println!("string typed: {}", s), /// Ok(s) => println!("string typed: {}", s),
/// Err(e) => println!("error: {}", e), /// Err(e) => println!("error: {}", e),
/// } /// }
///
/// ``` /// ```
pub fn read_line(&self) -> io::Result<String> { pub fn read_line(&self) -> io::Result<String> {
self.terminal_input.read_line(&self.stdout) self.terminal_input.read_line(&self.stdout)
@ -63,10 +56,7 @@ impl<'stdout> TerminalInput<'stdout> {
/// Read one character from the user input /// Read one character from the user input
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let input = input(&screen); /// let input = input(&screen);
/// ///
@ -74,7 +64,6 @@ impl<'stdout> TerminalInput<'stdout> {
/// Ok(c) => println!("character pressed: {}", c), /// Ok(c) => println!("character pressed: {}", c),
/// Err(e) => println!("error: {}", e), /// Err(e) => println!("error: {}", e),
/// } /// }
///
/// ``` /// ```
pub fn read_char(&self) -> io::Result<char> { pub fn read_char(&self) -> io::Result<char> {
return self.terminal_input.read_char(&self.stdout); return self.terminal_input.read_char(&self.stdout);
@ -82,12 +71,7 @@ impl<'stdout> TerminalInput<'stdout> {
/// Read the input asynchronously from the user. /// Read the input asynchronously from the user.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// use crossterm::{Crossterm, Screen}
///
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them. /// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
/// let screen = Screen::new(true); /// let screen = Screen::new(true);
/// let input = input(&screen); /// let input = input(&screen);
@ -116,8 +100,6 @@ impl<'stdout> TerminalInput<'stdout> {
/// Read the input asynchronously until a certain character is hit. /// Read the input asynchronously until a certain character is hit.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them. /// // we need to enable raw mode otherwise the characters will be outputted by default before we are able to read them.
/// let screen = Screen::new(true); /// let screen = Screen::new(true);

View File

@ -7,12 +7,9 @@ use Screen;
/// Struct that stores an specific platform implementation for color related actions. /// Struct that stores an specific platform implementation for color related actions.
/// ///
/// Check `/examples/version/color` in the library for more specific examples. /// Check `/examples/color` in the library for more specific examples.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// use crossterm::{Screen} /// use crossterm::{Screen}
/// use crossterm::color::color; /// use crossterm::color::color;
/// ///
@ -25,7 +22,6 @@ use Screen;
/// colored_terminal.set_bg(Color::Red); /// colored_terminal.set_bg(Color::Red);
/// // reset color to default /// // reset color to default
/// colored_terminal.reset(); /// colored_terminal.reset();
///
/// ``` /// ```
pub struct TerminalColor<'stdout> { pub struct TerminalColor<'stdout> {
color: Box<ITerminalColor>, color: Box<ITerminalColor>,
@ -52,8 +48,6 @@ impl<'stdout> TerminalColor<'stdout> {
/// Set the foreground color to the given color. /// Set the foreground color to the given color.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let colored_terminal = color(&screen); /// let colored_terminal = color(&screen);
@ -70,10 +64,7 @@ impl<'stdout> TerminalColor<'stdout> {
/// Set the background color to the given color. /// Set the background color to the given color.
/// ///
/// #Example
///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let colored_terminal = color(&screen); /// let colored_terminal = color(&screen);
/// ///
@ -88,14 +79,11 @@ impl<'stdout> TerminalColor<'stdout> {
} }
/// Reset the terminal colors and attributes to default. /// Reset the terminal colors and attributes to default.
/// # Example
/// ///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let colored_terminal = color(&screen); /// let colored_terminal = color(&screen);
/// colored_terminal.reset(); /// colored_terminal.reset();
///
/// ``` /// ```
pub fn reset(&self) { pub fn reset(&self) {
self.color.reset(&self.stdout); self.color.reset(&self.stdout);

View File

@ -30,7 +30,7 @@ use super::{functions, Stdout};
/// ///
/// This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific), /// 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. /// so that color related actions can be preformed on both unix and windows systems.
pub trait ITerminalColor { trait ITerminalColor {
/// Set the foreground color to the given color. /// Set the foreground color to the given color.
fn set_fg(&self, fg_color: Color, stdout: &Arc<Stdout>); fn set_fg(&self, fg_color: Color, stdout: &Arc<Stdout>);
/// Set the background color to the given color. /// Set the background color to the given color.

View File

@ -21,8 +21,6 @@ pub struct StyledObject<D: Display> {
impl<D: Display> StyledObject<D> { impl<D: Display> StyledObject<D> {
/// Set the foreground of the styled object to the passed `Color` /// Set the foreground of the styled object to the passed `Color`
/// ///
/// #Example
///
/// ```rust /// ```rust
/// use self::crossterm::style::{style,Color}; /// use self::crossterm::style::{style,Color};
/// ///

View File

@ -32,7 +32,7 @@ pub enum ClearType {
/// ///
/// This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific), /// 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. /// so that color related actions can be preformed on both unix and windows systems.
pub trait ITerminal { trait ITerminal {
/// Clear the current cursor by specifying the clear type /// Clear the current cursor by specifying the clear type
fn clear(&self, clear_type: ClearType, screen_manager: &Arc<Stdout>); fn clear(&self, clear_type: ClearType, screen_manager: &Arc<Stdout>);
/// Get the terminal size (x,y) /// Get the terminal size (x,y)

View File

@ -8,12 +8,9 @@ use std::io::Write;
/// Struct that stores an specific platform implementation for terminal related actions. /// Struct that stores an specific platform implementation for terminal related actions.
/// ///
/// Check `/examples/version/terminal` in the library for more specific examples. /// Check `/examples/terminal` in the library for more specific examples.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// use crossterm::terminal::terminal; /// use crossterm::terminal::terminal;
/// ///
/// let screen = Screen::default(); /// let screen = Screen::default();
@ -47,12 +44,9 @@ impl<'stdout> Terminal<'stdout> {
} }
} }
/// Clear the current cursor by specifying the clear type /// Clear the current cursor by specifying the clear type.
///
/// #Example
/// ///
/// ```rust /// ```rust
///
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
/// ///
@ -66,7 +60,6 @@ impl<'stdout> Terminal<'stdout> {
/// term.clear(terminal::ClearType::CurrentLine); /// term.clear(terminal::ClearType::CurrentLine);
/// // clear all cells from cursor position until new line in terminal. /// // clear all cells from cursor position until new line in terminal.
/// term.clear(terminal::ClearType::UntilNewLine); /// term.clear(terminal::ClearType::UntilNewLine);
///
/// ``` /// ```
pub fn clear(&self, clear_type: ClearType) { pub fn clear(&self, clear_type: ClearType) {
self.terminal.clear(clear_type, &self.screen); self.terminal.clear(clear_type, &self.screen);
@ -74,8 +67,6 @@ impl<'stdout> Terminal<'stdout> {
/// Get the terminal size (x,y). /// Get the terminal size (x,y).
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
@ -90,8 +81,6 @@ impl<'stdout> Terminal<'stdout> {
/// Scroll `n` lines up in the current terminal. /// Scroll `n` lines up in the current terminal.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
@ -106,8 +95,6 @@ impl<'stdout> Terminal<'stdout> {
/// Scroll `n` lines up in the current terminal. /// Scroll `n` lines up in the current terminal.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
@ -122,8 +109,6 @@ impl<'stdout> Terminal<'stdout> {
/// Set the terminal size. Note that not all terminals can be set to a very small scale. /// Set the terminal size. Note that not all terminals can be set to a very small scale.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
@ -138,8 +123,6 @@ impl<'stdout> Terminal<'stdout> {
/// Exit the current process. /// Exit the current process.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);
@ -153,8 +136,6 @@ impl<'stdout> Terminal<'stdout> {
/// Write any displayable content to the current terminal screen. /// Write any displayable content to the current terminal screen.
/// ///
/// #Example
///
/// ```rust /// ```rust
/// let screen = Screen::default(); /// let screen = Screen::default();
/// let mut term = terminal(&screen); /// let mut term = terminal(&screen);

View File

@ -39,8 +39,6 @@ pub struct Stdout {
pub is_in_raw_mode:bool, pub is_in_raw_mode:bool,
} }
// todo: impl Default for stdout
impl Stdout { impl Stdout {
/// Create new screen write instance whereon screen related actions can be performed. /// Create new screen write instance whereon screen related actions can be performed.
pub fn new(is_in_raw_mode: bool) -> Self { pub fn new(is_in_raw_mode: bool) -> Self {