From 966d89ae64cd71c652a1e981bc971de59d64f13d Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 23 Oct 2024 10:03:47 -0700 Subject: [PATCH] Fix Windows build break in Terminal. (#205) --- Sources/ConsoleKitTerminal/Terminal/Terminal.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/ConsoleKitTerminal/Terminal/Terminal.swift b/Sources/ConsoleKitTerminal/Terminal/Terminal.swift index 37f6265..6b92260 100644 --- a/Sources/ConsoleKitTerminal/Terminal/Terminal.swift +++ b/Sources/ConsoleKitTerminal/Terminal/Terminal.swift @@ -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. @@ -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 @@ -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 } }