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;
/// This type offers an easy way to use functionalities like `cursor`, `terminal`, `color`, `input`, and `styling`.
///
/// 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.
// TODO Should be removed? This adds just another way to achieve the same thing.
/// A crossterm functionality wrapper.
pub struct Crossterm;
impl Crossterm {
/// Create a new instance of `Crossterm`
/// Creates a new `Crossterm`.
pub fn new() -> Crossterm {
Crossterm
}
/// Get a `TerminalCursor` implementation whereon cursor related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let cursor = crossterm.cursor();
/// ```
/// Crates a new `TerminalCursor`.
#[cfg(feature = "cursor")]
pub fn cursor(&self) -> crossterm_cursor::TerminalCursor {
crossterm_cursor::TerminalCursor::new()
}
/// Get a `TerminalInput` implementation whereon terminal related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let input = crossterm.input();
/// ```
/// Creates a new `TerminalInput`.
#[cfg(feature = "input")]
pub fn input(&self) -> crossterm_input::TerminalInput {
crossterm_input::TerminalInput::new()
}
/// Get a `Terminal` implementation whereon terminal related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.terminal();
/// ```
/// Creates a new `Terminal`.
#[cfg(feature = "terminal")]
pub fn terminal(&self) -> crossterm_terminal::Terminal {
crossterm_terminal::Terminal::new()
}
/// Get a `TerminalColor` implementation whereon color related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.color();
/// ```
/// Creates a new `TerminalColor`.
#[cfg(feature = "style")]
pub fn color(&self) -> crossterm_style::TerminalColor {
crossterm_style::TerminalColor::new()
}
/// This could be used to style any type implementing `Display` with colors and attributes.
///
/// # 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.
/// Creates a new `StyledObject`.
#[cfg(feature = "style")]
pub fn style<D>(&self, val: D) -> crossterm_style::StyledObject<D>
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?
//! 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.
//! Through the simplicity of Crossterm, you do not have to worry about the platform you are working with.
//! Crossterm aims to be simple and easy to call in code. Through the simplicity of Crossterm, you do not
//! 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.
//! - [Crossterm Style](https://crates.io/crates/crossterm_style)
//! - [Crossterm Input](https://crates.io/crates/crossterm_input)
//! - [Crossterm Screen](https://crates.io/crates/crossterm_screen)
//! - [Crossterm Cursor](https://crates.io/crates/crossterm_cursor)
//! - [Crossterm Terminal](https://crates.io/crates/crossterm_terminal)
//! ## Important
//!
//! This crate re-exports all other `crossterm_*` crates types only. Please, consult the
//! `crossterm` crate repository [README](https://github.com/crossterm-rs/crossterm/blob/master/README.md) to
//! learn how to use features to enable/disable functionality, what's planned, etc. There will be
//! new code organization, breaking API changes, etc.
#[cfg(feature = "cursor")]
pub use crossterm_cursor::{