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 1 commit
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
6 changes: 5 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::fs::File;

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,10 @@ pub(crate) fn window_size() -> io::Result<WindowSize> {
};

if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }).is_ok() {
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").unwrap_or("0".to_string()).parse::<u16>().unwrap();
size.ws_col = env::var("COLUMNS").unwrap_or("0".to_string()).parse::<u16>().unwrap();
swilde marked this conversation as resolved.
Show resolved Hide resolved
}
return Ok(size.into());
}

Expand Down