Skip to content

Commit

Permalink
Improvements suggested by Josh McKinney.
Browse files Browse the repository at this point in the history
- Added comment with rational for window size fallback mechanism.
- Only unwrap once during parsing of env vars.
  • Loading branch information
swilde committed May 22, 2024
1 parent d24f4d9 commit 4a61d41
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/terminal/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ pub(crate) fn window_size() -> io::Result<WindowSize> {
};

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 {
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();
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

0 comments on commit 4a61d41

Please sign in to comment.