It shows bytes I guess
This commit is contained in:
parent
936c296449
commit
1ed84e6dee
13 changed files with 3986 additions and 2 deletions
34
src/line_number.rs
Normal file
34
src/line_number.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use ratatui::prelude::*;
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
pub struct LineNumberWidget(pub usize, pub usize);
|
||||
|
||||
fn usize_to_hex(mut value: usize, buffer: &mut [u8; 64]) -> &str {
|
||||
const HEX: &[u8; 16] = b"0123456789ABCDEF";
|
||||
let len = std::mem::size_of_val(&value);
|
||||
|
||||
for i in 0..len {
|
||||
let current_byte = value & 0xff;
|
||||
|
||||
buffer[63 - 2 * i] = HEX[current_byte & 0x0f];
|
||||
buffer[63 - 2 * i - 1] = HEX[current_byte >> 4];
|
||||
|
||||
value >>= 8;
|
||||
}
|
||||
|
||||
unsafe { std::str::from_utf8_unchecked(&buffer[64 - len * 2..]) }
|
||||
}
|
||||
|
||||
impl Widget for LineNumberWidget {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let visible_lines = area.height as usize;
|
||||
let mut buffer = [b'0'; 64];
|
||||
|
||||
let areas =
|
||||
Layout::vertical(vec![Constraint::Length(1); visible_lines.min(self.1)]).split(area);
|
||||
|
||||
for (i, a) in areas.iter().enumerate() {
|
||||
Line::from(usize_to_hex(self.0 + i * 16, &mut buffer)).render(*a, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue