Skip to content

Commit

Permalink
Fix Windows build break in Terminal. (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdav authored Oct 23, 2024
1 parent a44d671 commit 966d89a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/ConsoleKitTerminal/Terminal/Terminal.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Foundation
import NIOConcurrencyHelpers
#if os(Windows)
import WinSDK
#endif

/// Generic console that uses a mixture of Swift standard
/// library and Foundation code to fulfill protocol requirements.
Expand Down Expand Up @@ -72,8 +75,8 @@ public final class Terminal: Console, Sendable {
let c = _getch()
if c == 0x0d || c == 0x0a {
break
} else if isprint(c) {
pass.append(Character(Unicode.Scalar(c)))
} else if isprint(c) != 0, let scalar = Unicode.Scalar(UInt32(c)) {
pass.append(Character(scalar))
}
}
#endif
Expand Down Expand Up @@ -134,9 +137,15 @@ public final class Terminal: Console, Sendable {

/// See `Console`
public var size: (width: Int, height: Int) {
#if os(Windows)
var csbi = CONSOLE_SCREEN_BUFFER_INFO()
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)
return (Int(csbi.dwSize.X), Int(csbi.dwSize.Y))
#else
var w = winsize()
_ = ioctl(STDOUT_FILENO, UInt(TIOCGWINSZ), &w);
return (Int(w.ws_col), Int(w.ws_row))
#endif
}
}

Expand Down

0 comments on commit 966d89a

Please sign in to comment.