diff options
author | David Peter <mail@david-peter.de> | 2023-12-11 23:22:36 +0100 |
---|---|---|
committer | David Peter <david.peter@bosch.com> | 2023-12-11 23:22:36 +0100 |
commit | 45fa72ec3b171e0034be07bc3c959df6b743e8c1 (patch) | |
tree | 3b00420d12b554470f94613efd0f08c034e08db3 /src | |
parent | 711627bfe84dbc594708f5784284d3a34ef067f0 (diff) |
Add ASCII character table
closes #36
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/main.rs | 28 |
2 files changed, 25 insertions, 12 deletions
@@ -26,6 +26,7 @@ pub enum ByteCategory { #[non_exhaustive] pub enum CharacterTable { Default, + Ascii, CP437, } @@ -83,6 +84,14 @@ impl Byte { AsciiOther => '•', NonAscii => '×', }, + CharacterTable::Ascii => match self.category() { + Null => '.', + AsciiPrintable => self.0 as char, + AsciiWhitespace if self.0 == 0x20 => ' ', + AsciiWhitespace => '.', + AsciiOther => '.', + NonAscii => '.', + }, CharacterTable::CP437 => CP437[self.0 as usize], } } diff --git a/src/main.rs b/src/main.rs index 7cabed2..ddb4500 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,6 +145,21 @@ fn run() -> Result<()> { .help("Show the character panel on the right. This is the default, unless --no-characters has been specified."), ) .arg( + Arg::new("character-table") + .long("character-table") + .value_name("FORMAT") + .value_parser(["default", "ascii", "codepage-437"]) + .default_value("default") + .help( + "Defines how bytes are mapped to characters:\n \ + \"default\": show printable ASCII characters as-is, '⋄' for NULL bytes, \ + ' ' for space, '_' for other ASCII whitespace, \ + '•' for other ASCII characters, and '×' for non-ASCII bytes.\n \ + \"ascii\": show printable ASCII as-is, ' ' for space, '.' for everything else.\n \ + \"codepage-437\": uses code page 437 (for non-ASCII bytes).\n" + ), + ) + .arg( Arg::new("no_position") .short('P') .long("no-position") @@ -214,18 +229,6 @@ fn run() -> Result<()> { .help("An alias for '--endianness=little'."), ) .arg( - Arg::new("character-table") - .long("character-table") - .value_name("FORMAT") - .value_parser(["default", "codepage-437"]) - .default_value("default") - .help( - "The character table that should be used. 'default' \ - will show dots for non-ASCII characters, 'codepage-437' \ - will use code page 437 for those characters." - ), - ) - .arg( Arg::new("base") .short('b') .long("base") @@ -497,6 +500,7 @@ fn run() -> Result<()> { .as_ref() { "default" => CharacterTable::Default, + "ascii" => CharacterTable::Ascii, "codepage-437" => CharacterTable::CP437, _ => unreachable!(), }; |