aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--src/data.rs15
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> {