Skip to content

Commit

Permalink
Display non printable ascii chars with a dark dot (#580)
Browse files Browse the repository at this point in the history
* Display non printable ascii chars with a dark dot

* Revert into_iter
  • Loading branch information
vinc authored Feb 21, 2024
1 parent 699ddf0 commit e06d068
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/usr/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ pub fn print_hex(buf: &[u8]) {
}

pub fn print_hex_at(buf: &[u8], offset: usize) {
let null = 0 as char;
let cyan = Style::color("LightCyan");
let gray = Style::color("DarkGray");
let pink = Style::color("Pink");
let reset = Style::reset();

Expand All @@ -50,11 +52,13 @@ pub fn print_hex_at(buf: &[u8], offset: usize) {
if *byte >= 32 && *byte <= 126 {
*byte as char
} else {
'.'
null
}
).collect();

println!("{}{:08X}: {}{:40}{}{}", cyan, addr, pink, hex, reset, ascii);
let text = ascii.replace(null, &format!("{}.{}", gray, reset));

println!("{}{:08X}: {}{:40}{}{}", cyan, addr, pink, hex, reset, text);
}
}

Expand Down

0 comments on commit e06d068

Please sign in to comment.