diff options
author | David Peter <mail@david-peter.de> | 2022-12-07 21:50:12 +0100 |
---|---|---|
committer | David Peter <mail@david-peter.de> | 2022-12-07 21:50:12 +0100 |
commit | 1df35eeb6312ff642922ca2185b53fd2f06d3ef7 (patch) | |
tree | e066db09f64d3be5d5a59bcc92eddac7b340c4d7 | |
parent | 437a15f3d680d78c2c2889bddb7a7270a7a12d06 (diff) |
Renme --group-bytes to --group-size
For `xxd`-compatibility reasons
see #121
-rw-r--r-- | CHANGELOG.md | 8 | ||||
-rw-r--r-- | examples/simple.rs | 2 | ||||
-rw-r--r-- | src/bin/hexyl.rs | 36 | ||||
-rw-r--r-- | src/lib.rs | 24 | ||||
-rw-r--r-- | tests/integration_tests.rs | 18 |
5 files changed, 49 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c0453..74d2f09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,14 @@ - Do not fail with an error if `--panels=auto` is used and the output is piped, see #184 (@sharkdp) +## Changes + +- Breaking: For `xxd`-compatibility reasons, `--group_bytes` has been renamed to `--group-size` (with an `--groupsize` alias), see #121 (@sharkdp) + +## `hexyl` as a library + +- Breaking: `num_group_bytes` has been renamed to `group_size`. + # v0.11.0 diff --git a/examples/simple.rs b/examples/simple.rs index 4f4b671..f90a620 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -18,7 +18,7 @@ fn main() { .with_border_style(BorderStyle::Unicode) .enable_squeezing(false) .num_panels(2) - .num_group_bytes(1) + .group_size(1) .build(); printer.print_all(&input[..]).unwrap(); } diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index 5855b3c..c91d3a4 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -168,14 +168,16 @@ fn run() -> Result<()> { ), ) .arg( - Arg::new("group_bytes") + Arg::new("group_size") .short('g') - .long("group-bytes") + .long("group-size") + .alias("groupsize") .num_args(1) .value_name("N") .help( - "Sets the number of octets per group to be displayed. \ - The possible options are 1, 2, 4, 8. The default is 1", + "Number of bytes/octets that should be grouped together. \ + Possible group sizes are 1, 2, 4, 8. The default is 1. \ + '--groupsize can be used as an alias (xxd-compatibility).", ), ) .arg( @@ -323,12 +325,12 @@ fn run() -> Result<()> { .transpose()? .unwrap_or(0); - let max_panels_fn = |terminal_width: u64, base_digits: u64, group_bytes: u64| { + let max_panels_fn = |terminal_width: u64, base_digits: u64, group_size: u64| { let offset = if show_position_panel { 10 } else { 1 }; let col_width = if show_char_panel { - ((8 / group_bytes) * (base_digits * group_bytes + 1)) + 2 + 8 + ((8 / group_size) * (base_digits * group_size + 1)) + 2 + 8 } else { - ((8 / group_bytes) * (base_digits * group_bytes + 1)) + 2 + ((8 / group_size) * (base_digits * group_size + 1)) + 2 }; if (terminal_width - offset) / col_width < 1 { 1 @@ -369,21 +371,21 @@ fn run() -> Result<()> { Base::Hexadecimal => 2, }; - let group_bytes = if let Some(group_bytes) = matches - .get_one::<String>("group_bytes") + let group_size = if let Some(group_size) = matches + .get_one::<String>("group_size") .map(|s| { s.parse::<NonZeroU8>().map(u8::from).context(anyhow!( - "failed to parse `--group-bytes`/`-g` arg {:?} as unsigned nonzero integer", + "Failed to parse `--group-size`/`-g` argument {:?} as unsigned nonzero integer", s )) }) .transpose()? { - if (group_bytes <= 8) && ((group_bytes & (group_bytes - 1)) == 0) { - group_bytes + if (group_size <= 8) && ((group_size & (group_size - 1)) == 0) { + group_size } else { return Err(anyhow!( - "Possible options for the `--group-bytes`/`-g` option are 1, 2, 4 or 8. " + "Possible sizes for the `--group-size`/`-g` option are 1, 2, 4 or 8. " )); } } else { @@ -393,7 +395,7 @@ fn run() -> Result<()> { let terminal_width = terminal_size().map(|s| s.0 .0 as u64).unwrap_or(80); let panels = if matches.get_one::<String>("panels").map(String::as_ref) == Some("auto") { - max_panels_fn(terminal_width, base_digits, group_bytes.into()) + max_panels_fn(terminal_width, base_digits, group_size.into()) } else if let Some(panels) = matches .get_one::<String>("panels") .map(|s| { @@ -415,11 +417,11 @@ fn run() -> Result<()> { }) .transpose()? { - max_panels_fn(terminal_width, base_digits, group_bytes.into()) + max_panels_fn(terminal_width, base_digits, group_size.into()) } else { std::cmp::min( 2, - max_panels_fn(terminal_width, base_digits, group_bytes.into()), + max_panels_fn(terminal_width, base_digits, group_size.into()), ) }; @@ -433,7 +435,7 @@ fn run() -> Result<()> { .with_border_style(border_style) .enable_squeezing(squeeze) .num_panels(panels) - .num_group_bytes(group_bytes) + .group_size(group_size) .with_base(base) .build(); printer.display_offset(skip_offset + display_offset); @@ -168,7 +168,7 @@ pub struct PrinterBuilder<'a, Writer: Write> { border_style: BorderStyle, use_squeeze: bool, panels: u64, - group_bytes: u8, + group_size: u8, base: Base, } @@ -182,7 +182,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { border_style: BorderStyle::Unicode, use_squeeze: true, panels: 2, - group_bytes: 1, + group_size: 1, base: Base::Hexadecimal, } } @@ -217,8 +217,8 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self } - pub fn num_group_bytes(mut self, num: u8) -> Self { - self.group_bytes = num; + pub fn group_size(mut self, num: u8) -> Self { + self.group_size = num; self } @@ -236,7 +236,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self.border_style, self.use_squeeze, self.panels, - self.group_bytes, + self.group_size, self.base, ) } @@ -264,7 +264,7 @@ pub struct Printer<'a, Writer: Write> { panels: u64, squeeze_byte: usize, /// The number of octets per group. - group_bytes: u8, + group_size: u8, /// The number of digits used to write the base. base_digits: u8, } @@ -278,7 +278,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { border_style: BorderStyle, use_squeeze: bool, panels: u64, - group_bytes: u8, + group_size: u8, base: Base, ) -> Printer<'a, Writer> { Printer { @@ -322,7 +322,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { display_offset: 0, panels, squeeze_byte: 0x00, - group_bytes, + group_size, base_digits: match base { Base::Binary => 8, Base::Octal => 3, @@ -339,8 +339,8 @@ impl<'a, Writer: Write> Printer<'a, Writer> { fn panel_sz(&self) -> usize { // add one to include the trailing space of a group - let group_sz = self.base_digits as usize * self.group_bytes as usize + 1; - let group_per_panel = 8 / self.group_bytes as usize; + let group_sz = self.base_digits as usize * self.group_size as usize + 1; + let group_per_panel = 8 / self.group_size as usize; // add one to include the leading space 1 + group_sz * group_per_panel } @@ -510,7 +510,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { .write_all(self.colors[ByteColor::Reset as usize].as_bytes())?; } } else { - if i % (self.group_bytes as usize) == 0 { + if i % (self.group_size as usize) == 0 { self.writer.write_all(b" ")?; } } @@ -520,7 +520,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { } Squeezer::Delete => self.writer.write_all(b" ")?, Squeezer::Ignore | Squeezer::Disabled => { - if i % (self.group_bytes as usize) == 0 { + if i % (self.group_size as usize) == 0 { self.writer.write_all(b" ")?; } if self.show_color && self.curr_color != Some(Byte(b).color()) { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 028f67b..fda9daf 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -301,7 +301,7 @@ mod group { hexyl() .arg("ascii") .arg("--color=never") - .arg("--group-bytes=2") + .arg("--group-size=2") .assert() .success() .stdout( @@ -316,7 +316,7 @@ mod group { hexyl() .arg("ascii") .arg("--color=never") - .arg("--group-bytes=4") + .arg("--group-size=4") .assert() .success() .stdout( @@ -331,7 +331,7 @@ mod group { hexyl() .arg("ascii") .arg("--color=never") - .arg("--group-bytes=8") + .arg("--group-size=8") .assert() .success() .stdout( @@ -342,22 +342,22 @@ mod group { } #[test] - fn group_bytes_plain() { + fn group_size_plain() { hexyl() .arg("ascii") .arg("--color=never") .arg("--plain") - .arg("--group-bytes=2") + .arg("--group-size=2") .assert() .success() .stdout(" 3031 3233 3435 3637 3839 6162 6364 650a \n"); } #[test] - fn group_bytes_fill_space() { + fn group_size_fill_space() { hexyl() .arg("--color=never") - .arg("--group-bytes=2") + .arg("--group-size=2") .write_stdin("abc") .assert() .success() @@ -369,12 +369,12 @@ mod group { } #[test] - fn group_bytes_invalid() { + fn group_size_invalid() { hexyl() .arg("ascii") .arg("--color=never") .arg("--plain") - .arg("--group-bytes=3") + .arg("--group-size=3") .assert() .failure(); } |