General Improvements (#177)

This commit is contained in:
Andrey Kutejko 2019-07-16 19:07:55 +02:00 committed by Timon
parent d689d7e8ed
commit 7260da18e1
4 changed files with 25 additions and 15 deletions

View File

@ -16,7 +16,7 @@ pub fn get_terminal_size() -> (u16, u16) {
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut size) };
if r == 0 {
(size.ws_co, size.ws_row)
(size.ws_col, size.ws_row)
} else {
(0, 0)
}

View File

@ -52,18 +52,20 @@ impl Terminal {
///
/// # Example
/// ```rust
/// # use crossterm_terminal as crossterm;
/// # use crossterm_terminal::terminal;
/// let mut term = terminal();
///
/// // clear all cells in terminal.
/// term.clear(terminal::ClearType::All);
/// term.clear(crossterm::ClearType::All);
/// // clear all cells from the cursor position downwards in terminal.
/// term.clear(terminal::ClearType::FromCursorDown);
/// term.clear(crossterm::ClearType::FromCursorDown);
/// // clear all cells from the cursor position upwards in terminal.
/// term.clear(terminal::ClearType::FromCursorUp);
/// term.clear(crossterm::ClearType::FromCursorUp);
/// // clear current line cells in terminal.
/// term.clear(terminal::ClearType::CurrentLine);
/// term.clear(crossterm::ClearType::CurrentLine);
/// // clear all cells from cursor position until new line in terminal.
/// term.clear(terminal::ClearType::UntilNewLine);
/// term.clear(crossterm::ClearType::UntilNewLine);
/// ```
pub fn clear(&self, clear_type: ClearType) -> Result<()> {
self.terminal.clear(clear_type)
@ -96,6 +98,7 @@ impl Terminal {
/// Set the terminal size. Note that not all terminals can be set to a very small scale.
///
/// ```rust
/// # use crossterm_terminal::terminal;
/// let mut term = terminal();
///
/// // Set of the size to X: 10 and Y: 10
@ -108,6 +111,7 @@ impl Terminal {
/// Exit the current process.
///
/// ```rust
/// # use crossterm_terminal::terminal;
/// let mut term = terminal();
///
/// let size = term.exit();
@ -119,6 +123,7 @@ impl Terminal {
/// Write any displayable content to the current terminal screen.
///
/// ```rust
/// # use crossterm_terminal::terminal;
/// let mut term = terminal();
///
/// let size = term.write("Some text \n Some text on new line");

View File

@ -1,5 +1,3 @@
use super::{AnsiTerminal, ITerminal, WinApiTerminal};
/* ======================== WinApi =========================== */
#[cfg(windows)]
mod winapi_tests {
@ -21,6 +19,7 @@ mod winapi_tests {
/* ======================== ANSI =========================== */
#[test]
fn resize_ansi() {
use super::*;
use std::{thread, time};
if try_enable_ansi() {
let terminal = AnsiTerminal::new();

View File

@ -5,15 +5,16 @@ use std::fmt::Display;
/// 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);
/// 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
@ -30,6 +31,7 @@ impl Crossterm {
/// Get a `TerminalCursor` implementation whereon cursor related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let cursor = crossterm.cursor();
/// ```
@ -41,6 +43,7 @@ impl Crossterm {
/// Get a `TerminalInput` implementation whereon terminal related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let input = crossterm.input();
/// ```
@ -52,6 +55,7 @@ impl Crossterm {
/// Get a `Terminal` implementation whereon terminal related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.terminal();
/// ```
@ -63,6 +67,7 @@ impl Crossterm {
/// Get a `TerminalColor` implementation whereon color related actions can be performed.
///
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
/// let mut terminal = crossterm.color();
/// ```
@ -75,6 +80,7 @@ impl Crossterm {
///
/// # Example
/// ```rust
/// # use crossterm::*;
/// let crossterm = Crossterm::new();
///
/// // get an styled object which could be painted to the terminal.