highlight spaces between bytes when selected

This commit is contained in:
alice pellerin
2026-03-16 23:26:06 -05:00
parent 7a18c6cbfe
commit ce19c3eb9c
5 changed files with 106 additions and 55 deletions
+3 -3
View File
@@ -98,13 +98,13 @@ impl App {
}
}
Event::Key(key_event) if key_event.code == KeyCode::Char('w') => {
self.cursor.to_next_word(self.contents.len() - 1);
self.cursor.move_to_next_word(self.contents.len() - 1);
}
Event::Key(key_event) if key_event.code == KeyCode::Char('e') => {
self.cursor.to_next_end(self.contents.len() - 1);
self.cursor.move_to_next_end(self.contents.len() - 1);
}
Event::Key(key_event) if key_event.code == KeyCode::Char('b') => {
self.cursor.to_previous_beginning();
self.cursor.move_to_previous_beginning();
}
Event::Key(key_event) if key_event.code == KeyCode::Char(';') => {
self.cursor.collapse();
+38 -5
View File
@@ -53,11 +53,11 @@ mod address {
}
mod hex {
use std::{borrow::Cow, mem};
use std::{borrow::Cow, iter, mem};
use itertools::Itertools;
use ratatui::{style::{Color, Style, Stylize}, text::Span};
use crate::{BYTES_PER_LINE, BYTES_PER_CHUNK, app::App, cardinality::HasCardinality, empty_span::empty_span, cursor::InCursor};
use crate::{BYTES_PER_CHUNK, BYTES_PER_LINE, CHUNKS_PER_LINE, app::App, cardinality::HasCardinality, cursor::InCursor, empty_span::empty_span, select_grey::SelectGrey};
impl App {
pub fn render_chunks(
@@ -75,7 +75,13 @@ mod hex {
.copied()
.zip((address..).step_by(BYTES_PER_CHUNK))
.map(|(chunk, address)| self.render_chunk(address, chunk))
.intersperse(vec![" ".into()])
.interleave(
(address..)
.step_by(BYTES_PER_CHUNK)
.take(CHUNKS_PER_LINE)
.skip(1)
.map(|address| vec![self.render_large_space_before(address)])
)
.flatten()
}
@@ -90,7 +96,12 @@ mod hex {
.copied()
.zip(address..)
.map(|(byte, address)| self.render_byte_at(address, byte))
.intersperse(" ".into()) // TODO: highlight if selected
.interleave(
(address..)
.take(BYTES_PER_CHUNK)
.skip(1)
.map(|address| self.render_space_before(address))
)
.collect()
}
@@ -105,10 +116,32 @@ mod hex {
match self.cursor.contains(address) {
Some(InCursor::Head) => span.bg(Color::Gray),
Some(InCursor::Rest) => span.bg(Color::Indexed(242)),
Some(InCursor::Rest) => span.bg(Color::select_grey()),
None => span,
}
}
fn render_large_space_before(&self, address: usize) -> Span<'static> {
if self.cursor.contains_space_before(address) {
Span {
style: Style::new().bg(Color::select_grey()),
content: " ".into()
}
} else {
" ".into()
}
}
fn render_space_before(&self, address: usize) -> Span<'static> {
if self.cursor.contains_space_before(address) {
Span {
style: Style::new().bg(Color::select_grey()),
content: " ".into()
}
} else {
" ".into()
}
}
}
const fn create_byte_lookup_table() -> [Span<'static>; u8::CARDINALITY] {