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 47 48 49 50 51 52
use prototty::*; use text_info::TextInfo; #[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)] pub struct StringView; impl<T: AsRef<str>> View<T> for StringView { fn view<G: ViewGrid>(&mut self, string: &T, offset: Coord, depth: i32, grid: &mut G) { let string = string.as_ref(); for (i, ch) in string.chars().enumerate() { if let Some(cell) = grid.get_mut(offset + Coord::new(i as i32, 0), depth) { cell.set_character(ch); } } } } impl<T: AsRef<str>> ViewSize<T> for StringView { fn size(&mut self, string: &T) -> Size { let string = string.as_ref(); Size::new(string.len() as u32, 1) } } #[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)] pub struct RichStringView { pub info: TextInfo, } impl RichStringView { pub fn new() -> Self { Default::default() } } impl<T: AsRef<str>> View<T> for RichStringView { fn view<G: ViewGrid>(&mut self, string: &T, offset: Coord, depth: i32, grid: &mut G) { let string = string.as_ref(); for (i, ch) in string.chars().enumerate() { if let Some(cell) = grid.get_mut(offset + Coord::new(i as i32, 0), depth) { cell.set_character(ch); self.info.write_cell(cell); } } } } impl<T: AsRef<str>> ViewSize<T> for RichStringView { fn size(&mut self, string: &T) -> Size { let string = string.as_ref(); Size::new(string.len() as u32, 1) } }