mirror of https://github.com/adamdruppe/arsd.git
new method to check if valid to create Terminal;
This commit is contained in:
parent
2fa8f7cfa9
commit
3bcce8b478
19
terminal.d
19
terminal.d
|
@ -434,6 +434,25 @@ struct Terminal {
|
|||
@disable this(this);
|
||||
private ConsoleOutputType type;
|
||||
|
||||
/++
|
||||
Terminal is only valid to use on an actual console device or terminal
|
||||
handle. You should not attempt to construct a Terminal instance if this
|
||||
returns false;
|
||||
+/
|
||||
static bool stdoutIsTerminal() {
|
||||
version(Posix) {
|
||||
import core.sys.posix.unistd;
|
||||
return cast(bool) isatty(1);
|
||||
} else version(Windows) {
|
||||
auto hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
CONSOLE_SCREEN_BUFFER_INFO originalSbi;
|
||||
if(GetConsoleScreenBufferInfo(hConsole, &originalSbi) == 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
} else static assert(0);
|
||||
}
|
||||
|
||||
version(Posix) {
|
||||
private int fdOut;
|
||||
private int fdIn;
|
||||
|
|
Loading…
Reference in New Issue