From 8eadce7fba0cf2d7df97959c439ffb2ec761be7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Kj=C3=A4ll?= Date: Fri, 6 Mar 2026 17:38:33 +0100 Subject: [PATCH 1/4] upgrade terminal_size to 0.4 --- Cargo.toml | 2 +- src/width.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4f09f7..9de07b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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/src/width.rs b/src/width.rs index d1f8f16..f041c6d 100644 --- a/src/width.rs +++ b/src/width.rs @@ -5,7 +5,9 @@ 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) + unsafe { + terminal_size::terminal_size_using_fd(1).map(|(Width(w), _)| w as usize) + } } #[cfg(windows)] @@ -16,7 +18,9 @@ pub(crate) fn stdout_width() -> Option { #[cfg(unix)] pub(crate) fn stderr_width() -> Option { - terminal_size::terminal_size_using_fd(2).map(|(Width(w), _)| w as usize) + unsafe { + terminal_size::terminal_size_using_fd(2).map(|(Width(w), _)| w as usize) + } } #[cfg(windows)] From 75e533c702b186b4eb6c1a9ae95cd488463017f8 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sat, 7 Mar 2026 07:17:09 -0800 Subject: [PATCH 2/4] Use `terminal_size_of` rather than an unsafe API. --- src/width.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/width.rs b/src/width.rs index f041c6d..6fb5476 100644 --- a/src/width.rs +++ b/src/width.rs @@ -1,26 +1,28 @@ -// Copyright 2022-2023 Martin Pool +// Copyright 2022-2026 Martin Pool //! Measure terminal width. -use terminal_size::Width; +use std::{ + io::{stderr, stdout}, + os::fd::AsFd, +}; + +use terminal_size::{terminal_size_of, Width}; + #[cfg(unix)] pub(crate) fn stdout_width() -> Option { - unsafe { - terminal_size::terminal_size_using_fd(1).map(|(Width(w), _)| w as usize) - } + terminal_size_of(stdout().as_fd()).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... + // TODO: We could get the handle for stdout to make this more precise... terminal_size::terminal_size().map(|(Width(w), _)| w as usize) } #[cfg(unix)] pub(crate) fn stderr_width() -> Option { - unsafe { - terminal_size::terminal_size_using_fd(2).map(|(Width(w), _)| w as usize) - } + terminal_size_of(stderr().as_fd()).map(|(Width(w), _)| w as usize) } #[cfg(windows)] From 3941c6a79a1ffab302df2a512bffb9a065a4bf02 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sat, 7 Mar 2026 07:17:54 -0800 Subject: [PATCH 3/4] Prepare release 0.1.6 --- Cargo.toml | 2 +- NEWS.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9de07b9..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" 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 From ebb7883ac5ca1a6a5e58ca3780b9c176fd09194b Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Sat, 7 Mar 2026 07:29:04 -0800 Subject: [PATCH 4/4] Split out Unix and Windows impls, and use terminal_size_of also on Windows. --- src/width.rs | 29 +++++------------------------ src/width/unix.rs | 14 ++++++++++++++ src/width/windows.rs | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 src/width/unix.rs create mode 100644 src/width/windows.rs diff --git a/src/width.rs b/src/width.rs index 6fb5476..4e62538 100644 --- a/src/width.rs +++ b/src/width.rs @@ -2,31 +2,12 @@ //! Measure terminal width. -use std::{ - io::{stderr, stdout}, - os::fd::AsFd, -}; - -use terminal_size::{terminal_size_of, Width}; - #[cfg(unix)] -pub(crate) fn stdout_width() -> Option { - terminal_size_of(stdout().as_fd()).map(|(Width(w), _)| w as usize) -} - -#[cfg(windows)] -pub(crate) fn stdout_width() -> Option { - // TODO: We could get the handle for stdout 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_of(stderr().as_fd()).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) +}