Documentation fixes (#156)
This commit is contained in:
parent
2b36dbf9d9
commit
e1b8da03ba
12
README.md
12
README.md
@ -40,7 +40,7 @@ This crate consists of five modules that are provided behind [feature flags](htt
|
||||
- [Features](#features)
|
||||
- [Examples](#examples)
|
||||
- [Crossterm Type](#crossterm-type)
|
||||
- [Styled Font](#styled-font)
|
||||
- [Styled Text](#styled-text)
|
||||
- [Cursor](#cursor)
|
||||
- [Terminal](#terminal)
|
||||
- [Input Reading](#input-reading)
|
||||
@ -121,8 +121,8 @@ let terminal = crossterm.terminal();
|
||||
let input = crossterm.input();
|
||||
```
|
||||
|
||||
### Styled Font
|
||||
This module enables you to style the terminal font.
|
||||
### Styled Text
|
||||
This module enables you to style the terminal text.
|
||||
|
||||
Good documentation can be found at the following places: [docs](https://docs.rs/crossterm_style/), [book](https://timonpost.github.io/crossterm/docs/styling.html), [examples](https://github.com/TimonPost/crossterm/tree/master/examples/key_events.rs)
|
||||
|
||||
@ -130,7 +130,7 @@ _imports_
|
||||
```rust
|
||||
use crossterm::{Colored, Color, Colorize, Styler, Attribute};
|
||||
```
|
||||
_style font with attributes_
|
||||
_style text with attributes_
|
||||
```rust
|
||||
// pass any `Attribute` value to the formatting braces.
|
||||
println!("{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline);
|
||||
@ -143,7 +143,7 @@ println!("{}", styled_text);
|
||||
let styled_text = style("Bold Underlined").bold().underlined();
|
||||
```
|
||||
|
||||
_style font with colors_
|
||||
_style text with colors_
|
||||
```rust
|
||||
println!("{} Red foreground color", Colored::Fg(Color::Red));
|
||||
println!("{} Blue background color", Colored::Bg(Color::Blue));
|
||||
@ -155,7 +155,7 @@ println!("{}", styled_text);
|
||||
// old-way but still usable
|
||||
let styled_text = style("Bold Underlined").with(Color::Red).on(Color::Blue);
|
||||
```
|
||||
_style font with RGB and ANSI Value_
|
||||
_style text with RGB and ANSI Value_
|
||||
```rust
|
||||
// custom rgb value (Windows 10 and UNIX systems)
|
||||
println!("{} some colored text", Colored::Fg(Color::Rgb {
|
||||
|
@ -1,5 +1,5 @@
|
||||
//!
|
||||
//! Examples of actions that could be performed with te cursor.
|
||||
//! Examples of actions that could be performed with the cursor.
|
||||
//!
|
||||
|
||||
extern crate crossterm_cursor;
|
||||
|
@ -16,7 +16,7 @@ use crossterm_utils::supports_ansi;
|
||||
/// - Goto a certain position
|
||||
/// - Get cursor position
|
||||
/// - Storing the current cursor position and resetting to that stored cursor position later
|
||||
/// - Hiding an showing the cursor
|
||||
/// - Hiding and showing the cursor
|
||||
/// - Control over blinking of the terminal cursor (only some terminals are supporting this)
|
||||
///
|
||||
/// Note that positions of the cursor are 0 -based witch means that the coordinates (cells) starts counting from 0
|
||||
|
@ -24,7 +24,7 @@ pub struct TerminalInput {
|
||||
}
|
||||
|
||||
impl TerminalInput {
|
||||
/// Create a new instance of `TerminalInput` whereon input related actions could be preformed.
|
||||
/// Create a new instance of `TerminalInput` whereon input related actions could be performed.
|
||||
pub fn new() -> TerminalInput {
|
||||
#[cfg(windows)]
|
||||
let input = WindowsInput::new();
|
||||
@ -95,7 +95,7 @@ impl TerminalInput {
|
||||
|
||||
/// Read the input asynchronously until a certain character is hit, which means that input events are gathered on the background and will be queued for you to read.
|
||||
///
|
||||
/// If you want a blocking, or less resource consuming read to happen use `read_sync()`, this will leave a way all the thread and queueing and will be a blocking read.
|
||||
/// If you want a blocking or less resource consuming read to happen, use `read_sync()`. This will leave alone the background thread and queues and will be a blocking read.
|
||||
///
|
||||
/// This is the same as `read_async()` but stops reading when a certain character is hit.
|
||||
///
|
||||
@ -114,10 +114,10 @@ impl TerminalInput {
|
||||
self.input.read_until_async(delimiter)
|
||||
}
|
||||
|
||||
/// Read the input synchronously from the user, which means that reading call wil be blocking ones.
|
||||
/// It also uses less resources than the `AsyncReader` because background thread and queues are left away.
|
||||
/// Read the input synchronously from the user, which means that reading calls will block.
|
||||
/// It also uses less resources than the `AsyncReader` because the background thread and queues are left alone.
|
||||
///
|
||||
/// In case you don't want the reading to block your program you could consider `read_async`.
|
||||
/// Consider using `read_async` if you don't want the reading call to block your program.
|
||||
///
|
||||
/// # Remark
|
||||
/// - Readings will be blocking calls.
|
||||
@ -130,7 +130,7 @@ impl TerminalInput {
|
||||
|
||||
/// Enable mouse events to be captured.
|
||||
///
|
||||
/// When enabling mouse input you will be able to capture, mouse movements, pressed buttons and locations.
|
||||
/// When enabling mouse input, you will be able to capture mouse movements, pressed buttons, and locations.
|
||||
///
|
||||
/// # Remark
|
||||
/// - Mouse events will be send over the reader created with `read_async`, `read_async_until`, `read_sync`.
|
||||
@ -140,7 +140,7 @@ impl TerminalInput {
|
||||
|
||||
/// Disable mouse events to be captured.
|
||||
///
|
||||
/// When disabling mouse input you won't be able to capture, mouse movements, pressed buttons and locations anymore.
|
||||
/// When disabling mouse input, you won't be able to capture mouse movements, pressed buttons, and locations anymore.
|
||||
pub fn disable_mouse_mode(&self) -> Result<()> {
|
||||
self.input.disable_mouse_mode()
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::thread;
|
||||
|
||||
/// This trait defines the actions that can be preformed with the terminal input.
|
||||
/// This trait defines the actions that can be performed with the terminal input.
|
||||
/// This trait can be implemented so that a concrete implementation of the ITerminalInput can fulfill
|
||||
/// the wishes to work on a specific platform.
|
||||
///
|
||||
|
@ -78,9 +78,9 @@ impl ITerminalInput for UnixInput {
|
||||
}
|
||||
}
|
||||
|
||||
/// This type allows you to read input synchronously, which means that reading call will be blocking ones.
|
||||
/// This type allows you to read input synchronously, which means that reading calls will block.
|
||||
///
|
||||
/// This type is an iterator, and could be used to iterate over input events.
|
||||
/// This type is an iterator, and can be used to iterate over input events.
|
||||
///
|
||||
/// If you don't want to block your calls use [AsyncReader](./LINK), which will read input on the background and queue it for you to read.
|
||||
pub struct SyncReader {
|
||||
@ -92,10 +92,10 @@ impl Iterator for SyncReader {
|
||||
type Item = InputEvent;
|
||||
/// Read input from the user.
|
||||
///
|
||||
/// If there are no keys pressed this will be a blocking call until there are.
|
||||
/// This will return `None` in case of a failure and `Some(InputEvent) in case of an occurred input event.`
|
||||
/// If there are no keys pressed, this will be a blocking call until there is one.
|
||||
/// This will return `None` in case of a failure and `Some(InputEvent)` in case of an occurred input event.
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
// TODO: Currently errors are consumed and converted to a `NONE` maybe we should'nt be doing this?
|
||||
// TODO: Currently errors are consumed and converted to a `None`. Maybe we shouldn't be doing this?
|
||||
let source = &mut self.source;
|
||||
|
||||
if let Some(c) = self.leftover {
|
||||
|
@ -113,9 +113,9 @@ impl ITerminalInput for WindowsInput {
|
||||
}
|
||||
}
|
||||
|
||||
/// This type allows you to read input synchronously, which means that reading call will be blocking ones.
|
||||
/// This type allows you to read input synchronously, which means that reading calls will block.
|
||||
///
|
||||
/// This type is an iterator, and could be used to iterate over input events.
|
||||
/// This type is an iterator, and can be used to iterate over input events.
|
||||
///
|
||||
/// If you don't want to block your calls use [AsyncReader](./LINK), which will read input on the background and queue it for you to read.
|
||||
pub struct SyncReader;
|
||||
@ -125,8 +125,8 @@ impl Iterator for SyncReader {
|
||||
|
||||
/// Read input from the user.
|
||||
///
|
||||
/// If there are no keys pressed this will be a blocking call until there are.
|
||||
/// This will return `None` in case of a failure and `Some(InputEvent) in case of an occurred input event.`
|
||||
/// If there are no keys pressed, this will be a blocking call until there is one.
|
||||
/// This will return `None` in case of a failure and `Some(InputEvent)` in case of an occurred input event.
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut iterator = into_virtual_terminal_sequence().unwrap().1.into_iter();
|
||||
|
||||
|
@ -7,7 +7,7 @@ use std::{thread, time};
|
||||
|
||||
/// print wait screen on alternate screen, then switch back.
|
||||
pub fn print_wait_screen_on_alternate_window() {
|
||||
// move to alternate screen, 'false' means if the alternate screen should be in raw modes.
|
||||
// move to the alternate screen, 'false' determines if the alternate screen should be in raw mode.
|
||||
if let Ok(alternate) = AlternateScreen::to_alternate(false) {
|
||||
// do some stuff on the alternate screen.
|
||||
} // <- alternate screen will be disabled when dropped.
|
||||
|
@ -6,7 +6,7 @@ use std::io::{stdout, Write};
|
||||
use std::{thread, time};
|
||||
|
||||
pub fn raw_modes() {
|
||||
// create a Screen instance who operates on the default output; io::stdout(). By passing in 'true' we make this screen 'raw'
|
||||
// create a Screen instance that operates on the default output: io::stdout(). By passing in 'true', we make this screen 'raw'
|
||||
let screen = RawScreen::into_raw_mode();
|
||||
let screen = stdout().into_raw_mode();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! A module which provides some functionalities to work with the terminal screen.
|
||||
//! Like allowing you to switch between main and alternate screen or putting the terminal into raw mode.
|
||||
//! Like allowing you to switch between the main and alternate screen or putting the terminal into raw mode.
|
||||
#[macro_use]
|
||||
extern crate crossterm_utils;
|
||||
|
||||
|
@ -15,8 +15,8 @@ use crate::sys::{self, IAlternateScreenCommand};
|
||||
use super::RawScreen;
|
||||
use std::io;
|
||||
|
||||
/// With this type you will be able to switch to alternate screen and back to main screen.
|
||||
/// Check also the Screen type for swishing to alternate mode.
|
||||
/// With this type you will be able to switch to the alternate screen and then back to the main screen.
|
||||
/// Check also the Screen type for switching to alternate mode.
|
||||
///
|
||||
/// Although this type is available for you to use I would recommend using `Screen` instead.
|
||||
pub struct AlternateScreen {
|
||||
@ -28,13 +28,13 @@ pub struct AlternateScreen {
|
||||
}
|
||||
|
||||
impl AlternateScreen {
|
||||
/// Switch to alternate screen. This function will return an `AlternateScreen` instance if everything went well this type will give you control over the `AlternateScreen`.
|
||||
/// Switch to the alternate screen. This function will return an `AlternateScreen` instance if everything went well. This type will give you control over the `AlternateScreen`.
|
||||
///
|
||||
/// The bool specifies whether the screen should be in raw mode or not.
|
||||
///
|
||||
/// # What is Alternate screen?
|
||||
/// *Nix style applications often utilize an alternate screen buffer, so that they can modify the entire contents of the buffer, without affecting the application that started them.
|
||||
/// The alternate buffer is exactly the dimensions of the window, without any scrollback region.
|
||||
/// *Nix style applications often utilize an alternate screen buffer, so that they can modify the entire contents of the buffer without affecting the application that started them.
|
||||
/// The alternate buffer dimensions are exactly the same as the window, without any scrollback region.
|
||||
/// For an example of this behavior, consider when vim is launched from bash.
|
||||
/// Vim uses the entirety of the screen to edit the file, then returning to bash leaves the original buffer unchanged.
|
||||
pub fn to_alternate(raw_mode: bool) -> io::Result<AlternateScreen> {
|
||||
@ -66,7 +66,7 @@ impl AlternateScreen {
|
||||
})
|
||||
}
|
||||
|
||||
/// Switch the alternate screen back to main screen.
|
||||
/// Switch the alternate screen back to the main screen.
|
||||
pub fn to_main(&self) -> io::Result<()> {
|
||||
self.command.disable()?;
|
||||
Ok(())
|
||||
@ -74,7 +74,7 @@ impl AlternateScreen {
|
||||
}
|
||||
|
||||
impl Drop for AlternateScreen {
|
||||
/// This will switch back to main screen on drop.
|
||||
/// This will switch back to the main screen on drop.
|
||||
fn drop(&mut self) {
|
||||
self.to_main().unwrap();
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
use crate::sys;
|
||||
use std::io::{self, Stdout, Write};
|
||||
|
||||
/// A wrapper for the raw terminal state. Which can be used to write to.
|
||||
/// A wrapper for the raw terminal state, which can be used to write to.
|
||||
///
|
||||
/// Please take in mind that if this type drops the raw screen will be undone, to prevent this behaviour call `disable_drop`.
|
||||
/// Please note that if this type drops, the raw screen will be undone. To prevent this behaviour call `disable_drop`.
|
||||
pub struct RawScreen {
|
||||
drop: bool,
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod winapi;
|
||||
use crossterm_utils::Result;
|
||||
use std::io::Write;
|
||||
|
||||
/// This command is used for switching to alternate screen and back to main screen.
|
||||
/// This command is used for switching to the alternate screen and back to the main screen.
|
||||
pub struct ToAlternateScreenCommand;
|
||||
|
||||
impl ToAlternateScreenCommand {
|
||||
@ -30,7 +30,7 @@ impl IAlternateScreenCommand for ToAlternateScreenCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// This trait provides an interface for switching to alternate screen and back.
|
||||
// This trait provides an interface for switching to the alternate screen and back.
|
||||
pub trait IAlternateScreenCommand: Sync + Send {
|
||||
fn enable(&self) -> Result<()>;
|
||||
fn disable(&self) -> Result<()>;
|
||||
|
@ -5,7 +5,7 @@ use std::io;
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use winapi::um::wincon;
|
||||
|
||||
/// This command is used for enabling and disabling raw mode for windows systems.
|
||||
/// 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 RawModeCommand {
|
||||
@ -48,7 +48,7 @@ impl RawModeCommand {
|
||||
}
|
||||
}
|
||||
|
||||
/// This command is used for switching to alternate screen and back to main screen.
|
||||
/// This command is used for switching to the alternate screen and back to the main screen.
|
||||
/// check https://docs.microsoft.com/en-us/windows/console/reading-and-writing-blocks-of-characters-and-attributes for more info
|
||||
pub struct ToAlternateScreenCommand;
|
||||
|
||||
|
@ -15,10 +15,10 @@
|
||||
|
||||
[s7]: https://travis-ci.org/TimonPost/crossterm.svg?branch=master
|
||||
|
||||
This crate allows you to style te terminal cross-platform.
|
||||
This crate allows you to style the terminal cross-platform.
|
||||
It 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 is a sub-crate of [crossterm](https://crates.io/crates/crossterm) to style te terminal, and can be use individually.
|
||||
This crate is a sub-crate of [crossterm](https://crates.io/crates/crossterm) to style the terminal, and can be use individually.
|
||||
|
||||
Other sub-crates are:
|
||||
- [Crossterm Input](https://crates.io/crates/crossterm_input)
|
||||
@ -82,7 +82,7 @@ These are the features of this crate:
|
||||
## Examples
|
||||
The [examples](./examples) folder has more complete and verbose examples.
|
||||
|
||||
_style font with attributes_
|
||||
_style text with attributes_
|
||||
```rust
|
||||
use crossterm_style::{Colored, Color, Colorize, Styler, Attribute};
|
||||
|
||||
@ -97,7 +97,7 @@ println!("{}", styled_text);
|
||||
let styled_text = style("Bold Underlined").bold().underlined();
|
||||
```
|
||||
|
||||
_style font with colors_
|
||||
_style text with colors_
|
||||
```rust
|
||||
use crossterm_style::{Colored, Color, Colorize};
|
||||
|
||||
@ -111,7 +111,7 @@ println!("{}", styled_text);
|
||||
// old-way but still usable
|
||||
let styled_text = style("Bold Underlined").with(Color::Red).on(Color::Blue);
|
||||
```
|
||||
_style font with RGB and ANSI Value_
|
||||
_style text with RGB and ANSI Value_
|
||||
```rust
|
||||
// custom rgb value (Windows 10 and UNIX systems)
|
||||
println!("{} some colored text", Colored::Fg(Color::Rgb {
|
||||
|
@ -8,13 +8,13 @@ use self::crossterm_style::{
|
||||
color, style, Attribute, Color, Colored, Colorize, Styler, TerminalColor,
|
||||
};
|
||||
|
||||
/// print some red font | demonstration.
|
||||
/// print some red text | demonstration.
|
||||
pub fn paint_foreground() {
|
||||
println!("{}", "Red foreground text: {}".red());
|
||||
println!("{} Red foreground text", Colored::Fg(Color::Red));
|
||||
}
|
||||
|
||||
/// print some font on red background | demonstration.
|
||||
/// print some text on red background | demonstration.
|
||||
pub fn paint_background() {
|
||||
println!("{}", "Red background text: {}".on_red());
|
||||
println!("{} Red background text", Colored::Bg(Color::Red));
|
||||
@ -347,9 +347,9 @@ pub fn print_all_background_colors_with_method() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
/// Print text with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
#[cfg(unix)]
|
||||
pub fn print_font_with_attributes() {
|
||||
pub fn print_text_with_attributes() {
|
||||
println!("{}", "Normal text");
|
||||
println!("{}", "Bold text".bold());
|
||||
println!("{}", "Italic text".italic());
|
||||
@ -359,7 +359,7 @@ pub fn print_font_with_attributes() {
|
||||
println!("{}", "Underlined text".underlined());
|
||||
println!("{}", "Reversed text".reverse());
|
||||
println!("{}", "Dim text".dim());
|
||||
println!("{}", "Crossed out font".crossed_out());
|
||||
println!("{}", "Crossed out text".crossed_out());
|
||||
// ...
|
||||
|
||||
println!(
|
||||
@ -370,9 +370,9 @@ pub fn print_font_with_attributes() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
// Print text with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
#[cfg(windows)]
|
||||
pub fn print_font_with_attributes() {
|
||||
pub fn print_text_with_attributes() {
|
||||
println!("{}", "Normal text");
|
||||
println!("{}", "Bold text".bold());
|
||||
println!("{}", "Underlined text".underlined());
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! A module that contains all the actions related to the styling of the terminal.
|
||||
//! Like applying attributes to font and changing the foreground and background.
|
||||
//! Like applying attributes to text and changing the foreground and background.
|
||||
|
||||
use std::io;
|
||||
|
||||
|
@ -2,8 +2,9 @@ use std::fmt::Display;
|
||||
use std::io::stdout;
|
||||
use std::io::Write;
|
||||
|
||||
/// These are all the attributes which **could** be apply to font.
|
||||
/// There are few things to note
|
||||
/// These are all the attributes which can be applied to text.
|
||||
///
|
||||
/// There are few things to note:
|
||||
/// - Not all attributes are supported, some of them are only supported on Windows some only on Unix,
|
||||
/// and some are only very rarely supported.
|
||||
/// - I got those attributes, descriptions, supportability from here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
|
||||
@ -36,18 +37,18 @@ pub enum Attribute {
|
||||
/// [Supportability]: Windows, UNIX.
|
||||
Reset = 0,
|
||||
/// Increased Intensity
|
||||
/// [info]: This will increase the font sensitivity also known as bold.
|
||||
/// [info]: This will increase the text sensitivity also known as bold.
|
||||
/// [Supportability]: Windows, UNIX.
|
||||
Bold = 1,
|
||||
/// Decreased Intensity
|
||||
/// [info]: This will decrease the font sensitivity also known as bold.
|
||||
/// [info]: This will decrease the text sensitivity also known as bold.
|
||||
/// [Supportability]: Windows, UNIX.
|
||||
Dim = 2,
|
||||
/// Italic Text
|
||||
/// [info]: This will make the font italic.
|
||||
/// [info]: This will make the text italic.
|
||||
/// [Supportability]: Not widely supported, sometimes treated as inverse.
|
||||
Italic = 3,
|
||||
/// This will draw a line under the font.
|
||||
/// This will draw a line under the text.
|
||||
/// [info]: An line under a word, especially in order to show its importance.
|
||||
/// [Supportability]: Windows, UNIX
|
||||
Underlined = 4,
|
||||
@ -63,13 +64,13 @@ pub enum Attribute {
|
||||
/// [info]: swap foreground and background colors
|
||||
/// [Supportability]: Windows, UNIX
|
||||
Reverse = 7,
|
||||
/// Hide font
|
||||
/// Hide text
|
||||
/// [info]:
|
||||
/// - This will make the font hidden.
|
||||
/// - This will make the text hidden.
|
||||
/// - Also known as 'Conceal'
|
||||
/// [Supportability]: Windows, UNIX
|
||||
Hidden = 8,
|
||||
/// Cross-out font
|
||||
/// Cross-out text
|
||||
/// [info]: Characters legible, but marked for deletion.
|
||||
/// [Supportability]: UNIX
|
||||
CrossedOut = 9,
|
||||
@ -107,7 +108,7 @@ pub enum Attribute {
|
||||
/// [info]: Opposite of `Reverse`(7)
|
||||
/// [Supportability]: Windows, unknown
|
||||
NoInverse = 27,
|
||||
/// This will make the font visible.
|
||||
/// This will make the text visible.
|
||||
/// [info]: Opposite of `Hidden`(8)
|
||||
/// [Supportability]: Unknown
|
||||
NoHidden = 28,
|
||||
@ -115,12 +116,12 @@ pub enum Attribute {
|
||||
/// [info]: Opposite of `CrossedOut`(9)
|
||||
/// [Supportability]: Not widely supported
|
||||
NotCrossedOut = 29,
|
||||
/// Framed font.
|
||||
/// Framed text.
|
||||
/// [Supportability]: Not widely supported
|
||||
Framed = 51,
|
||||
/// This will turn on the encircled attribute.
|
||||
Encircled = 52,
|
||||
/// This will draw a line at the top of the font.
|
||||
/// This will draw a line at the top of the text.
|
||||
/// [info]: Implementation defined (according to standard)
|
||||
/// [Supportability]: Unknown
|
||||
OverLined = 53,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::convert::AsRef;
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Colors that are available for coloring the terminal font.
|
||||
/// Colors that are available for coloring the terminal text.
|
||||
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
|
||||
pub enum Color {
|
||||
// This resets the color.
|
||||
@ -43,14 +43,14 @@ pub enum Color {
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for Color {
|
||||
/// Get an color from an &str like `Color::from("blue")`.
|
||||
/// Get a `Color` from a `&str` like `Color::from("blue")`.
|
||||
fn from(src: &str) -> Self {
|
||||
src.parse().unwrap_or(Color::White)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Color {
|
||||
/// Get an color from an &str like `Color::from(String::from(blue))`.
|
||||
/// Get a `Color` from a `&str` like `Color::from(String::from(blue))`.
|
||||
fn from(src: String) -> Self {
|
||||
src.parse().unwrap_or(Color::White)
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl From<String> for Color {
|
||||
impl FromStr for Color {
|
||||
type Err = ();
|
||||
|
||||
/// Convert a string to an Color value
|
||||
/// Convert a `&str` to a `Color` value
|
||||
fn from_str(src: &str) -> ::std::result::Result<Self, Self::Err> {
|
||||
let src = src.to_lowercase();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! A module that contains all the actions related to the styling of the terminal.
|
||||
//! Like applying attributes to font and changing the foreground and background.
|
||||
//! Like applying attributes to text and changing the foreground and background.
|
||||
|
||||
#[macro_use]
|
||||
extern crate crossterm_utils;
|
||||
@ -31,9 +31,9 @@ pub use self::styledobject::StyledObject;
|
||||
pub use self::traits::{Colorize, Styler};
|
||||
use crossterm_utils::Result;
|
||||
|
||||
/// This trait defines the actions that can be preformed with terminal color.
|
||||
/// This trait defines the actions that can be performed with terminal colors.
|
||||
/// This trait can be implemented so that a concrete implementation of the ITerminalColor can fulfill
|
||||
/// the wishes to work on an specific platform.
|
||||
/// the wishes to work on a specific platform.
|
||||
///
|
||||
/// ## For example:
|
||||
///
|
||||
@ -46,20 +46,20 @@ trait ITerminalColor {
|
||||
fn set_bg(&self, fg_color: Color) -> Result<()>;
|
||||
/// Reset the terminal color to default.
|
||||
fn reset(&self) -> Result<()>;
|
||||
/// Gets an value that represents an color from the given `Color` and `ColorType`.
|
||||
/// Gets an value that represents a color from the given `Color` and `ColorType`.
|
||||
fn color_value(&self, cored: Colored) -> String;
|
||||
}
|
||||
|
||||
/// This could be used to style a type who is implementing `Display` with colors and attributes.
|
||||
/// This could be used to style a type that implements `Display` with colors and attributes.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// // get an styled object which could be painted to the terminal.
|
||||
/// // get a 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);
|
||||
///
|
||||
/// // print the styled font * times to the current screen.
|
||||
/// // print the styled text * times to the current screen.
|
||||
/// for i in 1..10
|
||||
/// {
|
||||
/// println!("{}", styled_object);
|
||||
|
@ -6,7 +6,7 @@ use std::fmt::Display;
|
||||
|
||||
use super::Attribute;
|
||||
|
||||
/// Struct that contains the style properties that can be applied to an displayable object.
|
||||
/// Struct that contains the style properties that can be applied to a displayable object.
|
||||
#[derive(Clone)]
|
||||
pub struct ObjectStyle {
|
||||
pub fg_color: Option<Color>,
|
||||
@ -25,7 +25,7 @@ impl Default for ObjectStyle {
|
||||
}
|
||||
|
||||
impl ObjectStyle {
|
||||
/// Apply an `StyledObject` to the passed displayable object.
|
||||
/// Apply a `StyledObject` to the passed displayable object.
|
||||
pub fn apply_to<D: Display>(&self, val: D) -> StyledObject<D> {
|
||||
StyledObject {
|
||||
object_style: self.clone(),
|
||||
@ -33,7 +33,7 @@ impl ObjectStyle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an new instance of `ObjectStyle`
|
||||
/// Get a new instance of `ObjectStyle`
|
||||
pub fn new() -> ObjectStyle {
|
||||
ObjectStyle {
|
||||
fg_color: None,
|
||||
|
@ -8,7 +8,7 @@ use std::result;
|
||||
use super::Attribute;
|
||||
use crate::{Colorize, Styler};
|
||||
|
||||
/// Contains both the style and the content wits can be styled.
|
||||
/// Contains both the style and the content which can be styled.
|
||||
pub struct StyledObject<D: Display> {
|
||||
pub object_style: ObjectStyle,
|
||||
pub content: D,
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! This is an `WinApi` specific implementation for styling related action.
|
||||
//! This is a `WinApi` specific implementation for styling related action.
|
||||
//! This module is used for non supporting `ANSI` Windows terminals.
|
||||
|
||||
use crate::{Color, Colored, ITerminalColor};
|
||||
|
@ -16,7 +16,7 @@ pub use self::terminal::{terminal, Terminal};
|
||||
|
||||
use crossterm_utils::Result;
|
||||
|
||||
/// Enum that specifies a way of clearing.
|
||||
/// Enum that specifies ways of clearing the terminal.
|
||||
pub enum ClearType {
|
||||
/// clear all cells in terminal.
|
||||
All,
|
||||
@ -30,14 +30,14 @@ pub enum ClearType {
|
||||
UntilNewLine,
|
||||
}
|
||||
|
||||
/// This trait defines the actions that can be preformed with the terminal color.
|
||||
/// This trait defines the actions that can be performed with the terminal color.
|
||||
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can fulfill.
|
||||
/// the wishes to work on an specific platform.
|
||||
///
|
||||
/// ## For example:
|
||||
///
|
||||
/// This trait is implemented for `WinApi` (Windows specific) and `ANSI` (Unix specific),
|
||||
/// so that terminal related actions can be preformed on both Unix and Windows systems.
|
||||
/// so that terminal related actions can be performed on both Unix and Windows systems.
|
||||
trait ITerminal {
|
||||
/// Clear the current cursor by specifying the clear type
|
||||
fn clear(&self, clear_type: ClearType) -> Result<()>;
|
||||
|
@ -131,7 +131,7 @@ impl Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a `Terminal` instance whereon terminal related actions could performed.
|
||||
/// Get a `Terminal` instance whereon terminal related actions can be performed.
|
||||
pub fn terminal() -> Terminal {
|
||||
Terminal::new()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! This is an `WINAPI` specific implementation for terminal related action.
|
||||
//! This is a `WINAPI` specific implementation for terminal related action.
|
||||
//! This module is used for non supporting `ANSI` windows terminals.
|
||||
//!
|
||||
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
|
||||
@ -8,7 +8,7 @@ use crossterm_cursor::sys::winapi::Cursor;
|
||||
use crossterm_utils::{ErrorKind, Result};
|
||||
use crossterm_winapi::{Console, Coord, Handle, ScreenBuffer, Size};
|
||||
|
||||
/// This struct is an winapi implementation for terminal related actions.
|
||||
/// This struct is a winapi implementation for terminal related actions.
|
||||
pub struct WinApiTerminal;
|
||||
|
||||
impl WinApiTerminal {
|
||||
|
@ -8,7 +8,7 @@ use std::{
|
||||
/// The `crossterm` result type.
|
||||
pub type Result<T> = std::result::Result<T, ErrorKind>;
|
||||
|
||||
/// Wrapper for all errors who could occur in `crossterm`.
|
||||
/// Wrapper for all errors that can occur in `crossterm`.
|
||||
#[derive(Debug)]
|
||||
pub enum ErrorKind {
|
||||
IoError(io::Error),
|
||||
|
@ -119,7 +119,7 @@ impl Console {
|
||||
Ok(cells_written)
|
||||
}
|
||||
|
||||
/// Retrieves the size of the largest possible console window, based on the current font and the size of the display.
|
||||
/// Retrieves the size of the largest possible console window, based on the current text and the size of the display.
|
||||
///
|
||||
/// Wraps the underlying function call: [GetLargestConsoleWindowSize]
|
||||
/// link: [https://docs.microsoft.com/en-us/windows/console/getlargestconsolewindowsize]
|
||||
|
@ -215,10 +215,10 @@ if let Ok(alternate) = screen.enable_alternate_modes(false) {
|
||||
|
||||
***WARNING***
|
||||
|
||||
This new version contains some cool features but to get those features working I needed to add some user API braking changes.
|
||||
This new version contains some cool features but to get those features working I needed to add some user API breaking changes.
|
||||
I really did not want to do this but it had to be done for some reasons.
|
||||
|
||||
#### 1. You need to pass a reference to an `Screen` to the modules: `cursor(), color(), terminal()`
|
||||
#### 1. You need to pass a reference to a `Screen` to the modules: `cursor()`, `color()`, `terminal()`
|
||||
|
||||
_**old**_
|
||||
```
|
||||
@ -255,11 +255,11 @@ use crossterm::style::{Color, input, style};
|
||||
|
||||
// 1: use the `Crossterm` type
|
||||
let crossterm = Crossterm::new();
|
||||
let styled_object = crossterm.style("Red font on Black background").with(Color::Red).on(Color::Black);
|
||||
let styled_object = crossterm.style("Red text on Black background").with(Color::Red).on(Color::Black);
|
||||
styled_object.paint(&screen);
|
||||
|
||||
// 2: use the `Terminal` type
|
||||
let styled_object = style("Red font on Black background").with(Color::Red).on(Color::Black);
|
||||
let styled_object = style("Red text on Black background").with(Color::Red).on(Color::Black);
|
||||
styled_object.paint(&screen);
|
||||
|
||||
```
|
||||
|
@ -9,14 +9,14 @@ Crossterm provides two ways to read user input, synchronous and asynchronous.
|
||||
Read the input synchronously from the user, the reads performed will be blocking calls.
|
||||
Using synchronous over asynchronous reading has the benefit that it is using fewer resources than the asynchronous because background thread and queues are left away.
|
||||
|
||||
You can get an synchronous event reader by calling: `TerminalInput::read_sync`.
|
||||
You can get a synchronous event reader by calling: `TerminalInput::read_sync`.
|
||||
|
||||
### Asynchronous reading
|
||||
|
||||
Read the input asynchronously, input events are gathered on the background and will be queued for you to read.
|
||||
Using asynchronous reading has the benefit that input events are queued until you read them. You can poll for occurred events, and the reads won't block your program.
|
||||
|
||||
You can get an synchronous event reader by calling: `TerminalInput::read_async`, `TerminalInput::read_async_until`.
|
||||
You can get a synchronous event reader by calling: `TerminalInput::read_async`, `TerminalInput::read_async_until`.
|
||||
|
||||
### Technical details
|
||||
On UNIX systems crossterm reads from the TTY, on Windows, it uses `ReadConsoleInputW`.
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Styling Module
|
||||
|
||||
Crossterm provides options for you to style your font and terminal. Take for example coloring output and applying attributes.
|
||||
Crossterm provides options for you to style your text and terminal. Take for example coloring output and applying attributes.
|
||||
|
||||
**Color support**
|
||||
Windows systems with versions less than 10 will only have support for 16 colors and don't have any support for attributes. Most UNIX-terminal is supporting lots of colors and attributes.
|
||||
@ -32,10 +32,10 @@ Crossterm implements almost all attributes shown in this [Wikipedia-list](https:
|
||||
| Attribute | Support | Note |
|
||||
| :-------------: | :-------------: | :-------------: |
|
||||
| Reset | Windows, UNIX | This will reset all current set attributes. |
|
||||
| Bold | Windows, UNIX | This will increase the font sensitivity also known as bold. |
|
||||
| Dim | Windows, UNIX | This will decrease the font sensitivity also known as bold. |
|
||||
| Italic | Not widely supported, sometimes treated as inverse. | This will make the font italic. |
|
||||
| Underlined | Windows, UNIX | An line under a word, especially in order to show its importance. |
|
||||
| Bold | Windows, UNIX | This will increase the text sensitivity also known as bold. |
|
||||
| Dim | Windows, UNIX | This will decrease the text sensitivity also known as bold. |
|
||||
| Italic | Not widely supported, sometimes treated as inverse. | This will make the text italic. |
|
||||
| Underlined | Windows, UNIX | A line under a word, especially in order to show its importance. |
|
||||
| SlowBlink | Not widely supported, sometimes treated as inverse. | less than 150 per minute |
|
||||
| RapidBlink | Not widely supported | MS-DOS ANSI.SYS; 150+ per minute; |
|
||||
| Reverse | Windows, UNIX | foreground and background colors |
|
||||
@ -43,9 +43,9 @@ Crossterm implements almost all attributes shown in this [Wikipedia-list](https:
|
||||
| Fraktur | UNIX | characters legible, but marked for deletion. |
|
||||
| DefaultForegroundColor | Unknown | Implementation defined (according to standard) |
|
||||
| DefaultBackgroundColor | Unknown | Implementation defined (according to standard) |
|
||||
| Framed | Not widely supported | Framed font.
|
||||
| Framed | Not widely supported | Framed text.
|
||||
| Encircled | Unknown | This will turn on the encircled attribute. |
|
||||
| OverLined | Unknown | This will draw a line at the top of the font. |
|
||||
| OverLined | Unknown | This will draw a line at the top of the text. |
|
||||
|
||||
(There are a few attributes who disable one of the above attributes, I did not write those down to keep the list short).
|
||||
|
||||
|
@ -66,7 +66,7 @@ println!("{} some colored text", Colored::Fg(Color::AnsiValue(10)));
|
||||
```
|
||||
|
||||
## Attributes
|
||||
When working with UNIX or Windows 10 terminals you could also use attributes to style your font. For example, you could cross your text with a line and make it bold.
|
||||
When working with UNIX or Windows 10 terminals you could also use attributes to style your text. For example, you could cross your text with a line and make it bold.
|
||||
See [this](styling.md#Attributes) for more information.
|
||||
|
||||
### Using Enum
|
||||
|
@ -12,7 +12,7 @@ pub fn main() {
|
||||
let terminal = crossterm.terminal();
|
||||
let terminal = crossterm.input();
|
||||
let style = crossterm
|
||||
.style("Black font on green background")
|
||||
.style("Black text on green background")
|
||||
.with(Color::Black)
|
||||
.on(Color::Green);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//!
|
||||
//! Examples of actions that could be performed with te cursor.
|
||||
//! Examples of actions that could be performed with the cursor.
|
||||
//!
|
||||
|
||||
extern crate crossterm_cursor;
|
||||
|
@ -1,4 +1,4 @@
|
||||
This folder will contain some examples of how to use this crate in an real live environment.
|
||||
This folder will contain some examples of how to use this crate in a real live environment.
|
||||
|
||||
If you have created a game or something feel free to upload it, would be a great help for other people and me to make this crate better!
|
||||
|
||||
@ -6,7 +6,7 @@ The programs are:
|
||||
|
||||
- First depth search:
|
||||
|
||||
This is an search algorithm implemented visually. This program uses the following functionalities: cursor movement, coloring, alternate screen and terminal clearing.
|
||||
This is a search algorithm implemented visually. This program uses the following functionalities: cursor movement, coloring, alternate screen and terminal clearing.
|
||||
To run this use `cargo run` in the directory of first depth search.
|
||||
|
||||
- Snake
|
||||
@ -20,5 +20,5 @@ The programs are:
|
||||
|
||||
- Logging:
|
||||
|
||||
This is an async logging program to demonstrate asynchronous logging with an queue.
|
||||
This is an async logging program to demonstrate asynchronous logging with a queue.
|
||||
To run this use `cargo run --example logging`
|
@ -69,7 +69,7 @@ impl Map {
|
||||
self.map[y][x].visited
|
||||
}
|
||||
|
||||
// change an position in the map to visited.
|
||||
// change a position in the map to visited.
|
||||
pub fn set_visited(&mut self, x: usize, y: usize) {
|
||||
self.map[y][x].visited = true;
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ extern crate crossterm;
|
||||
|
||||
use self::crossterm::{color, Attribute, Color, Colored, Colorize, Styler};
|
||||
|
||||
/// print some red font | demonstration.
|
||||
/// print some red text | demonstration.
|
||||
pub fn paint_foreground() {
|
||||
println!("{}", "Red foreground text: {}".red());
|
||||
println!("{} Red foreground text", Colored::Fg(Color::Red));
|
||||
}
|
||||
|
||||
/// print some font on red background | demonstration.
|
||||
/// print some text on red background | demonstration.
|
||||
pub fn paint_background() {
|
||||
println!("{}", "Red background text: {}".on_red());
|
||||
println!("{} Red background text", Colored::Bg(Color::Red));
|
||||
@ -364,9 +364,9 @@ pub fn print_all_background_colors_with_method() {
|
||||
);
|
||||
}
|
||||
|
||||
/// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
/// Print text with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
#[cfg(unix)]
|
||||
pub fn print_font_with_attributes() {
|
||||
pub fn print_text_with_attributes() {
|
||||
println!("{}", "Normal text");
|
||||
println!("{}", "Bold text".bold());
|
||||
println!("{}", "Italic text".italic());
|
||||
@ -376,7 +376,7 @@ pub fn print_font_with_attributes() {
|
||||
println!("{}", "Underlined text".underlined());
|
||||
println!("{}", "Reversed text".reverse());
|
||||
println!("{}", "Dim text".dim());
|
||||
println!("{}", "Crossed out font".crossed_out());
|
||||
println!("{}", "Crossed out text".crossed_out());
|
||||
// ...
|
||||
|
||||
println!(
|
||||
@ -387,9 +387,9 @@ pub fn print_font_with_attributes() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// Print font with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
// Print text with all available attributes. Note that this can only be used at unix systems and that some are not supported widely | demonstration..
|
||||
#[cfg(windows)]
|
||||
pub fn print_font_with_attributes() {
|
||||
pub fn print_text_with_attributes() {
|
||||
println!("{}", "Normal text");
|
||||
println!("{}", "Bold text".bold());
|
||||
println!("{}", "Underlined text".underlined());
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
/// This type offers a easy way to use functionalities like `cursor, terminal, color, input, styling`.
|
||||
/// 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:
|
||||
///
|
||||
@ -11,7 +11,7 @@ use std::fmt::Display;
|
||||
// let terminal = crossterm.terminal();
|
||||
// let terminal = crossterm.input();
|
||||
// let style = crossterm
|
||||
// .style(format!("{} {}", 0, "Black font on green background"))
|
||||
// .style(format!("{} {}", 0, "Black text on green background"))
|
||||
// .with(Color::Black)
|
||||
// .on(Color::Green);
|
||||
/// ```
|
||||
@ -82,7 +82,7 @@ impl Crossterm {
|
||||
/// .with(Color::Blue)
|
||||
/// .on(Color::Black);
|
||||
///
|
||||
/// // print the styled font * times to the current screen.
|
||||
/// // print the styled text * times to the current screen.
|
||||
/// for i in 1..10
|
||||
/// {
|
||||
/// println!("{}", styled_object);
|
||||
|
Loading…
Reference in New Issue
Block a user