embedded_term/
text_buffer.rs1use crate::cell::Cell;
2
3pub trait TextBuffer {
5 fn width(&self) -> usize;
7
8 fn height(&self) -> usize;
10
11 fn read(&self, row: usize, col: usize) -> Cell;
15
16 fn write(&mut self, row: usize, col: usize, cell: Cell);
18
19 fn delete(&mut self, row: usize, col: usize) {
21 self.write(row, col, Cell::default());
22 }
23
24 fn new_line(&mut self, cell: Cell) {
29 for i in 1..self.height() {
30 for j in 0..self.width() {
31 self.write(i - 1, j, self.read(i, j));
32 }
33 }
34 for j in 0..self.width() {
35 self.write(self.height() - 1, j, cell);
36 }
37 }
38
39 fn clear(&mut self, cell: Cell) {
41 for i in 0..self.height() {
42 for j in 0..self.width() {
43 self.write(i, j, cell);
44 }
45 }
46 }
47}