From 338a8a734b8998d71063e8417ed2ef1f9297a69e Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Thu, 13 Jul 2023 15:22:56 +0200 Subject: [PATCH 1/4] Add PageUp and PageDown support to keyboard --- src/sys/keyboard.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/sys/keyboard.rs b/src/sys/keyboard.rs index 08ac6d960..26103f820 100644 --- a/src/sys/keyboard.rs +++ b/src/sys/keyboard.rs @@ -68,10 +68,12 @@ fn send_key(c: char) { sys::console::key_handle(c); } -fn send_csi(c: char) { +fn send_csi(code: &str) { send_key('\x1B'); // ESC send_key('['); - send_key(c); + for c in code.chars() { + send_key(c); + } } fn interrupt_handler() { @@ -91,11 +93,13 @@ fn interrupt_handler() { if let Some(key) = keyboard.process_keyevent(event) { match key { DecodedKey::Unicode('\u{7f}') if is_alt && is_ctrl => syscall::reboot(), // Ctrl-Alt-Del - DecodedKey::RawKey(KeyCode::ArrowUp) => send_csi('A'), - DecodedKey::RawKey(KeyCode::ArrowDown) => send_csi('B'), - DecodedKey::RawKey(KeyCode::ArrowRight) => send_csi('C'), - DecodedKey::RawKey(KeyCode::ArrowLeft) => send_csi('D'), - DecodedKey::Unicode('\t') if is_shift => send_csi('Z'), // Convert Shift-Tab into Backtab + DecodedKey::RawKey(KeyCode::PageUp) => send_csi("5~"), + DecodedKey::RawKey(KeyCode::PageDown) => send_csi("6~"), + DecodedKey::RawKey(KeyCode::ArrowUp) => send_csi("A"), + DecodedKey::RawKey(KeyCode::ArrowDown) => send_csi("B"), + DecodedKey::RawKey(KeyCode::ArrowRight) => send_csi("C"), + DecodedKey::RawKey(KeyCode::ArrowLeft) => send_csi("D"), + DecodedKey::Unicode('\t') if is_shift => send_csi("Z"), // Convert Shift-Tab into Backtab DecodedKey::Unicode(c) => send_key(c), _ => {}, }; From dcef570d0c657c2a70378aab5b0f8928f7c0de47 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Thu, 13 Jul 2023 15:23:11 +0200 Subject: [PATCH 2/4] Add support in editor --- src/usr/editor.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/usr/editor.rs b/src/usr/editor.rs index 500436c39..93e40a31f 100644 --- a/src/usr/editor.rs +++ b/src/usr/editor.rs @@ -245,6 +245,7 @@ impl Editor { let mut escape = false; let mut csi = false; + let mut csi_params = String::new(); loop { let c = io::stdin().read_char().unwrap_or('\0'); print!("\x1b[?25l"); // Disable cursor @@ -296,7 +297,17 @@ impl Editor { self.offset.x = 0; self.print_screen(); }, - 'A' if csi => { // Arrow up + '~' if csi && csi_params == "5" => { // Page Up + let scroll = self.rows() - 1; // Keep one previous line on screen + self.offset.y -= cmp::min(scroll, self.offset.y); + self.print_screen(); + }, + '~' if csi && csi_params == "6" => { // Page Down + let scroll = self.rows() - 1; // Keep one previous line on screen + self.offset.y += cmp::min(scroll, (self.lines.len() - 2) - self.offset.y); + self.print_screen(); + }, + 'A' if csi => { // Arrow Up if self.cursor.y > 0 { self.cursor.y -= 1 } else if self.offset.y > 0 { @@ -305,7 +316,7 @@ impl Editor { } self.cursor.x = self.next_pos(self.cursor.x, self.cursor.y); }, - 'B' if csi => { // Arrow down + 'B' if csi => { // Arrow Down let is_eof = self.offset.y + self.cursor.y == self.lines.len() - 1; let is_bottom = self.cursor.y == self.rows() - 1; if self.cursor.y < cmp::min(self.rows(), self.lines.len() - 1) { @@ -320,7 +331,7 @@ impl Editor { self.cursor.x = self.next_pos(self.cursor.x, self.cursor.y); } }, - 'C' if csi => { // Arrow right + 'C' if csi => { // Arrow Right let line = &self.lines[self.offset.y + self.cursor.y]; if line.is_empty() || self.cursor.x + self.offset.x >= line.chars().count() { print!("\x1b[?25h"); // Enable cursor @@ -333,7 +344,7 @@ impl Editor { self.cursor.x += 1; } }, - 'D' if csi => { // Arrow left + 'D' if csi => { // Arrow Left if self.cursor.x + self.offset.x == 0 { print!("\x1b[?25h"); // Enable cursor continue; @@ -465,6 +476,10 @@ impl Editor { print!("\x1b[2K\x1b[1G{}", line); } }, + c if csi => { + csi_params.push(c); + continue; + }, c => { if let Some(s) = self.render_char(c) { let y = self.offset.y + self.cursor.y; @@ -487,6 +502,7 @@ impl Editor { } escape = false; csi = false; + csi_params = String::new(); self.print_editing_status(); self.print_highlighted(); print!("\x1b[{};{}H", self.cursor.y + 1, self.cursor.x + 1); From 11a6553925c7d469bb174df08b84d410c0bdf7e0 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sat, 15 Jul 2023 10:51:18 +0200 Subject: [PATCH 3/4] Fix edge cases --- src/usr/editor.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/usr/editor.rs b/src/usr/editor.rs index 93e40a31f..a38a34f92 100644 --- a/src/usr/editor.rs +++ b/src/usr/editor.rs @@ -304,7 +304,11 @@ impl Editor { }, '~' if csi && csi_params == "6" => { // Page Down let scroll = self.rows() - 1; // Keep one previous line on screen - self.offset.y += cmp::min(scroll, (self.lines.len() - 2) - self.offset.y); + let remaining = cmp::max(self.lines.len(), 1) - self.offset.y - 1; + self.offset.y += cmp::min(scroll, remaining); + if self.cursor.y + scroll > remaining { + self.cursor.y = 0; + } self.print_screen(); }, 'A' if csi => { // Arrow Up From 0b07088160f424f2b41b05c4a80ed76e4ae48c04 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sat, 15 Jul 2023 12:38:07 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd1e559b6..b74cccabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog ## Unreleased +- Add PageUp and PageDown keys support ([#515](https://github.com/vinc/moros/pull/515)) +- Bump pbkdf2 from 0.12.1 to 0.12.2 ([#513](https://github.com/vinc/moros/pull/513)) +- Bump uart_16550 from 0.2.18 to 0.2.19 ([#514](https://github.com/vinc/moros/pull/514)) - Add namespaces to lisp ([#511](https://github.com/vinc/moros/pull/511)) - Update smoltcp from 0.9.1 to 0.10.0 ([#510](https://github.com/vinc/moros/pull/510))