#include <dds/cli/dispatch_main.hpp> | #include <dds/cli/dispatch_main.hpp> | ||||
#include <dds/cli/options.hpp> | #include <dds/cli/options.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <dds/util/output.hpp> | |||||
#include <dds/util/signal.hpp> | #include <dds/util/signal.hpp> | ||||
#include <debate/debate.hpp> | #include <debate/debate.hpp> | ||||
std::setlocale(LC_CTYPE, ".utf8"); | std::setlocale(LC_CTYPE, ".utf8"); | ||||
dds::install_signal_handlers(); | dds::install_signal_handlers(); | ||||
dds::enable_ansi_console(); | |||||
dds::cli::options opts; | dds::cli::options opts; | ||||
debate::argument_parser parser; | debate::argument_parser parser; |
namespace dds { | namespace dds { | ||||
void enable_ansi_console() noexcept; | |||||
bool stdout_is_a_tty() noexcept; | bool stdout_is_a_tty() noexcept; | ||||
} // namespace dds | } // namespace dds |
using namespace dds; | using namespace dds; | ||||
void dds::enable_ansi_console() noexcept { | |||||
// unix consoles generally already support ANSI control chars by default | |||||
} | |||||
bool dds::stdout_is_a_tty() noexcept { return ::isatty(STDOUT_FILENO) != 0; } | bool dds::stdout_is_a_tty() noexcept { return ::isatty(STDOUT_FILENO) != 0; } | ||||
#endif | #endif |
#include <dds/util/output.hpp> | |||||
#if _WIN32 | #if _WIN32 | ||||
#include <dds/util/output.hpp> | |||||
#include <windows.h> | |||||
void dds::enable_ansi_console() noexcept { | |||||
auto stdio_console = ::GetStdHandle(STD_OUTPUT_HANDLE); | |||||
if (stdio_console == INVALID_HANDLE_VALUE) { | |||||
// Oh well... | |||||
return; | |||||
} | |||||
DWORD mode = 0; | |||||
if (!::GetConsoleMode(stdio_console, &mode)) { | |||||
// Failed to get the mode? | |||||
return; | |||||
} | |||||
// Set the bit! | |||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | |||||
::SetConsoleMode(stdio_console, mode); | |||||
} | |||||
bool dds::stdout_is_a_tty() noexcept { | bool dds::stdout_is_a_tty() noexcept { | ||||
// XXX: Newer Windows consoles support ANSI color, so this should be made smarter | // XXX: Newer Windows consoles support ANSI color, so this should be made smarter | ||||
return false; | |||||
auto stdio_console = ::GetStdHandle(STD_OUTPUT_HANDLE); | |||||
if (stdio_console == INVALID_HANDLE_VALUE) { | |||||
return false; | |||||
} | |||||
DWORD mode = 0; | |||||
if (!::GetConsoleMode(stdio_console, &mode)) { | |||||
// Failed to get the mode | |||||
return false; | |||||
} | |||||
return (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING); | |||||
} | } | ||||
#endif | #endif |