From a8cffbb6df3e51337749a42a7231dd66b4c9ad55 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Sun, 27 Nov 2022 17:17:25 -0500 Subject: [PATCH] Move `group_bytes` so it can be used for panels --- src/bin/hexyl.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index a27e6e8..3a45603 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -331,6 +331,28 @@ fn run() -> Result<(), AnyhowError> { } }; + + let group_bytes = if let Some(group_bytes) = matches + .get_one::("group_bytes") + .map(|s| { + s.parse::().map(u8::from).context(anyhow!( + "failed to parse `--group-bytes`/`-g` arg {:?} as unsigned nonzero integer", + s + )) + }) + .transpose()? + { + if (group_bytes <= 8) && ((group_bytes & (group_bytes - 1)) == 0) { + group_bytes + } else { + return Err(anyhow!( + "Possible options for the `--group-bytes`/`-g` option are 1, 2, 4 or 8. " + )); + } + } else { + 1 + }; + let panels = if matches.get_one::("panels").map(String::as_ref) == Some("auto") { max_panels_fn(terminal_size().ok_or_else(|| anyhow!("not a TTY"))?.0 .0 as u64) } else if let Some(panels) = matches