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 + 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);
}
+31 -18
View File
@@ -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};
impl App {
pub fn render_character_panel(
&self,
address: usize,
bytes: &[u8]
) -> impl Iterator<Item=Span<'static>> {
bytes
.iter()
.copied()
.zip(address..)
.map(|(byte, address)| self.render_character_at(address, byte))
}
pub fn render_character_panel(
bytes: &[u8]
) -> impl Iterator<Item=Span<'static>> {
bytes
.iter()
.copied()
.map(render_character)
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,
}
}
}
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()
}
const fn create_character_lookup_table() -> [Span<'static>; 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
// - 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