diff --git a/src/action.rs b/src/action.rs index a024424..aacb7ee 100644 --- a/src/action.rs +++ b/src/action.rs @@ -251,14 +251,14 @@ impl App { self.cursor.head = min( self.cursor.head + BYTES_PER_LINE, self.contents.len() - 1 - ) + ); } else { self.cursor.tail -= self.cursor.tail % BYTES_PER_LINE; self.cursor.head += BYTES_PER_LINE - 1 - (self.cursor.head % BYTES_PER_LINE); } } - fn extend_line_above(&mut self) { + const fn extend_line_above(&mut self) { if self.cursor.head > self.cursor.tail { swap(&mut self.cursor.head, &mut self.cursor.tail); } diff --git a/src/app/widget.rs b/src/app/widget.rs index 9014dc4..9bcbb98 100644 --- a/src/app/widget.rs +++ b/src/app/widget.rs @@ -48,7 +48,7 @@ impl App { iter::once(address::render_address(address)) .chain(self.render_chunks(address, bytes)) .chain(iter::once(" ".into())) - .chain(character_panel::render_character_panel(bytes)) + .chain(self.render_character_panel(address, bytes)) .collect() } @@ -57,7 +57,7 @@ impl App { iter::once(address::render_address(address)) .chain(self.render_partial_chunks(address, bytes)) .chain(iter::once(" ".into())) - .chain(character_panel::render_character_panel(bytes)) + .chain(self.render_character_panel(address, bytes)) .collect() } } @@ -277,25 +277,38 @@ mod hex { mod character_panel { use std::{borrow::Cow, mem}; - use ratatui::{style::{Color, Style}, text::Span}; + use ratatui::{style::{Color, Style, Stylize}, text::Span}; + use crate::{app::App, cardinality::HasCardinality, cursor::InCursor, custom_greys::CustomGreys, empty_span::empty_span}; - use crate::{cardinality::HasCardinality, empty_span::empty_span}; - - pub fn render_character_panel( - bytes: &[u8] - ) -> impl Iterator> { - bytes - .iter() - .copied() - .map(render_character) - } - - fn render_character(byte: u8) -> Span<'static> { - const SPAN_FOR_BYTE: [Span; u8::CARDINALITY] = create_character_lookup_table(); + impl App { + pub fn render_character_panel( + &self, + address: usize, + bytes: &[u8] + ) -> impl Iterator> { + bytes + .iter() + .copied() + .zip(address..) + .map(|(byte, address)| self.render_character_at(address, byte)) + } - SPAN_FOR_BYTE[byte as usize].clone() + fn render_character_at( + &self, + address: usize, + byte: u8 + ) -> Span<'static> { + const SPAN_FOR_BYTE: [Span; u8::CARDINALITY] = create_character_lookup_table(); + + let span = SPAN_FOR_BYTE[byte as usize].clone(); + + match self.cursor.contains(address) { + Some(InCursor::Head) => span.bg(Color::select_grey()), + Some(InCursor::Rest) => span.bg(Color::DarkGray), + None => span, + } + } } - const fn create_character_lookup_table() -> [Span<'static>; u8::CARDINALITY] { let mut result = [const { empty_span() }; u8::CARDINALITY]; diff --git a/src/main.rs b/src/main.rs index 5c5b8ca..5072bc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,9 +30,9 @@ const CHUNKS_PER_LINE: usize = BYTES_PER_LINE / BYTES_PER_CHUNK; // - mode // - delete // - change -// - highlight cursor in character panel too (but lighter?) -// - edit too -// - modifier on existing keys like teehee? or jump to panel? +// - edit character panel +// - modifier on existing keys like teehee? or jump to panel? +// - if jump to panel, space? // - search // - jumplist // - f/t