1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt::{Display, Formatter};
use crate::escape;

#[derive(Clone)]
pub struct ControlSequence {
    arguments: Vec<String>,
    end: String,
}

impl ControlSequence {
    pub fn new(from: &[&str], end: &str) -> Self {
        ControlSequence { arguments: from.iter().map(|s| s.to_string()).collect::<Vec<_>>(), end: end.to_string() }
    }
}

impl Display for ControlSequence {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}{}{}", escape::CSI, self.arguments.join(";"), self.end)
    }
}

pub mod rendition;
pub mod mode;
pub mod cursor;
pub mod area;
pub mod device {}
pub mod tabulation {}
pub mod view;

/// This function is a shorthand for :
/// ```
/// use coded_chars::control::area::{erase_in_page, AreaPosition};
/// use coded_chars::control::cursor::set_position;
/// print!(
///     "{}{}",
///     erase_in_page(
///         AreaPosition::Whole
///     ),
///     set_position(1, 1)
/// )
/// ```
/// 
/// The page is erased and the cursor position is set to the first line and the first column.
pub fn clear_screen() {
    print!("{}{}", area::erase_in_page(area::AreaPosition::Whole), cursor::set_position(1, 1))
}