debug: add is_interactive_console query

This commit is contained in:
Danny Robson 2020-10-20 06:57:56 +10:00
parent 6d2be3daed
commit 6b46852902
4 changed files with 31 additions and 0 deletions

View File

@ -124,6 +124,7 @@ if (NOT WIN32)
memory/system.hpp
debug_posix.cpp
debug/crash_posix.cpp
debug/system_posix.cpp
io_posix.cpp
io_posix.hpp
library_posix.hpp
@ -147,6 +148,7 @@ if (WIN32)
APPEND UTIL_FILES
debug_win32.cpp
debug/crash_win32.cpp
debug/system_win32.cpp
exe_win32.cpp
io_win32.cpp
io_win32.hpp

View File

@ -16,4 +16,9 @@ void force_console (void);
///////////////////////////////////////////////////////////////////////////////
namespace cruft::debug {
void init (void);
/// Return true if the application appears to be running as an
/// interactive console application.
bool is_interactive_console (void);
}

10
debug/system_posix.cpp Normal file
View File

@ -0,0 +1,10 @@
#include "./system.hpp"
#include <unistd.h>
bool
cruft::debug::is_interactive_console (void)
{
return isatty (STDIN_FILENO);
}

14
debug/system_win32.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "./system.hpp"
#include <cruft/util/win32/windows.hpp>
bool cruft::debug::is_interactive_console (void)
{
HWND console_window = GetConsoleWindow ();
DWORD dwProcessId;
GetWindowThreadProcessId (console_window, &dwProcessId);
return GetCurrentProcessId () == dwProcessId;
}