Add ASCII character table

closes #36
This commit is contained in:
David Peter authored and David Peter committed 2023-12-11 23:22:36 +01:00
1 parent 711627bfe8
commit 45fa72ec3b
3 files changed
+79 -12

No files matched your search

+9
View File
@@ -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],
}
}
+16 -12
View File
@@ -144,6 +144,21 @@ fn run() -> Result<()> {
.action(ArgAction::SetTrue)
.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')
@@ -213,18 +228,6 @@ fn run() -> Result<()> {
.hide(true)
.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')
@@ -497,6 +500,7 @@ fn run() -> Result<()> {
.as_ref()
{
"default" => CharacterTable::Default,
"ascii" => CharacterTable::Ascii,
"codepage-437" => CharacterTable::CP437,
_ => unreachable!(),
};