Skip to content

Commit 7012613

Browse files
leogrekoops
authored andcommitted
refactor(ctl): use rustix::termios::tcgetwinsize instead of ioctl
Co-authored-by: Leonardo Di Giovanna <leonardodigiovanna1@gmail.com> Signed-off-by: Leonardo Grasso <me@leonardograsso.com>
1 parent aea9c33 commit 7012613

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

tools/premptictl/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ serde_json = "1"
1616
libc = "0.2"
1717
# `process` enables `kill_process` / `test_kill_process` (safe wrappers
1818
# around `kill(pid, sig)` and `kill(pid, 0)`).
19-
rustix = { version = "1", features = ["process"] }
19+
# `termios` enables `tcgetwinsize` (safe wrapper around `ioctl(TIOCGWINSZ)`).
20+
rustix = { version = "1", features = ["process", "termios"] }
2021

2122
[target.'cfg(windows)'.dependencies]
2223
uds_windows = "1.2"

tools/premptictl/src/logs_pretty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,9 +1597,7 @@ pub fn detect_term_size() -> (usize, usize) {
15971597
#[cfg(unix)]
15981598
{
15991599
if cols.is_none() || rows.is_none() {
1600-
let mut ws: libc::winsize = unsafe { std::mem::zeroed() };
1601-
let r = unsafe { libc::ioctl(libc::STDOUT_FILENO, libc::TIOCGWINSZ, &mut ws) };
1602-
if r == 0 {
1600+
if let Ok(ws) = rustix::termios::tcgetwinsize(std::io::stdout()) {
16031601
if cols.is_none() && ws.ws_col > 20 {
16041602
cols = Some(ws.ws_col as usize);
16051603
}

0 commit comments

Comments
 (0)