Do not fail if output is not a TTY for --panels=auto

closes #184
This commit is contained in:
David Peter committed 2022-12-07 21:33:20 +01:00
1 parent c7e2235293
commit 70fa092df1
2 files changed
+16 -6

No files matched your search

+11
View File
@@ -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
+5 -6
View File
@@ -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| {