Skip to content

Commit 1423c1e

Browse files
committed
TSCBasic: use the "portable" names for terminalType
This adds the Windows path which uses the `_isatty` and `_fileno` for the conversion. This is likely still insufficiently to properly detect the stream. `_isatty` is okay in the short term, but it is better to use `GetFileType` on the `HANDLE` associated with the file descriptor. This requires better auditing to ensure that the handle is convertible to the underlying Windows handle.
1 parent 154af99 commit 1423c1e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/TSCBasic/TerminalController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ public final class TerminalController {
109109

110110
/// Computes the terminal type of the stream.
111111
public static func terminalType(_ stream: LocalFileOutputByteStream) -> TerminalType {
112+
#if os(Windows)
113+
return _isatty(_fileno(stream.filePointer)) == 0 ? .file : .tty
114+
#else
112115
if ProcessEnv.vars["TERM"] == "dumb" {
113116
return .dumb
114117
}
115118
let isTTY = isatty(fileno(stream.filePointer)) != 0
116119
return isTTY ? .tty : .file
120+
#endif
117121
}
118122

119123
/// Tries to get the terminal width first using COLUMNS env variable and

0 commit comments

Comments
 (0)