File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,14 @@ public final class TerminalController {
121
121
///
122
122
/// - Returns: Current width of terminal if it was determinable.
123
123
public static func terminalWidth( ) -> Int ? {
124
+ #if os(Windows)
125
+ var csbi : CONSOLE_SCREEN_BUFFER_INFO = CONSOLE_SCREEN_BUFFER_INFO ( )
126
+ if !GetConsoleScreenBufferInfo( GetStdHandle ( STD_OUTPUT_HANDLE) , & csbi) {
127
+ // GetLastError()
128
+ return nil
129
+ }
130
+ return Int ( csbi. srWindow. Right - csbi. srWindow. Left) + 1
131
+ #else
124
132
// Try to get from environment.
125
133
if let columns = ProcessEnv . vars [ " COLUMNS " ] , let width = Int ( columns) {
126
134
return width
@@ -130,13 +138,14 @@ public final class TerminalController {
130
138
// Following code does not compile on ppc64le well. TIOCGWINSZ is
131
139
// defined in system ioctl.h file which needs to be used. This is
132
140
// a temporary arrangement and needs to be fixed.
133
- #if !( arch(powerpc64le) || os(Windows) )
141
+ #if !arch(powerpc64le)
134
142
var ws = winsize ( )
135
143
if ioctl ( 1 , UInt ( TIOCGWINSZ) , & ws) == 0 {
136
144
return Int ( ws. ws_col)
137
145
}
138
146
#endif
139
147
return nil
148
+ #endif
140
149
}
141
150
142
151
/// Flushes the stream.
You can’t perform that action at this time.
0 commit comments