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
use prototty::*; use prototty_grid::*; use terminal::Terminal; use cell::Colour; pub struct Context { terminal: Terminal, grid: Grid<Colour, Colour>, } impl Context { pub fn new() -> Self { let terminal = Terminal::new(); let grid = Grid::new(terminal.size()); Self { terminal, grid } } pub fn quit(&self) { self.terminal.quit(); } } impl Renderer for Context { type Error = (); fn render_at<V: View<T>, T>( &mut self, view: &mut V, data: &T, offset: Coord, depth: i32, ) -> Result<(), Self::Error> { self.grid.clear(); view.view(data, offset, depth, &mut self.grid); self.terminal.draw_grid(&self.grid); Ok(()) } fn size(&self) -> Size { self.terminal.size() } }