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