Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If ioctl TIOCGWINSZ returns 0,0 try to use env vars instead. #893

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/terminal/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use std::os::unix::io::{IntoRawFd, RawFd};

use std::{io, mem, process};
use std::{env, io, mem, process};

// Some(Termios) -> we're in the raw mode and this is the previous mode
// None -> we're not in the raw mode
Expand Down Expand Up @@ -53,6 +53,14 @@
};

if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }).is_ok() {
// For some terminals (for example Emacs eshell/eterm) the
// ioctl with TIOCGWINSZ might falsely return 0 columns and 0
// rows. If this happens we try to use environment variables
// to determine the window size.

Check failure on line 59 in src/terminal/sys/unix.rs

View workflow job for this annotation

GitHub Actions / stable on ubuntu-latest

Diff in /home/runner/work/crossterm/crossterm/src/terminal/sys/unix.rs

Check failure on line 59 in src/terminal/sys/unix.rs

View workflow job for this annotation

GitHub Actions / stable on macOS-latest

Diff in /Users/runner/work/crossterm/crossterm/src/terminal/sys/unix.rs
if size.ws_row == 0 && size.ws_col == 0 {
swilde marked this conversation as resolved.
Show resolved Hide resolved
size.ws_row = env::var("LINES").map_or(Ok(0), |v| v.parse()).unwrap_or(0);
size.ws_col = env::var("COLUMNS").map_or(Ok(0), |v| v.parse()).unwrap_or(0);
}
return Ok(size.into());
}

Expand Down