diff options
author | Roy Ivy III <rivy.dev@gmail.com> | 2024-08-12 16:36:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-12 17:36:37 -0400 |
commit | a9cdfdc98ec4ef4b4e608537acd828d35a936a60 (patch) | |
tree | 241d7b45280a0830073c47c15d8ae5cc99347583 /runtime/ops | |
parent | d3ced2fe43262dacca4ff0b38dd90ad91db26cd7 (diff) |
fix(runtime/windows): fix calculation of console size (#23873)
Diffstat (limited to 'runtime/ops')
-rw-r--r-- | runtime/ops/tty.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/ops/tty.rs b/runtime/ops/tty.rs index be22bdd2a..5b49e3a24 100644 --- a/runtime/ops/tty.rs +++ b/runtime/ops/tty.rs @@ -351,10 +351,20 @@ fn console_size_from_fd( { return Err(Error::last_os_error()); } - Ok(ConsoleSize { - cols: bufinfo.dwSize.X as u32, - rows: bufinfo.dwSize.Y as u32, - }) + + // calculate the size of the visible window + // * use over/under-flow protections b/c MSDN docs only imply that srWindow components are all non-negative + // * ref: <https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str> @@ <https://archive.is/sfjnm> + let cols = std::cmp::max( + bufinfo.srWindow.Right as i32 - bufinfo.srWindow.Left as i32 + 1, + 0, + ) as u32; + let rows = std::cmp::max( + bufinfo.srWindow.Bottom as i32 - bufinfo.srWindow.Top as i32 + 1, + 0, + ) as u32; + + Ok(ConsoleSize { cols, rows }) } } |