diff options
| author | Adandi <rwindowed@gmail.com> | 2025-03-21 15:57:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-21 15:57:22 +0200 |
| commit | 018d4287dc2a564b2daf8d595692024b91681ea3 (patch) | |
| tree | 8a84529a6f08138d2842718b21430475dca4b46a /src/input.rs | |
| parent | 1fcd3aa2098de576f5551af0c332665f9233eb4c (diff) | |
Add files via upload
Diffstat (limited to 'src/input.rs')
| -rw-r--r-- | src/input.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..0db7e16 --- /dev/null +++ b/src/input.rs @@ -0,0 +1,23 @@ +use std::{io, time::Duration}; +use crossterm::{event::{self, KeyCode, KeyEvent}}; + +pub fn handle_input(cursor: &mut usize, data: &mut [u8]) -> 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::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; + } + _ => {} + } + } + } + Ok(true) +} |
