diff options
| author | Namilskyy <alive6863@gmail.com> | 2025-04-01 22:29:47 +0300 |
|---|---|---|
| committer | Namilskyy <alive6863@gmail.com> | 2025-04-01 22:31:49 +0300 |
| commit | c9bca4946f43629e9b5a3f6549dc3851c6e713b3 (patch) | |
| tree | 5548312adc31c3299f1c74d7b0dee6589ff0214e /src/input.rs | |
| parent | 0b069b828d117655053bd8972e32424ec78cbdb5 (diff) | |
Implemented the scrolling fucntion
Diffstat (limited to 'src/input.rs')
| -rw-r--r-- | src/input.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/input.rs b/src/input.rs index 0db7e16..1258ac0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,20 +1,35 @@ use std::{io, time::Duration}; use crossterm::{event::{self, KeyCode, KeyEvent}}; -pub fn handle_input(cursor: &mut usize, data: &mut [u8]) -> io::Result<bool> { +pub fn handle_input( + cursor: &mut usize, + data: &mut [u8], + scroll_position: &mut usize +) -> io::Result<bool> { if event::poll(Duration::from_millis(100))? { if let event::Event::Key(KeyEvent { code, .. }) = event::read()? { match code { KeyCode::Esc => return Ok(false), KeyCode::Left if *cursor > 0 => *cursor -= 1, KeyCode::Right if *cursor < data.len() * 2 - 1 => *cursor += 1, - KeyCode::Up if *cursor >= 32 => *cursor -= 32, - KeyCode::Down if *cursor + 32 < data.len() * 2 => *cursor += 32, + KeyCode::Up => { + if *cursor >= 32 { + *cursor -= 32; + *scroll_position = scroll_position.saturating_sub(1); + } + }, + KeyCode::Down => { + if *cursor + 32 < data.len() * 2 { + *cursor += 32; + *scroll_position = scroll_position.saturating_add(1); + } + }, KeyCode::Char(c) if c.is_ascii_hexdigit() => { let byte_index = *cursor / 2; let shift = if *cursor % 2 == 0 { 4 } else { 0 }; - data[byte_index] = (data[byte_index] & (0x0F << (4 - shift))) | (c.to_digit(16).unwrap() as u8) << shift; - } + data[byte_index] = (data[byte_index] & (0x0f << (4 - shift))) + | (c.to_digit(16).unwrap() as u8) << shift; + }, _ => {} } } |
