2018-03-11 03:33:06 +11:00
|
|
|
//! This is an `ANSI escape code` specific implementation for terminal related action.
|
|
|
|
//! This module is used for windows 10 terminals and unix terminals by default.
|
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
use super::{ClearType, ITerminal, Rc};
|
2018-07-10 03:37:07 +10:00
|
|
|
use super::super::cursor::cursor;
|
2018-07-02 06:43:43 +10:00
|
|
|
use shared::functions;
|
|
|
|
use Context;
|
2018-01-18 09:06:45 +11:00
|
|
|
|
|
|
|
/// This struct is an ansi implementation for terminal related actions.
|
2018-07-02 06:43:43 +10:00
|
|
|
pub struct AnsiTerminal {
|
|
|
|
context: Rc<Context>,
|
2018-06-23 05:04:30 +10:00
|
|
|
}
|
2018-01-18 09:06:45 +11:00
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
impl AnsiTerminal {
|
2018-06-23 05:04:30 +10:00
|
|
|
pub fn new(context: Rc<Context>) -> Box<AnsiTerminal> {
|
2018-07-02 06:43:43 +10:00
|
|
|
Box::from(AnsiTerminal { context: context })
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-04 03:17:28 +11:00
|
|
|
impl ITerminal for AnsiTerminal {
|
2018-07-02 06:43:43 +10:00
|
|
|
fn clear(&self, clear_type: ClearType) {
|
2018-06-23 05:04:30 +10:00
|
|
|
let mut screen_manager = self.context.screen_manager.lock().unwrap();
|
2018-06-10 05:59:43 +10:00
|
|
|
{
|
|
|
|
match clear_type {
|
|
|
|
ClearType::All => {
|
2018-07-09 06:13:32 +10:00
|
|
|
screen_manager.write_str(csi!("2J"));
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2018-06-10 05:59:43 +10:00
|
|
|
ClearType::FromCursorDown => {
|
2018-07-09 06:13:32 +10:00
|
|
|
screen_manager.write_str(csi!("J"));
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2018-06-10 05:59:43 +10:00
|
|
|
ClearType::FromCursorUp => {
|
2018-07-09 06:13:32 +10:00
|
|
|
screen_manager.write_str(csi!("1J"));
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2018-06-10 05:59:43 +10:00
|
|
|
ClearType::CurrentLine => {
|
2018-07-09 06:13:32 +10:00
|
|
|
screen_manager.write_str(csi!("2K"));
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2018-06-10 05:59:43 +10:00
|
|
|
ClearType::UntilNewLine => {
|
2018-07-09 06:13:32 +10:00
|
|
|
screen_manager.write_str(csi!("K"));
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2018-06-10 05:59:43 +10:00
|
|
|
};
|
|
|
|
}
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
fn terminal_size(&self) -> (u16, u16) {
|
2018-07-02 06:40:07 +10:00
|
|
|
functions::get_terminal_size(&self.context.screen_manager)
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
fn scroll_up(&self, count: i16) {
|
|
|
|
let mut screen = self.context.screen_manager.lock().unwrap();
|
2018-06-10 05:59:43 +10:00
|
|
|
{
|
2018-07-09 06:13:32 +10:00
|
|
|
screen.write_string(format!(csi!("{}S"), count));
|
2018-06-10 05:59:43 +10:00
|
|
|
}
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
fn scroll_down(&self, count: i16) {
|
|
|
|
let mut screen = self.context.screen_manager.lock().unwrap();
|
2018-06-10 05:59:43 +10:00
|
|
|
{
|
2018-07-09 06:13:32 +10:00
|
|
|
screen.write_string(format!(csi!("{}T"), count));
|
2018-06-10 05:59:43 +10:00
|
|
|
}
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|
2018-01-26 04:26:08 +11:00
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
fn set_size(&self, width: i16, height: i16) {
|
|
|
|
let mut screen = self.context.screen_manager.lock().unwrap();
|
2018-06-10 05:59:43 +10:00
|
|
|
{
|
2018-07-09 06:13:32 +10:00
|
|
|
screen.write_string(format!(csi!("8;{};{}t"), width, height));
|
2018-06-10 05:59:43 +10:00
|
|
|
}
|
2018-01-26 04:26:08 +11:00
|
|
|
}
|
2018-06-24 03:48:22 +10:00
|
|
|
|
2018-07-02 06:43:43 +10:00
|
|
|
fn exit(&self) {
|
2018-06-27 04:21:47 +10:00
|
|
|
functions::exit_terminal();
|
|
|
|
}
|
2018-01-18 09:06:45 +11:00
|
|
|
}
|