12 Commits
Author SHA1 Message Date
David Peter abc20a380c Bump version 2024-12-27 14:43:18 +01:00
David Peter dd89c22327 Remove color reference from README 2024-12-27 14:42:27 +01:00
David Peter 45a557e0df Merge pull request #235 from sahinfalcon/print-colour-table
PR #229 • Add option to print color table
2024-12-27 14:41:12 +01:00
David Peter 73cfd05a10 Minor updates 2024-12-27 14:37:04 +01:00
Taylan Sahin 37e9ef6a64 cargo fmt 2024-12-27 14:35:04 +01:00
Taylan Sahin 568f38ae77 PR #229 • Add option to print color table 2024-12-27 14:35:03 +01:00
David Peter 6e0bff2cc5 Merge pull request #234 from Integral-Tech/error-on-dir
fix: throw an error when try to view a directory
2024-12-27 14:29:34 +01:00
David Peter 1783fe6a9b Merge pull request #233 from lunrenyi/patch-1
docs(install): add x-cmd method to install hexyl
2024-12-27 14:26:02 +01:00
David Peter 733b9e12e4 Fix CI 2024-12-27 14:25:01 +01:00
David Peter 19198c2aac Minor updates 2024-12-27 14:23:02 +01:00
Integral c65b298e60 fix: throw an error when try to view a directory 2024-11-21 00:55:37 +08:00
lunrenyi f986c196d2 docs(install): add x-cmd method to install hexyl 2024-11-12 14:30:33 +08:00
6 changed files with 86 additions and 21 deletions

No files matched your search

+2 -1
View File
@@ -76,7 +76,8 @@ jobs:
- { target: i686-pc-windows-msvc , os: windows-2019 }
- { target: i686-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
- { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true }
- { target: x86_64-apple-darwin , os: macos-12 }
- { target: x86_64-apple-darwin , os: macos-13 }
- { target: aarch64-apple-darwin , os: macos-15 }
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
+18
View File
@@ -1,3 +1,21 @@
# unreleased
## Features
## Bugfixes
# v0.16.0
## Features
* New `--print-color-table` option, see #229 (@sahinfalcon)
## Bugfixes
- Throw an error when try to view a directory, see #234 (@Integral-Tech)
# v0.15.0
## Features
Generated
+1 -1
View File
@@ -217,7 +217,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hexyl"
version = "0.15.0"
version = "0.16.0"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -7,7 +7,7 @@ license = "MIT/Apache-2.0"
name = "hexyl"
readme = "README.md"
repository = "https://github.com/sharkdp/hexyl"
version = "0.15.0"
version = "0.16.0"
edition = "2021"
rust-version = "1.74"
+4 -13
View File
@@ -17,19 +17,6 @@ of bytes (NULL bytes, printable ASCII characters, ASCII whitespace characters, o
![](https://i.imgur.com/f8nm8g6.png)
## Color Reference
|Type of Byte|Color|ANSI Code |
|---|---|---|
|NULL|![#555753](https://placehold.co/10x10/555753/555753.png) Bright Black|90|
|OFFSET|![#555753](https://placehold.co/10x10/555753/555753.png) Bright Black|90|
|ASCII Printable|![#06989a](https://placehold.co/10x10/06989a/06989a.png) Cyan|36|
|ASCII Whitespace|![#4e9a06](https://placehold.co/10x10/4e9a06/4e9a06.png) Green|32|
|ASCII Other|![#4e9a06](https://placehold.co/10x10/4e9a06/4e9a06.png) Green|32|
|Non-ASCII|![#c4a000](https://placehold.co/10x10/c4a000/c4a000.png) Yellow|33|
*Colors taken from the Ubuntu terminal color scheme, they could look different in your terminal*
## Installation
@@ -189,6 +176,10 @@ sudo snap install hexyl
scoop install hexyl
```
### Via [X-CMD](https://x-cmd.com)
```
x env use hexyl
```
## License
+60 -5
View File
@@ -6,7 +6,7 @@ use std::path::PathBuf;
use clap::builder::ArgPredicate;
use clap::{ArgAction, Parser, ValueEnum};
use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, bail, Context, Result};
use const_format::formatcp;
@@ -16,6 +16,11 @@ use terminal_size::terminal_size;
use hexyl::{Base, BorderStyle, CharacterTable, Endianness, Input, PrinterBuilder};
use hexyl::{
COLOR_ASCII_OTHER, COLOR_ASCII_PRINTABLE, COLOR_ASCII_WHITESPACE, COLOR_NONASCII, COLOR_NULL,
COLOR_RESET,
};
#[cfg(test)]
mod tests;
@@ -179,6 +184,10 @@ struct Opt {
conflicts_with("panels")
)]
terminal_width: Option<NonZeroU64>,
/// Print a table showing how different types of bytes are colored.
#[arg(long)]
print_color_table: bool,
}
#[derive(Clone, Debug, Default, ValueEnum)]
@@ -231,10 +240,21 @@ impl From<GroupSize> for u8 {
fn run() -> Result<()> {
let opt = Opt::parse();
if opt.print_color_table {
return print_color_table().map_err(|e| anyhow!(e));
}
let stdin = io::stdin();
let mut reader = match opt.file {
Some(filename) => Input::File(File::open(filename)?),
Some(filename) => {
if filename.is_dir() {
bail!("'{}' is a directory.", filename.to_string_lossy());
}
let file = File::open(&filename)?;
Input::File(file)
}
None => Input::Stdin(stdin.lock()),
};
@@ -409,10 +429,9 @@ fn run() -> Result<()> {
let character_table = opt.character_table;
let stdout = io::stdout();
let mut stdout_lock = BufWriter::new(stdout.lock());
let mut stdout = BufWriter::new(io::stdout().lock());
let mut printer = PrinterBuilder::new(&mut stdout_lock)
let mut printer = PrinterBuilder::new(&mut stdout)
.show_color(show_color)
.show_char_panel(show_char_panel)
.show_position_panel(show_position_panel)
@@ -468,6 +487,42 @@ impl From<NonNegativeI64> for u64 {
}
}
fn print_color_table() -> io::Result<()> {
let mut stdout = BufWriter::new(io::stdout().lock());
writeln!(stdout, "hexyl color reference:\n")?;
// NULL bytes
stdout.write_all(COLOR_NULL)?;
writeln!(stdout, "⋄ NULL bytes (0x00)")?;
stdout.write_all(COLOR_RESET)?;
// ASCII printable
stdout.write_all(COLOR_ASCII_PRINTABLE)?;
writeln!(stdout, "a ASCII printable characters (0x20 - 0x7E)")?;
stdout.write_all(COLOR_RESET)?;
// ASCII whitespace
stdout.write_all(COLOR_ASCII_WHITESPACE)?;
writeln!(stdout, "_ ASCII whitespace (0x09 - 0x0D, 0x20)")?;
stdout.write_all(COLOR_RESET)?;
// ASCII other
stdout.write_all(COLOR_ASCII_OTHER)?;
writeln!(
stdout,
"• ASCII control characters (except NULL and whitespace)"
)?;
stdout.write_all(COLOR_RESET)?;
// Non-ASCII
stdout.write_all(COLOR_NONASCII)?;
writeln!(stdout, "× Non-ASCII bytes (0x80 - 0xFF)")?;
stdout.write_all(COLOR_RESET)?;
Ok(())
}
#[derive(Clone, Copy, Debug, Default, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub struct PositiveI64(i64);