diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-05 01:32:25 -0500 |
commit | 4b4a9c18e4c55a2ba6558ef614292db9c18ab88a (patch) | |
tree | 03c9ada690835acbf3d1b02f46341bde5b579989 /src/parser.rs | |
parent | 59e7c620a516278719c1689ebebeb558bede5b60 (diff) | |
download | vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.tar.gz vt100-rust-4b4a9c18e4c55a2ba6558ef614292db9c18ab88a.zip |
expose the screen separately from the parser
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..2e27399 --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,33 @@ +pub struct Parser { + parser: vte::Parser, + screen: crate::screen::Screen, +} + +impl Parser { + /// Creates a new terminal parser of the given size. + pub fn new(rows: u16, cols: u16) -> Self { + Self { + parser: vte::Parser::new(), + screen: crate::screen::Screen::new(crate::grid::Size { + rows, + cols, + }), + } + } + + /// Processes the contents of the given byte string, and updates the + /// in-memory terminal state. + pub fn process(&mut self, bytes: &[u8]) { + for byte in bytes { + self.parser.advance(&mut self.screen, *byte); + } + } + + pub fn screen(&self) -> &crate::screen::Screen { + &self.screen + } + + pub fn screen_mut(&mut self) -> &mut crate::screen::Screen { + &mut self.screen + } +} |