A simple CPU rendered GUI IDE experience.
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
use std::iter::{repeat, repeat_n};

use dsb::Cell;
use dsb::cell::Style;
use ropey::Rope;
#[derive(Debug, Default, Clone)]
pub struct TextArea {
    rope: Rope,
    cursor: usize,
}

impl TextArea {
    pub fn insert(&mut self, c: &str) {
        self.rope.insert(self.cursor, c);
        self.cursor += c.chars().count();
    }

    pub fn cells(
        &self,
        (c, r): (usize, usize),
        color: [u8; 3],
        bg: [u8; 3],
    ) -> Vec<Cell> {
        let mut cells = vec![
            Cell {
                style: Style {
                    color,
                    bg,
                    flags: 0,
                },
                letter: None,
            };
            c * r
        ];
        for (l, y) in self.rope.lines().take(r).zip(0..) {
            for (e, x) in l.chars().take(c).zip(0..) {
                cells[y * c + x].letter = Some(e);
            }
        }
        cells
    }
}