diff options
author | Jesse Luehrs <doy@tozt.net> | 2023-03-26 11:58:08 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2023-03-26 11:58:08 -0400 |
commit | eb233b745ff7b3db516d0ff1cb80f12269e31c02 (patch) | |
tree | 7b458872d0163a553837b1907ccdf876f511dd9b | |
parent | 8b6f319774f83ee287e72e4e58cf4e171211cbd1 (diff) | |
download | fancy-prompt-eb233b745ff7b3db516d0ff1cb80f12269e31c02.tar.gz fancy-prompt-eb233b745ff7b3db516d0ff1cb80f12269e31c02.zip |
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
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | 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<String> { } fn terminal_cols() -> Option<usize> { - 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<std::path::PathBuf> { |