1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(runtime/windows): fix calculation of console size (#23873)

This commit is contained in:
Roy Ivy III 2024-08-12 16:36:37 -05:00 committed by GitHub
parent d3ced2fe43
commit a9cdfdc98e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -351,10 +351,20 @@ fn console_size_from_fd(
{ {
return Err(Error::last_os_error()); return Err(Error::last_os_error());
} }
Ok(ConsoleSize {
cols: bufinfo.dwSize.X as u32, // calculate the size of the visible window
rows: bufinfo.dwSize.Y as u32, // * 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 })
} }
} }