From 454b14c5c67e7945e951a555d719c43995599ee3 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Thu, 16 Jul 2020 20:58:58 +0200 Subject: [PATCH] Improve support to mingw --- CMakeLists.txt | 18 ++++++------- src/ftxui/component/screen_interactive.cpp | 31 +++++++++++++++------- src/ftxui/screen/screen.cpp | 4 ++- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 276fdf3..18c0689 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,11 +104,15 @@ foreach(lib screen dom component) endif() # Add as many warning as possible: - if (MSVC) - target_compile_options(${lib} PRIVATE "/W4") - target_compile_options(${lib} PRIVATE "/WX") - target_compile_options(${lib} PRIVATE "/wd4244") - target_compile_options(${lib} PRIVATE "/wd4267") + if (WIN32) + if (MSVC) + target_compile_options(${lib} PRIVATE "/W4") + target_compile_options(${lib} PRIVATE "/WX") + target_compile_options(${lib} PRIVATE "/wd4244") + target_compile_options(${lib} PRIVATE "/wd4267") + endif() + # Force Win32 to UNICODE + target_compile_definitions(${lib} PRIVATE UNICODE _UNICODE) else() target_compile_options(${lib} PRIVATE "-Wall") target_compile_options(${lib} PRIVATE "-Wextra") @@ -117,10 +121,6 @@ foreach(lib screen dom component) target_compile_options(${lib} PRIVATE "-Wno-sign-compare") endif() - # Force Win32 to UNICODE - if(MSVC) - target_compile_definitions(${lib} PRIVATE UNICODE _UNICODE) - endif() endforeach() if(FTXUI_ENABLE_INSTALL) diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 5c1971c..d61cc42 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -4,10 +4,13 @@ #include "ftxui/component/screen_interactive.hpp" +#define DEFINE_CONSOLEV2_PROPERTIES + #include #include #include +#include #include #include #include @@ -18,8 +21,10 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN - #define NOMINMAX - #include + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include #ifndef UNICODE #error Must be compiled in UNICODE mode #endif @@ -136,7 +141,7 @@ void OnExit(int signal) { } if (signal == SIGINT) - quick_exit(SIGINT); + std::exit(SIGINT); } auto install_signal_handler = [](int sig, SignalHandler handler) { @@ -206,13 +211,21 @@ void ScreenInteractive::Loop(Component* component) { on_exit_functions.push([=] { SetConsoleMode(stdout_handle, out_mode); }); on_exit_functions.push([=] { SetConsoleMode(stdin_handle, in_mode); }); - out_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - out_mode |= DISABLE_NEWLINE_AUTO_RETURN; + // https://docs.microsoft.com/en-us/windows/console/setconsolemode + const int enable_virtual_terminal_processing = 0x0004; + const int disable_newline_auto_return = 0x0008; + out_mode |= enable_virtual_terminal_processing; + out_mode |= disable_newline_auto_return; - in_mode &= ~ENABLE_ECHO_INPUT; - in_mode &= ~ENABLE_LINE_INPUT; - in_mode |= ENABLE_VIRTUAL_TERMINAL_INPUT; - in_mode |= ENABLE_WINDOW_INPUT; + // https://docs.microsoft.com/en-us/windows/console/setconsolemode + const int enable_line_input = 0x0002; + const int enable_echo_input = 0x0004; + const int enable_virtual_terminal_input = 0x0200; + const int enable_window_input = 0x0008; + in_mode &= ~enable_echo_input; + in_mode &= ~enable_line_input; + in_mode |= enable_virtual_terminal_input; + in_mode |= enable_window_input; SetConsoleMode(stdin_handle, in_mode); SetConsoleMode(stdout_handle, out_mode); diff --git a/src/ftxui/screen/screen.cpp b/src/ftxui/screen/screen.cpp index 9dd14c2..dc72128 100644 --- a/src/ftxui/screen/screen.cpp +++ b/src/ftxui/screen/screen.cpp @@ -13,7 +13,9 @@ #if defined(_WIN32) #define WIN32_LEAN_AND_MEAN - #define NOMINMAX + #ifndef NOMINMAX + #define NOMINMAX + #endif #include #endif