mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-26 20:16:31 +00:00
PR #229 • Add option to print color table
This commit is contained in:
1 parent
6e0bff2cc5
commit
568f38ae77
2 files changed
+50
-1
No files matched your search
+6
-1
@@ -1,9 +1,14 @@
|
|||||||
# unreleased
|
# unreleased
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* New `--print-color-table` option, see #229 (@sahinfalcon)
|
||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
||||||
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
|
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
|
||||||
|
|
||||||
|
|
||||||
# v0.15.0
|
# v0.15.0
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|||||||
+44
@@ -16,6 +16,8 @@ use terminal_size::terminal_size;
|
|||||||
|
|
||||||
use hexyl::{Base, BorderStyle, CharacterTable, Endianness, Input, PrinterBuilder};
|
use hexyl::{Base, BorderStyle, CharacterTable, Endianness, Input, PrinterBuilder};
|
||||||
|
|
||||||
|
use hexyl::{COLOR_NULL, COLOR_RESET, COLOR_ASCII_PRINTABLE, COLOR_ASCII_WHITESPACE, COLOR_ASCII_OTHER, COLOR_NONASCII};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
@@ -179,6 +181,10 @@ struct Opt {
|
|||||||
conflicts_with("panels")
|
conflicts_with("panels")
|
||||||
)]
|
)]
|
||||||
terminal_width: Option<NonZeroU64>,
|
terminal_width: Option<NonZeroU64>,
|
||||||
|
|
||||||
|
/// Print a table showing how different types of bytes are colored.
|
||||||
|
#[arg(short('t'), long)]
|
||||||
|
print_color_table: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, ValueEnum)]
|
#[derive(Clone, Debug, Default, ValueEnum)]
|
||||||
@@ -231,6 +237,10 @@ impl From<GroupSize> for u8 {
|
|||||||
fn run() -> Result<()> {
|
fn run() -> Result<()> {
|
||||||
let opt = Opt::parse();
|
let opt = Opt::parse();
|
||||||
|
|
||||||
|
if opt.print_color_table {
|
||||||
|
return print_color_table().map_err(|e| anyhow!(e));
|
||||||
|
}
|
||||||
|
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
||||||
let mut reader = match opt.file {
|
let mut reader = match opt.file {
|
||||||
@@ -475,6 +485,40 @@ impl From<NonNegativeI64> for u64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_color_table() -> io::Result<()> {
|
||||||
|
let stdout = io::stdout();
|
||||||
|
let mut stdout_lock = BufWriter::new(stdout.lock());
|
||||||
|
|
||||||
|
writeln!(stdout_lock, "hexyl color reference:\n")?;
|
||||||
|
|
||||||
|
// NULL bytes
|
||||||
|
stdout_lock.write_all(COLOR_NULL)?;
|
||||||
|
writeln!(stdout_lock, "⋄ NULL bytes (0x00)")?;
|
||||||
|
stdout_lock.write_all(COLOR_RESET)?;
|
||||||
|
|
||||||
|
// ASCII printable
|
||||||
|
stdout_lock.write_all(COLOR_ASCII_PRINTABLE)?;
|
||||||
|
writeln!(stdout_lock, "a ASCII printable characters (0x20 - 0x7E)")?;
|
||||||
|
stdout_lock.write_all(COLOR_RESET)?;
|
||||||
|
|
||||||
|
// ASCII whitespace
|
||||||
|
stdout_lock.write_all(COLOR_ASCII_WHITESPACE)?;
|
||||||
|
writeln!(stdout_lock, "_ ASCII whitespace (0x09 - 0x0D, 0x20)")?;
|
||||||
|
stdout_lock.write_all(COLOR_RESET)?;
|
||||||
|
|
||||||
|
// ASCII other
|
||||||
|
stdout_lock.write_all(COLOR_ASCII_OTHER)?;
|
||||||
|
writeln!(stdout_lock, "• ASCII control characters (except NULL and whitespace)")?;
|
||||||
|
stdout_lock.write_all(COLOR_RESET)?;
|
||||||
|
|
||||||
|
// Non-ASCII
|
||||||
|
stdout_lock.write_all(COLOR_NONASCII)?;
|
||||||
|
writeln!(stdout_lock, "× Non-ASCII bytes (0x80 - 0xFF)")?;
|
||||||
|
stdout_lock.write_all(COLOR_RESET)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct PositiveI64(i64);
|
pub struct PositiveI64(i64);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user