1use std::ops::{Index, IndexMut};
2
3use crossterm::style::{Color, Stylize};
4
5#[derive(Clone)]
7pub struct Frame {
8 pub cols: usize,
9 pub rows: usize,
10 inner: Vec<Vec<<char as Stylize>::Styled>>,
11}
12
13impl Frame {
14 pub fn new(cols: usize, rows: usize) -> Self {
16 let inner = vec![vec![' '.with(Color::White); rows]; cols];
17 Self { cols, rows, inner }
18 }
19 pub fn clear(&mut self) {
21 for row in &mut self.inner {
22 row.fill(' '.with(Color::White));
23 }
24 }
25}
26
27impl Index<usize> for Frame {
29 type Output = Vec<<char as Stylize>::Styled>;
30
31 fn index(&self, index: usize) -> &Self::Output {
32 &self.inner[index]
33 }
34}
35
36impl IndexMut<usize> for Frame {
38 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
39 &mut self.inner[index]
40 }
41}