From 53fcc9df534f6fd60e2a58f4745db4094c99f0c0 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 2 Mar 2020 14:44:53 +0100 Subject: [PATCH] src/console_win32.cpp: define _getNativeHandle() and use that instead of hard coded stdout. --- src/console_win32.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/console_win32.cpp b/src/console_win32.cpp index af99a2a..d3b1614 100644 --- a/src/console_win32.cpp +++ b/src/console_win32.cpp @@ -48,10 +48,20 @@ namespace eoskeygen { namespace console { +HANDLE _getNativeHandle(const std::ostream& os) { + + if (&os == &std::cout) { + return ::GetStdHandle(STD_OUTPUT_HANDLE); + } else if (&os == &std::cerr) { + return ::GetStdHandle(STD_ERROR_HANDLE); + } + return NULL; +} + std::ostream& reset(std::ostream& os) { if (isColorsSupported(os)) { - ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), FG_DEFAULT); + ::SetConsoleTextAttribute(_getNativeHandle(os), FG_DEFAULT); } return os; } @@ -84,7 +94,7 @@ std::ostream& operator<<(std::ostream& os, const fg& obj) { code = FG_DEFAULT; } - ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), code); + ::SetConsoleTextAttribute(_getNativeHandle(os), code); } // WinAPI does not support text attributes in the console.