cool keys, bound check printing, add backspace

This commit is contained in:
andromeda
2026-01-18 11:45:10 +01:00
parent b3e784fa97
commit aecca6f229

View File

@@ -73,8 +73,22 @@ impl Model {
impl Perform for Model {
// draw a character to the screen and update states
fn print(&mut self, c: char) {
if self.cursor.col < self.buffer.width {
// scrolls
while self.cursor.row >= self.buffer.height {
for row in 0..(self.buffer.height - 1) {
for col in 0..self.buffer.width {
self.buffer.set(col, row, self.buffer.get(col, row + 1));
};
};
for col in 0..self.buffer.width {
self.buffer.set(col, self.buffer.height - 1, None);
}
self.cursor.row -= 1;
};
self.buffer.set(self.cursor.col, self.cursor.row, Some(c));
self.cursor.col += 1;
}
println!("[print] {:?}", c);
}
@@ -83,6 +97,10 @@ impl Perform for Model {
match byte {
0x0D => self.cursor.col = 0,
0x0A => self.cursor.row = self.cursor.row + 1,
0x08 => {
self.cursor.col = self.cursor.col - 1;
self.buffer.set(self.cursor.col, self.cursor.row, None);
},
_ => (),
}
println!("[execute] {:02x}", byte);
@@ -241,10 +259,9 @@ fn main() {
Err(_e) => (),
};
let keys = window.get_keys_pressed(KeyRepeat::No);
if !keys.is_empty() { println!("{:?}", keys); }
let shift = window.is_key_down(Key::LeftShift);
let ctrl = window.is_key_down(Key::LeftCtrl);
let keys = window.get_keys_pressed(KeyRepeat::Yes);
let shift = window.is_key_down(Key::LeftShift) || window.is_key_down(Key::RightShift) || window.is_key_down(Key::CapsLock);
let ctrl = window.is_key_down(Key::LeftCtrl) || window.is_key_down(Key::RightCtrl);
if !keys.is_empty() {
let bytes: Vec<u8> = keys
.iter()