Skip to content

Commit 020800d

Browse files
authored
Handle failures getting terminal size on windows (#386)
- Fixes #369 - Adds an error check for the return value of GetConsoleScreenBufferInfo Windows. If GetConsoleScreenBufferInfo a default size of 80 by 25 is used.
1 parent cca8f80 commit 020800d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/ArgumentParser/Usage/HelpGenerator.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ func _terminalSize() -> (width: Int, height: Int) {
353353
return (80, 25)
354354
#elseif os(Windows)
355355
var csbi: CONSOLE_SCREEN_BUFFER_INFO = CONSOLE_SCREEN_BUFFER_INFO()
356-
357-
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)
356+
guard GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi) else {
357+
return (80, 25)
358+
}
358359
return (width: Int(csbi.srWindow.Right - csbi.srWindow.Left) + 1,
359360
height: Int(csbi.srWindow.Bottom - csbi.srWindow.Top) + 1)
360361
#else

0 commit comments

Comments
 (0)