Skip to content

Commit

Permalink
Merge pull request #39 from jgardona/feat/enhance-characters
Browse files Browse the repository at this point in the history
Enhance characters and rendering
  • Loading branch information
jgardona authored Nov 28, 2023
2 parents 1917996 + ad593bd commit 1bb3a34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/cli/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub fn display_data<W: Write>(
for b in d {
match *b {
// null byte
0x00 => write!(output, "{} ", "··".bright_black()).unwrap(),
0xff => write!(output, "{} ", "••".bright_black()).unwrap(),
0x00 => write!(output, "{} ", "00".bright_black()).unwrap(),
0xff => write!(output, "{} ", "ff".bright_red()).unwrap(),
// ascii printable characters
0x21..=0x7e => write!(output, "{:02x} ", b.blue()).unwrap(),
// ascii white space characters and controls
Expand All @@ -40,14 +40,18 @@ pub fn display_data<W: Write>(
}
}

if OFFSET - d.len() > 0 {
write!(output, "{}", " ".repeat((OFFSET - d.len()) * 3)).unwrap();
}

for b in d {
match *b {
0x00 => write!(output, "{}", "·".bright_black()).unwrap(),
0xff => write!(output, "{}", "•".bright_black()).unwrap(),
0x00 => write!(output, "{}", "".bright_black()).unwrap(),
0xff => write!(output, "{}", "×".bright_red()).unwrap(),
0x21..=0x7e => write!(output, "{}", (*b as char).blue()).unwrap(),
0x09..=0x0d | 0x20 | 0x7f => write!(output, "{}", "_".green()).unwrap(),
0x01..=0x08 | 0x0e..=0x1f => write!(output, "{}", "•".green()).unwrap(),
0x80..=0xfe => write!(output, "{}", "".bright_red()).unwrap(),
0x80..=0xfe => write!(output, "{}", "×".bright_red()).unwrap(),
}
}
writeln!(output).unwrap();
Expand Down Expand Up @@ -155,7 +159,7 @@ mod test_view {
fn test_display_data_16_null_bytes() -> Result<()> {
let input = [0u8; 16];
let expected =
"00000000 ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················\n";
"00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦\n";
let mut output = Cursor::new(Vec::<u8>::new());

display_data(0, false, &input, &mut output)?;
Expand Down Expand Up @@ -243,7 +247,7 @@ mod test_view {
let result = std::str::from_utf8(&plain_result)?;

let expected =
"00000000 ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················\n\
"00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦\n\
*\n\
00000020 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ••••••••••••••••\n";

Expand All @@ -266,7 +270,7 @@ mod test_view {

let expected =
"00000000 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ••••••••••••••••\n\
00000010 ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ·· ················\n\
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦◦\n\
*\n\
00000030 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ••••••••••••••••\n";

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn test_no_squeeze_skip_4_length_5b() -> Result<()> {
let result = cmd.output()?.stdout;
let result = strip_ansi_escapes::strip(&result);
let result = std::str::from_utf8(&result)?;
let expected = "00000004 71 75 69 63 6b quick\n";
let expected = "00000004 71 75 69 63 6b quick\n";
assert_eq!(expected, result);

Ok(())
Expand Down

0 comments on commit 1bb3a34

Please sign in to comment.