From 70fa092df122b97b1de0cb26e29514445a9390ed Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 7 Dec 2022 21:30:10 +0100 Subject: [PATCH] Do not fail if output is not a TTY for `--panels=auto` closes #184 --- CHANGELOG.md | 11 +++++++++++ src/bin/hexyl.rs | 11 +++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a1944..c7c0453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# unreleased + +## Features + +- Only show one panel by default if the terminal width is not wide enough for two panels, see #182 (@sharkdp) + +## Bugfixes + +- Do not fail with an error if `--panels=auto` is used and the output is piped, see #184 (@sharkdp) + + # v0.11.0 ## Features diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index 3ecf1b0..42d4768 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -163,7 +163,8 @@ fn run() -> Result<()> { .help( "Sets the number of hex data panels to be displayed. \ `--panels=auto` will display the maximum number of hex data panels \ - based on the current terminal width", + based on the current terminal width. By default, hexyl will show \ + two panels, unless the terminal is not wide enough for that.", ), ) .arg( @@ -389,12 +390,10 @@ fn run() -> Result<()> { 1 }; + let terminal_width = terminal_size().map(|s| s.0 .0 as u64).unwrap_or(80); + 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, - base_digits, - group_bytes.into(), - ) + max_panels_fn(terminal_width, base_digits, group_bytes.into()) } else if let Some(panels) = matches .get_one::("panels") .map(|s| {