minicrossterm/src/terminal/mod.rs

54 lines
1.6 KiB
Rust
Raw Normal View History

//! Module that contains all the actions related to the terminal.
//!
//! We can think of:
//! - alternate screen
//! - raw mode
//! - clearing resizing scrolling the terminal.
//!
pub mod terminal;
2018-07-02 06:43:43 +10:00
mod ansi_terminal;
2018-03-04 03:07:51 +11:00
#[cfg(target_os = "windows")]
mod winapi_terminal;
2018-07-02 06:43:43 +10:00
use self::ansi_terminal::AnsiTerminal;
#[cfg(target_os = "windows")]
use self::winapi_terminal::WinApiTerminal;
use std::rc::Rc;
2018-07-02 06:43:43 +10:00
pub use self::terminal::terminal;
use Context;
/// Enum that can be used for the kind of clearing that can be done in the terminal.
pub enum ClearType {
All,
FromCursorDown,
FromCursorUp,
CurrentLine,
UntilNewLine,
}
///! This trait defines the actions that can be preformed with the terminal.
///! This trait can be implemented so that an concrete implementation of the ITerminal can forfill
///! the wishes to work on an specific platform.
///!
///! ## For example:
///!
///! This trait is implemented for `WINAPI` (Windows specific) and `ANSI` (Unix specific),
///! so that cursor related actions can be preformed on both unix and windows systems.
pub trait ITerminal {
/// Clear the current cursor by specifying the clear type
fn clear(&self, clear_type: ClearType);
/// Get the terminal size (x,y)
fn terminal_size(&self) -> (u16, u16);
/// Scroll `n` lines up in the current terminal.
fn scroll_up(&self, count: i16);
/// Scroll `n` lines down in the current terminal.
fn scroll_down(&self, count: i16);
/// Resize terminal to the given width and height.
2018-07-02 06:43:43 +10:00
fn set_size(&self, width: i16, height: i16);
2018-06-27 04:21:47 +10:00
/// Close the current terminal
fn exit(&self);
}