From 2da0604391e857b45a706ce9085feb6ea58f252e Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Fri, 20 Jun 2025 15:19:18 +0300 Subject: [PATCH] sysutils/top: add down/up keys --- userspace/graphics/term/src/escape.rs | 4 ++++ userspace/lib/libterm/src/lib.rs | 10 +--------- userspace/sysutils/src/top.rs | 4 ++-- userspace/sysutils/src/tst.rs | 3 --- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/userspace/graphics/term/src/escape.rs b/userspace/graphics/term/src/escape.rs index 369b9f17..161d86f8 100644 --- a/userspace/graphics/term/src/escape.rs +++ b/userspace/graphics/term/src/escape.rs @@ -8,6 +8,8 @@ pub const KEY_ENTER: &[u8] = b"\x0D"; pub const KEY_ESCAPE: &[u8] = b"\x1B"; pub const KEY_HOME: &[u8] = b"\x1B[H"; pub const KEY_END: &[u8] = b"\x1B[F"; +pub const KEY_PAGEUP: &[u8] = b"\x1B[5~"; +pub const KEY_PAGEDOWN: &[u8] = b"\x1B[6~"; pub fn map(modifier: KeyModifiers, key: Key) -> Option<&'static [u8]> { match (modifier, key) { @@ -19,6 +21,8 @@ pub fn map(modifier: KeyModifiers, key: Key) -> Option<&'static [u8]> { (KeyModifiers::NONE, Key::Left) => Some(KEY_LEFT), (KeyModifiers::NONE, Key::Home) => Some(KEY_HOME), (KeyModifiers::NONE, Key::End) => Some(KEY_END), + (KeyModifiers::NONE, Key::PageUp) => Some(KEY_PAGEUP), + (KeyModifiers::NONE, Key::PageDown) => Some(KEY_PAGEDOWN), _ => None, } } diff --git a/userspace/lib/libterm/src/lib.rs b/userspace/lib/libterm/src/lib.rs index 29cd7fea..59124921 100644 --- a/userspace/lib/libterm/src/lib.rs +++ b/userspace/lib/libterm/src/lib.rs @@ -156,15 +156,7 @@ impl Term { } pub fn set_cursor_visible(&mut self, visible: bool) -> io::Result<()> { - #[cfg(unix)] - { - self.stdout.raw_set_cursor_visible(visible) - } - #[cfg(target_os = "yggdrasil")] - { - let _ = visible; - Ok(()) - } + self.stdout.raw_set_cursor_visible(visible) } pub fn set_cursor_style(&mut self, style: CursorStyle) -> io::Result<()> { self.stdout.raw_set_cursor_style(style) diff --git a/userspace/sysutils/src/top.rs b/userspace/sysutils/src/top.rs index e9dcf042..faa0f1e7 100644 --- a/userspace/sysutils/src/top.rs +++ b/userspace/sysutils/src/top.rs @@ -262,10 +262,10 @@ fn run() -> io::Result<()> { log::error!("Kill: {error}"); } } - TermKey::Char('k') => { + TermKey::Char('k') | TermKey::Up => { state.prev(); } - TermKey::Char('j') => { + TermKey::Char('j') | TermKey::Down => { state.next(); } _ => (), diff --git a/userspace/sysutils/src/tst.rs b/userspace/sysutils/src/tst.rs index 73eedcc2..ff7fecb4 100644 --- a/userspace/sysutils/src/tst.rs +++ b/userspace/sysutils/src/tst.rs @@ -13,9 +13,6 @@ fn main() { term.set_cursor_position(i, 0).ok(); write!(term, "{key:?}").ok(); } - let (row, column) = term.report_cursor_position().unwrap().unwrap(); - term.set_cursor_position(25, 0).ok(); - write!(term, "row = {row}, column = {column}").ok(); term.flush().ok(); let key = term.read_key().unwrap();