Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions src/width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use terminal_size::Width;
#[cfg(unix)]
pub(crate) fn stdout_width() -> Option<usize> {
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)
}
Comment on lines +8 to +10
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces an unsafe block to call terminal_size_using_fd(1) but does not document the safety invariants being relied on. Please add a brief // SAFETY: comment explaining why passing fd 1 is valid here (and under what conditions), and consider replacing the magic number with a named constant (e.g., stdout’s fd via std::io::stdout().as_raw_fd() or libc::STDOUT_FILENO) to make the intent clearer.

Copilot uses AI. Check for mistakes.
}

#[cfg(windows)]
Expand All @@ -16,7 +18,9 @@ pub(crate) fn stdout_width() -> Option<usize> {

#[cfg(unix)]
pub(crate) fn stderr_width() -> Option<usize> {
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)
}
Comment on lines +21 to +23
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as stdout: the unsafe block around terminal_size_using_fd(2) should include a // SAFETY: comment justifying the preconditions for using fd 2, and using a named constant instead of 2 would reduce ambiguity and help future maintenance.

Copilot uses AI. Check for mistakes.
}

#[cfg(windows)]
Expand Down