Implement character table control and codepage 437 option

This commit is contained in:
Sharif Haason committed 2023-12-10 13:21:23 -05:00
1 parent 663e4c19ff
commit 6a230d34a4
2 files changed
+86 -11

No files matched your search

+24 -1
View File
@@ -17,7 +17,7 @@ use thiserror::Error as ThisError;
use terminal_size::terminal_size;
use hexyl::{Base, BorderStyle, Endianness, Input, PrinterBuilder};
use hexyl::{Base, BorderStyle, CharTable, Endianness, Input, PrinterBuilder};
#[cfg(test)]
mod tests;
@@ -212,6 +212,17 @@ fn run() -> Result<()> {
.hide(true)
.help("An alias for '--endianness=little'."),
)
.arg(
Arg::new("character_table")
.long("character_table")
.value_name("FORMAT")
.value_parser(["codepage-437", "ascii-only"])
.help(
"The character table that should be used. 'ascii-only' \
will show dots for non-ASCII characters, and 'codepage-437 \
will use Code page 437 for those characters."
),
)
.arg(
Arg::new("base")
.short('b')
@@ -469,6 +480,17 @@ fn run() -> Result<()> {
("big", _) => Endianness::Big,
_ => unreachable!(),
};
let char_table = match matches
.get_one::<String>("character_table")
.unwrap_or(&String::from("ascii-only"))
.as_ref()
{
"ascii-only" => CharTable::AsciiOnly,
"codepage-437" => CharTable::CP437,
_ => unreachable!(),
};
let stdout = io::stdout();
let mut stdout_lock = BufWriter::new(stdout.lock());
@@ -482,6 +504,7 @@ fn run() -> Result<()> {
.group_size(group_size)
.with_base(base)
.endianness(endianness)
.char_table(char_table)
.build();
printer.display_offset(skip_offset + display_offset);
printer.print_all(&mut reader).map_err(|e| anyhow!(e))?;