frozen_term/
terminal_grid.rs

1use iced::advanced::text::{self};
2
3pub trait TerminalGrid {
4    fn advance_bytes(&mut self, bytes: &[u8]);
5    fn resize(&mut self, size: Size);
6
7    fn press_key(
8        &mut self,
9        key: iced::keyboard::Key,
10        modifiers: iced::keyboard::Modifiers,
11    ) -> Option<Vec<u8>>;
12    fn paste(&mut self, text: &str) -> Option<Vec<u8>>;
13
14    fn scroll(&mut self, lines: isize);
15    fn scroll_to(&mut self, y: usize);
16    fn get_scroll(&self) -> usize;
17    fn available_lines(&self) -> usize;
18
19    fn start_selection(&mut self, start: VisiblePosition);
20    fn move_selection(&mut self, end: VisiblePosition);
21    fn end_selection(&mut self);
22    fn currently_selecting(&self) -> bool;
23    fn selected_text(&self) -> Option<String>;
24
25    fn get_title(&self) -> &str;
26    fn get_size(&self) -> Size;
27    fn get_cursor(&self) -> Option<VisiblePosition>;
28}
29
30pub trait PreRenderer<R>
31where
32    R: text::Renderer,
33    R::Font: 'static,
34{
35    type Grid: TerminalGrid;
36
37    fn clear_cache(&mut self);
38    fn update(&mut self, grid: &Self::Grid, renderer: &R);
39    fn visible_rows<'a>(
40        &'a self,
41    ) -> impl Iterator<Item = Option<(&'a R::Paragraph, &'a [text::Span<'a, (), R::Font>])>>;
42}
43
44#[derive(Debug, Clone, Copy)]
45pub struct Size {
46    pub cols: usize,
47    pub rows: usize,
48}
49
50#[derive(Debug, Clone, PartialEq)]
51pub struct VisiblePosition {
52    pub x: usize,
53    pub y: usize,
54}