pub struct ScreenParser {
parser: vt100::Parser,
}
impl ScreenParser {
pub fn new(rows: u16, cols: u16) -> Self {
Self {
parser: vt100::Parser::new(rows, cols, 0),
}
}
pub fn default_size() -> Self {
Self::new(24, 80)
}
pub fn process(&mut self, data: &[u8]) {
self.parser.process(data);
}
pub fn contents(&self) -> String {
self.parser.screen().contents()
}
pub fn row_text(&self, row: u16) -> String {
let screen = self.parser.screen();
let (rows, cols) = screen.size();
if row >= rows {
return String::new();
}
screen.contents_between(row, 0, row, cols - 1)
}
pub fn cursor_position(&self) -> (u16, u16) {
self.parser.screen().cursor_position()
}
pub fn size(&self) -> (u16, u16) {
self.parser.screen().size()
}
}
impl Default for ScreenParser {
fn default() -> Self {
Self::default_size()
}
}