From aecca6f229c5a0de9bd1cec6304ef32365cb03aa Mon Sep 17 00:00:00 2001 From: andromeda Date: Sun, 18 Jan 2026 11:45:10 +0100 Subject: [PATCH] cool keys, bound check printing, add backspace --- src/main.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 927e5ff..95fa2b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = keys .iter()