From eb233b745ff7b3db516d0ff1cb80f12269e31c02 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 26 Mar 2023 11:58:08 -0400 Subject: fix getting the terminal size when redirecting output the term_size crate checked all fds automatically, but we have to do it ourselves when using terminal_size --- CHANGELOG.md | 4 ++++ src/data.rs | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2523056..c405d7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes +## 0.3.1 + +* Fix getting the correct terminal size when redirecting output + ## 0.3.0 * Rerelease because apparently 0.2.0 and 0.2.1 were already released from diff --git a/src/data.rs b/src/data.rs index 3e761c1..c423f61 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,3 +1,5 @@ +use std::os::fd::AsRawFd as _; + use crate::args; use crate::colors; use crate::power; @@ -69,11 +71,16 @@ fn hostname() -> Option { } fn terminal_cols() -> Option { - if let Some((w, _h)) = terminal_size::terminal_size() { - Some(usize::from(w.0)) - } else { - None + for fd in [ + std::io::stdout().as_raw_fd(), + std::io::stderr().as_raw_fd(), + std::io::stdin().as_raw_fd(), + ] { + if let Some((w, _h)) = terminal_size::terminal_size_using_fd(fd) { + return Some(usize::from(w.0)); + } } + None } fn pwd() -> Option { -- cgit v1.2.3-54-g00ecf