Skip to content

Commit

Permalink
Return Window even when pixel measurements not reported in ioctl (#115
Browse files Browse the repository at this point in the history
)

Co-authored-by: Dhruv Bhanushali <[email protected]>
  • Loading branch information
erikjuhani and dhruvkb authored Oct 7, 2024
1 parent bb29ea9 commit f8fdfa4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use log::debug;
use std::sync::LazyLock;

static PLS: LazyLock<Pls> = LazyLock::new(|| {
let (supports_gfx, window) = match (is_supported(), Window::try_new()) {
(true, Some(window)) => (true, Some(window)),
_ => (false, None),
let window = Window::try_new();
let supports_gfx = match &window {
Some(win) if win.ws_xpixel > 0 && win.ws_ypixel > 0 => is_supported(),
_ => false,
};

Pls {
Expand Down
2 changes: 1 addition & 1 deletion src/models/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl Window {
let mut win = Self::default();
#[allow(clippy::useless_conversion)]
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut win) };
if r == 0 && win.ws_xpixel > win.ws_col && win.ws_ypixel > win.ws_row {
if r == 0 && win.ws_row > 0 && win.ws_col > 0 {
return Some(win);
}
warn!("Could not determine cell dimensions.");
Expand Down

0 comments on commit f8fdfa4

Please sign in to comment.