2018-11-29 02:42:05 +11:00
|
|
|
//! A module that contains all the actions related to the terminal. like clearing, resizing, pausing and scrolling the terminal.
|
2018-09-22 06:22:25 +10:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test;
|
|
|
|
|
2018-11-29 02:42:05 +11:00
|
|
|
mod terminal;
|
2018-01-18 09:06:45 +11:00
|
|
|
|
2018-07-31 05:35:35 +10:00
|
|
|
mod ansi_terminal;
|
2019-04-11 07:46:30 +10:00
|
|
|
#[cfg(windows)]
|
2018-01-18 09:06:45 +11:00
|
|
|
mod winapi_terminal;
|
|
|
|
|
2018-07-31 05:35:35 +10:00
|
|
|
use self::ansi_terminal::AnsiTerminal;
|
2019-04-11 07:46:30 +10:00
|
|
|
#[cfg(windows)]
|
2018-06-17 04:10:51 +10:00
|
|
|
use self::winapi_terminal::WinApiTerminal;
|
|
|
|
|
2019-07-25 04:10:27 +10:00
|
|
|
pub use self::terminal::{terminal, Clear, ScrollDown, ScrollUp, SetSize, Terminal};
|
2019-01-28 07:16:14 +11:00
|
|
|
|
2019-04-11 07:46:30 +10:00
|
|
|
use crossterm_utils::Result;
|
2018-06-17 04:10:51 +10:00
|
|
|
|
2019-07-25 04:10:27 +10:00
|
|
|
/// Enum with the different values to clear the terminal.
|
|
|
|
#[derive(Clone)]
|
2018-03-06 08:06:43 +11:00
|
|
|
pub enum ClearType {
|
2019-01-28 07:16:14 +11:00
|
|
|
/// clear all cells in terminal.
|
2018-03-06 08:06:43 +11:00
|
|
|
All,
|
2019-01-28 07:16:14 +11:00
|
|
|
/// clear all cells from the cursor position downwards in terminal.
|
2018-03-06 08:06:43 +11:00
|
|
|
FromCursorDown,
|
2019-01-28 07:16:14 +11:00
|
|
|
/// clear all cells from the cursor position upwards in terminal.
|
2018-03-06 08:06:43 +11:00
|
|
|
FromCursorUp,
|
2019-01-28 07:16:14 +11:00
|
|
|
/// clear current line cells in terminal.
|
2018-03-06 08:06:43 +11:00
|
|
|
CurrentLine,
|
2019-01-28 07:16:14 +11:00
|
|
|
/// clear all cells from cursor position until new line in terminal.
|
2018-03-06 08:06:43 +11:00
|
|
|
UntilNewLine,
|
|
|
|
}
|
|
|
|
|
2019-06-22 02:10:46 +10:00
|
|
|
/// This trait defines the actions that can be performed with the terminal color.
|
2018-11-29 02:42:05 +11:00
|
|
|
/// This trait can be implemented so that an concrete implementation of the ITerminalColor can fulfill.
|
2018-07-30 05:30:09 +10:00
|
|
|
/// the wishes to work on an specific platform.
|
|
|
|
///
|
|
|
|
/// ## For example:
|
|
|
|
///
|
2018-11-29 02:42:05 +11:00
|
|
|
/// This trait is implemented for `WinApi` (Windows specific) and `ANSI` (Unix specific),
|
2019-06-22 02:10:46 +10:00
|
|
|
/// so that terminal related actions can be performed on both Unix and Windows systems.
|
2018-08-15 07:02:25 +10:00
|
|
|
trait ITerminal {
|
2018-03-06 08:06:43 +11:00
|
|
|
/// Clear the current cursor by specifying the clear type
|
2019-04-11 07:46:30 +10:00
|
|
|
fn clear(&self, clear_type: ClearType) -> Result<()>;
|
2018-03-06 08:06:43 +11:00
|
|
|
/// Get the terminal size (x,y)
|
2019-04-11 07:46:30 +10:00
|
|
|
fn terminal_size(&self) -> (u16, u16);
|
2018-03-06 08:06:43 +11:00
|
|
|
/// Scroll `n` lines up in the current terminal.
|
2019-04-11 07:46:30 +10:00
|
|
|
fn scroll_up(&self, count: i16) -> Result<()>;
|
2018-03-06 08:06:43 +11:00
|
|
|
/// Scroll `n` lines down in the current terminal.
|
2019-04-11 07:46:30 +10:00
|
|
|
fn scroll_down(&self, count: i16) -> Result<()>;
|
2018-03-06 08:06:43 +11:00
|
|
|
/// Resize terminal to the given width and height.
|
2019-04-11 07:46:30 +10:00
|
|
|
fn set_size(&self, width: i16, height: i16) -> Result<()>;
|
2018-03-06 08:06:43 +11:00
|
|
|
}
|