diff --git a/Cargo.toml b/Cargo.toml index f4f09f7..0e049f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nutmeg" -version = "0.1.5" +version = "0.1.6" edition = "2021" description = "An unopinionated progress bar library" license = "MIT" @@ -12,7 +12,7 @@ rust-version = "1.75" # Could perhaps be even older, but this is 2 years at tim [dependencies] atty = "0.2" -terminal_size = "0.2" +terminal_size = "0.4" yansi = "0.5" [dev-dependencies] diff --git a/NEWS.md b/NEWS.md index e7b8322..77c71a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # Nutmeg Changelog +## 0.1.6 + +Released 2026-03-07 + +- Updated `terminal_size` dependency. + ## 0.1.5 Released 2025-10-05 diff --git a/src/width.rs b/src/width.rs index d1f8f16..4e62538 100644 --- a/src/width.rs +++ b/src/width.rs @@ -1,26 +1,13 @@ -// Copyright 2022-2023 Martin Pool +// Copyright 2022-2026 Martin Pool //! Measure terminal width. -use terminal_size::Width; #[cfg(unix)] -pub(crate) fn stdout_width() -> Option { - terminal_size::terminal_size_using_fd(1).map(|(Width(w), _)| w as usize) -} - -#[cfg(windows)] -pub(crate) fn stdout_width() -> Option { - // TODO: We could get the handle for stderr to make this more precise... - terminal_size::terminal_size().map(|(Width(w), _)| w as usize) -} - +mod unix; #[cfg(unix)] -pub(crate) fn stderr_width() -> Option { - terminal_size::terminal_size_using_fd(2).map(|(Width(w), _)| w as usize) -} +pub(crate) use unix::{stderr_width, stdout_width}; #[cfg(windows)] -pub(crate) fn stderr_width() -> Option { - // TODO: We could get the handle for stderr to make this more precise... - terminal_size::terminal_size().map(|(Width(w), _)| w as usize) -} +mod windows; +#[cfg(windows)] +pub(crate) use windows::{stderr_width, stdout_width}; diff --git a/src/width/unix.rs b/src/width/unix.rs new file mode 100644 index 0000000..4a45134 --- /dev/null +++ b/src/width/unix.rs @@ -0,0 +1,14 @@ +use std::{ + io::{stderr, stdout}, + os::fd::AsFd, +}; + +use terminal_size::{terminal_size_of, Width}; + +pub(crate) fn stdout_width() -> Option { + terminal_size_of(stdout().as_fd()).map(|(Width(w), _)| w as usize) +} + +pub(crate) fn stderr_width() -> Option { + terminal_size_of(stderr().as_fd()).map(|(Width(w), _)| w as usize) +} diff --git a/src/width/windows.rs b/src/width/windows.rs new file mode 100644 index 0000000..894f10b --- /dev/null +++ b/src/width/windows.rs @@ -0,0 +1,14 @@ +use std::{ + io::{stderr, stdout}, + os::windows::io::AsHandle, +}; + +use terminal_size::{terminal_size_of, Width}; + +pub(crate) fn stdout_width() -> Option { + terminal_size_of(stdout().as_handle()).map(|(Width(w), _)| w as usize) +} + +pub(crate) fn stderr_width() -> Option { + terminal_size_of(stderr().as_handle()).map(|(Width(w), _)| w as usize) +}