summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-01-18 11:45:10 +0100
committerandromeda <andromeda@lenovo>2026-01-18 11:45:10 +0100
commitaecca6f229c5a0de9bd1cec6304ef32365cb03aa (patch)
tree558872b06a389b8cfa02b66d79fa9857d75c4c20 /src/main.rs
parentb3e784fa97f68e2e458c632b57d71d89d061d675 (diff)
cool keys, bound check printing, add backspace
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs25
1 files 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<u8> = keys
.iter()