diff options
author | David Peter <mail@david-peter.de> | 2022-12-07 21:30:10 +0100 |
---|---|---|
committer | David Peter <mail@david-peter.de> | 2022-12-07 21:33:20 +0100 |
commit | 70fa092df122b97b1de0cb26e29514445a9390ed (patch) | |
tree | a4368eef629b436a0876c44abac5011ffc81f7e7 /src | |
parent | c7e2235293ae9f182af34899df29517780d0246d (diff) |
Do not fail if output is not a TTY for `--panels=auto`
closes #184
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/hexyl.rs | 11 |
1 files changed, 5 insertions, 6 deletions
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::<String>("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::<String>("panels") .map(|s| { |