highlight cursor in character panel

This commit is contained in:
alice pellerin
2026-03-18 03:27:56 -05:00
parent c503d32b20
commit 98f4c56852
3 changed files with 36 additions and 23 deletions
+2 -2
View File
@@ -251,14 +251,14 @@ impl App {
self.cursor.head = min( self.cursor.head = min(
self.cursor.head + BYTES_PER_LINE, self.cursor.head + BYTES_PER_LINE,
self.contents.len() - 1 self.contents.len() - 1
) );
} else { } else {
self.cursor.tail -= self.cursor.tail % BYTES_PER_LINE; self.cursor.tail -= self.cursor.tail % BYTES_PER_LINE;
self.cursor.head += BYTES_PER_LINE - 1 - (self.cursor.head % 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 { if self.cursor.head > self.cursor.tail {
swap(&mut self.cursor.head, &mut self.cursor.tail); swap(&mut self.cursor.head, &mut self.cursor.tail);
} }
+31 -18
View File
@@ -48,7 +48,7 @@ impl App {
iter::once(address::render_address(address)) iter::once(address::render_address(address))
.chain(self.render_chunks(address, bytes)) .chain(self.render_chunks(address, bytes))
.chain(iter::once(" ".into())) .chain(iter::once(" ".into()))
.chain(character_panel::render_character_panel(bytes)) .chain(self.render_character_panel(address, bytes))
.collect() .collect()
} }
@@ -57,7 +57,7 @@ impl App {
iter::once(address::render_address(address)) iter::once(address::render_address(address))
.chain(self.render_partial_chunks(address, bytes)) .chain(self.render_partial_chunks(address, bytes))
.chain(iter::once(" ".into())) .chain(iter::once(" ".into()))
.chain(character_panel::render_character_panel(bytes)) .chain(self.render_character_panel(address, bytes))
.collect() .collect()
} }
} }
@@ -277,25 +277,38 @@ mod hex {
mod character_panel { mod character_panel {
use std::{borrow::Cow, mem}; 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}; impl App {
pub fn render_character_panel(
pub fn render_character_panel( &self,
bytes: &[u8] address: usize,
) -> impl Iterator<Item=Span<'static>> { bytes: &[u8]
bytes ) -> impl Iterator<Item=Span<'static>> {
.iter() bytes
.copied() .iter()
.map(render_character) .copied()
} .zip(address..)
.map(|(byte, address)| self.render_character_at(address, byte))
fn render_character(byte: u8) -> Span<'static> { }
const SPAN_FOR_BYTE: [Span; u8::CARDINALITY] = create_character_lookup_table();
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] { const fn create_character_lookup_table() -> [Span<'static>; u8::CARDINALITY] {
let mut result = [const { empty_span() }; u8::CARDINALITY]; let mut result = [const { empty_span() }; u8::CARDINALITY];
+3 -3
View File
@@ -30,9 +30,9 @@ const CHUNKS_PER_LINE: usize = BYTES_PER_LINE / BYTES_PER_CHUNK;
// - mode // - mode
// - delete // - delete
// - change // - change
// - highlight cursor in character panel too (but lighter?) // - edit character panel
// - edit too // - modifier on existing keys like teehee? or jump to panel?
// - modifier on existing keys like teehee? or jump to panel? // - if jump to panel, space?
// - search // - search
// - jumplist // - jumplist
// - f/t // - f/t