summaryrefslogtreecommitdiff
path: root/src/devices/system/read_only_text_buffer.rs
blob: 7c59025a7f3091bd75e63778621fabb34ebf6af4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pub struct ReadOnlyTextBuffer {
    chars: Vec<u8>,
    pointer: usize,
}

impl ReadOnlyTextBuffer {
    pub fn from_text(text: &str) -> Self {
        Self {
            chars: text.chars().map(|c| c as u32 as u8).collect(),
            pointer: 0,
        }
    }

    pub fn read_byte(&mut self) -> u8 {
        let byte = self.chars[self.pointer];
        self.pointer += 1;
        return byte;
    }

    pub fn reset_pointer(&mut self) {
        self.pointer = 0;
    }
}