diff --git a/CMakeLists.txt b/CMakeLists.txt index f212562a..0bdf74ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/debug/system.hpp b/debug/system.hpp index 1ec872d8..a0204216 100644 --- a/debug/system.hpp +++ b/debug/system.hpp @@ -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); } diff --git a/debug/system_posix.cpp b/debug/system_posix.cpp new file mode 100644 index 00000000..a79fbb46 --- /dev/null +++ b/debug/system_posix.cpp @@ -0,0 +1,10 @@ +#include "./system.hpp" + +#include + + +bool +cruft::debug::is_interactive_console (void) +{ + return isatty (STDIN_FILENO); +} diff --git a/debug/system_win32.cpp b/debug/system_win32.cpp new file mode 100644 index 00000000..98600f1f --- /dev/null +++ b/debug/system_win32.cpp @@ -0,0 +1,14 @@ +#include "./system.hpp" + +#include + + +bool cruft::debug::is_interactive_console (void) +{ + HWND console_window = GetConsoleWindow (); + + DWORD dwProcessId; + GetWindowThreadProcessId (console_window, &dwProcessId); + + return GetCurrentProcessId () == dwProcessId; +} \ No newline at end of file