Update API docs

Signed-off-by: Robert Vojta <rvojta@me.com>
This commit is contained in:
Robert Vojta 2019-10-02 09:37:49 +02:00
parent beb05b4b1e
commit e335a65a40
No known key found for this signature in database
GPG Key ID: 082AAEA8854E3D88
2 changed files with 23 additions and 80 deletions

View File

@ -1,102 +1,40 @@
use std::fmt::Display; use std::fmt::Display;
/// This type offers an easy way to use functionalities like `cursor`, `terminal`, `color`, `input`, and `styling`. // TODO Should be removed? This adds just another way to achieve the same thing.
/// /// A crossterm functionality wrapper.
/// To get a cursor instance to perform cursor related actions, you can do the following:
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let cursor = crossterm.cursor();
/// let color = crossterm.color();
/// let terminal = crossterm.terminal();
/// let terminal = crossterm.input();
/// let style = crossterm
/// .style(format!("{} {}", 0, "Black text on green background"))
/// .with(Color::Black)
/// .on(Color::Green);
/// ```
///
/// # Remark
/// - depending on the feature flags you've enabled you are able to call methods of this type.
/// - checkout the crossterm book for more information about feature flags or alternate screen.
pub struct Crossterm; pub struct Crossterm;
impl Crossterm { impl Crossterm {
/// Create a new instance of `Crossterm` /// Creates a new `Crossterm`.
pub fn new() -> Crossterm { pub fn new() -> Crossterm {
Crossterm Crossterm
} }
/// Get a `TerminalCursor` implementation whereon cursor related actions can be performed. /// Crates a new `TerminalCursor`.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let cursor = crossterm.cursor();
/// ```
#[cfg(feature = "cursor")] #[cfg(feature = "cursor")]
pub fn cursor(&self) -> crossterm_cursor::TerminalCursor { pub fn cursor(&self) -> crossterm_cursor::TerminalCursor {
crossterm_cursor::TerminalCursor::new() crossterm_cursor::TerminalCursor::new()
} }
/// Get a `TerminalInput` implementation whereon terminal related actions can be performed. /// Creates a new `TerminalInput`.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let input = crossterm.input();
/// ```
#[cfg(feature = "input")] #[cfg(feature = "input")]
pub fn input(&self) -> crossterm_input::TerminalInput { pub fn input(&self) -> crossterm_input::TerminalInput {
crossterm_input::TerminalInput::new() crossterm_input::TerminalInput::new()
} }
/// Get a `Terminal` implementation whereon terminal related actions can be performed. /// Creates a new `Terminal`.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.terminal();
/// ```
#[cfg(feature = "terminal")] #[cfg(feature = "terminal")]
pub fn terminal(&self) -> crossterm_terminal::Terminal { pub fn terminal(&self) -> crossterm_terminal::Terminal {
crossterm_terminal::Terminal::new() crossterm_terminal::Terminal::new()
} }
/// Get a `TerminalColor` implementation whereon color related actions can be performed. /// Creates a new `TerminalColor`.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.color();
/// ```
#[cfg(feature = "style")] #[cfg(feature = "style")]
pub fn color(&self) -> crossterm_style::TerminalColor { pub fn color(&self) -> crossterm_style::TerminalColor {
crossterm_style::TerminalColor::new() crossterm_style::TerminalColor::new()
} }
/// This could be used to style any type implementing `Display` with colors and attributes. /// Creates a new `StyledObject`.
///
/// # Example
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
///
/// // get an styled object which could be painted to the terminal.
/// let styled_object = crossterm.style("Some Blue colored text on black background")
/// .with(Color::Blue)
/// .on(Color::Black);
///
/// // print the styled text * times to the current screen.
/// for i in 1..10
/// {
/// println!("{}", styled_object);
/// }
/// ```
///
/// # Remark
/// `val`: any type implementing Display e.g. string.
#[cfg(feature = "style")] #[cfg(feature = "style")]
pub fn style<D>(&self, val: D) -> crossterm_style::StyledObject<D> pub fn style<D>(&self, val: D) -> crossterm_style::StyledObject<D>
where where

View File

@ -1,17 +1,22 @@
//! # Crossterm
//!
//! Have you ever been disappointed when a terminal library for rust was only written for UNIX systems? //! Have you ever been disappointed when a terminal library for rust was only written for UNIX systems?
//! Crossterm provides clearing, input handling, styling, cursor movement, and terminal actions for both Windows and UNIX systems. //! Crossterm provides clearing, input handling, styling, cursor movement, and terminal actions for both
//! Windows and UNIX systems.
//! //!
//! Crossterm aims to be simple and easy to call in code. //! Crossterm aims to be simple and easy to call in code. Through the simplicity of Crossterm, you do not
//! Through the simplicity of Crossterm, you do not have to worry about the platform you are working with. //! have to worry about the platform you are working with.
//! //!
//! This crate supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested see [Tested Terminals](#tested-terminals) for more info). //! This crate supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested
//! see [Tested Terminals](https://github.com/crossterm-rs/crossterm/tree/zrzka/docs-update#tested-terminals)
//! for more info).
//! //!
//! This crate consists of five modules that are provided behind [feature flags](https://crossterm-rs.github.io/crossterm/docs/feature_flags.html) so that you can define which features you'd like to have; by default, all features are enabled. //! ## Important
//! - [Crossterm Style](https://crates.io/crates/crossterm_style) //!
//! - [Crossterm Input](https://crates.io/crates/crossterm_input) //! This crate re-exports all other `crossterm_*` crates types only. Please, consult the
//! - [Crossterm Screen](https://crates.io/crates/crossterm_screen) //! `crossterm` crate repository [README](https://github.com/crossterm-rs/crossterm/blob/master/README.md) to
//! - [Crossterm Cursor](https://crates.io/crates/crossterm_cursor) //! learn how to use features to enable/disable functionality, what's planned, etc. There will be
//! - [Crossterm Terminal](https://crates.io/crates/crossterm_terminal) //! new code organization, breaking API changes, etc.
#[cfg(feature = "cursor")] #[cfg(feature = "cursor")]
pub use crossterm_cursor::{ pub use crossterm_cursor::{