Skip to content

Commit f7c199f

Browse files
authored
Merge pull request #19 from sourcefrog/update-terminal-size
Update terminal size
2 parents 9e0bc0f + ebb7883 commit f7c199f

5 files changed

Lines changed: 42 additions & 21 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nutmeg"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2021"
55
description = "An unopinionated progress bar library"
66
license = "MIT"
@@ -12,7 +12,7 @@ rust-version = "1.75" # Could perhaps be even older, but this is 2 years at tim
1212

1313
[dependencies]
1414
atty = "0.2"
15-
terminal_size = "0.2"
15+
terminal_size = "0.4"
1616
yansi = "0.5"
1717

1818
[dev-dependencies]

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Nutmeg Changelog
22

3+
## 0.1.6
4+
5+
Released 2026-03-07
6+
7+
- Updated `terminal_size` dependency.
8+
39
## 0.1.5
410

511
Released 2025-10-05

src/width.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
1-
// Copyright 2022-2023 Martin Pool
1+
// Copyright 2022-2026 Martin Pool
22

33
//! Measure terminal width.
44
5-
use terminal_size::Width;
65
#[cfg(unix)]
7-
pub(crate) fn stdout_width() -> Option<usize> {
8-
terminal_size::terminal_size_using_fd(1).map(|(Width(w), _)| w as usize)
9-
}
10-
11-
#[cfg(windows)]
12-
pub(crate) fn stdout_width() -> Option<usize> {
13-
// TODO: We could get the handle for stderr to make this more precise...
14-
terminal_size::terminal_size().map(|(Width(w), _)| w as usize)
15-
}
16-
6+
mod unix;
177
#[cfg(unix)]
18-
pub(crate) fn stderr_width() -> Option<usize> {
19-
terminal_size::terminal_size_using_fd(2).map(|(Width(w), _)| w as usize)
20-
}
8+
pub(crate) use unix::{stderr_width, stdout_width};
219

2210
#[cfg(windows)]
23-
pub(crate) fn stderr_width() -> Option<usize> {
24-
// TODO: We could get the handle for stderr to make this more precise...
25-
terminal_size::terminal_size().map(|(Width(w), _)| w as usize)
26-
}
11+
mod windows;
12+
#[cfg(windows)]
13+
pub(crate) use windows::{stderr_width, stdout_width};

src/width/unix.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::{
2+
io::{stderr, stdout},
3+
os::fd::AsFd,
4+
};
5+
6+
use terminal_size::{terminal_size_of, Width};
7+
8+
pub(crate) fn stdout_width() -> Option<usize> {
9+
terminal_size_of(stdout().as_fd()).map(|(Width(w), _)| w as usize)
10+
}
11+
12+
pub(crate) fn stderr_width() -> Option<usize> {
13+
terminal_size_of(stderr().as_fd()).map(|(Width(w), _)| w as usize)
14+
}

src/width/windows.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::{
2+
io::{stderr, stdout},
3+
os::windows::io::AsHandle,
4+
};
5+
6+
use terminal_size::{terminal_size_of, Width};
7+
8+
pub(crate) fn stdout_width() -> Option<usize> {
9+
terminal_size_of(stdout().as_handle()).map(|(Width(w), _)| w as usize)
10+
}
11+
12+
pub(crate) fn stderr_width() -> Option<usize> {
13+
terminal_size_of(stderr().as_handle()).map(|(Width(w), _)| w as usize)
14+
}

0 commit comments

Comments
 (0)