From 158cae043bdc3db055e1d029aa2a1b8261d9140a Mon Sep 17 00:00:00 2001 From: modeco80 Date: Tue, 22 Aug 2023 16:53:16 -0400 Subject: [PATCH] forgot windows has to be fucking special --- src/main.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index a09325e..a980790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,31 @@ #include "fprint.hpp" #include "worker.hpp" +#ifdef _WIN32 +#define _WIN32_LEAN_AND_MEAN +#include + +std::uint32_t lastVtMode = 0; + +void EnableVtMode() { + GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &lastVtMode); + auto newMode = lastVtMode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING; + SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), newMode); +} + +void DisableVtMode() { + SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), lastVtMode); +} + +struct ScopedVtMode { + ScopedVtMode() { EnableVtMode(); } + ~ScopedVtMode() { DisableVtMode(); } + ScopedVtMode(const ScopedVtMode&) = delete; + ScopedVtMode(ScopedVtMode&&) = delete; +}; + +#endif + struct Arguments { bool exact { false }; std::uint32_t startLength = 2; @@ -119,6 +144,9 @@ struct Arguments { }; int main(int argc, char** argv) { +#ifdef _WIN32 + ScopedVtMode vtmode; +#endif auto args = Arguments::FromArgv(argc, argv); if(!args.Validate()) { return 1;