[+] bool Aurora::Console::ConsoleStd::IsStdOutTTY[(AuUInt handle), ()]]

[+] Check for TTY validity on ConsoleTTY start
This commit is contained in:
Reece Wilson 2022-07-21 01:25:38 +01:00
parent ad4c18abe7
commit cb2b58eb52
3 changed files with 52 additions and 1 deletions

View File

@ -7,6 +7,12 @@
***/
#pragma once
namespace Aurora::Console::ConsoleStd
{
bool IsStdOutTTY(AuUInt handle);
bool IsStdOutTTY();
}
#include "ENoncanonicalInput.hpp"
#include "NoncanonicalInput.hpp"
#include "NoncanonicalAPI.hpp"

View File

@ -384,6 +384,47 @@ namespace Aurora::Console::ConsoleStd
}
#endif
bool IsStdOutTTY()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
HANDLE hConsole;
DWORD dwType;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (!(dwType = GetFileType(hConsole)))
{
return false;
}
return dwType == FILE_TYPE_CHAR;
#else
return IsStdOutTTY(stdout);
#endif
}
bool IsStdOutTTY(AuUInt handle)
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
HANDLE hConsole {(HANDLE)handle};
DWORD dwType;
if (handle == 0 || (AuUInt)INVALID_HANDLE_VALUE == handle)
{
return false;
}
if (!(dwType = GetFileType(hConsole)))
{
return false;
}
return dwType == FILE_TYPE_CHAR;
#else
return ::isatty((int)handle);
#endif
}
AuList<NoncanonicalInput> DequeueNoncanonicalInput()
{
AU_LOCK_GUARD(gRingLock);

View File

@ -43,6 +43,11 @@ namespace Aurora::Console::ConsoleTTY
bool TTYConsole::Start()
{
if (!ConsoleStd::IsStdOutTTY())
{
return false;
}
gTTYConsoleEnabled = true;
#if defined(AURORA_IS_MODERNNT_DERIVED)
@ -62,7 +67,6 @@ namespace Aurora::Console::ConsoleTTY
}
#endif
return true;
}