Improve support to mingw

This commit is contained in:
ArthurSonzogni 2020-07-16 20:58:58 +02:00 committed by Arthur Sonzogni
parent dbfc5d0503
commit 454b14c5c6
3 changed files with 34 additions and 19 deletions

View File

@ -104,11 +104,15 @@ foreach(lib screen dom component)
endif() endif()
# Add as many warning as possible: # Add as many warning as possible:
if (MSVC) if (WIN32)
target_compile_options(${lib} PRIVATE "/W4") if (MSVC)
target_compile_options(${lib} PRIVATE "/WX") target_compile_options(${lib} PRIVATE "/W4")
target_compile_options(${lib} PRIVATE "/wd4244") target_compile_options(${lib} PRIVATE "/WX")
target_compile_options(${lib} PRIVATE "/wd4267") 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() else()
target_compile_options(${lib} PRIVATE "-Wall") target_compile_options(${lib} PRIVATE "-Wall")
target_compile_options(${lib} PRIVATE "-Wextra") target_compile_options(${lib} PRIVATE "-Wextra")
@ -117,10 +121,6 @@ foreach(lib screen dom component)
target_compile_options(${lib} PRIVATE "-Wno-sign-compare") target_compile_options(${lib} PRIVATE "-Wno-sign-compare")
endif() endif()
# Force Win32 to UNICODE
if(MSVC)
target_compile_definitions(${lib} PRIVATE UNICODE _UNICODE)
endif()
endforeach() endforeach()
if(FTXUI_ENABLE_INSTALL) if(FTXUI_ENABLE_INSTALL)

View File

@ -4,10 +4,13 @@
#include "ftxui/component/screen_interactive.hpp" #include "ftxui/component/screen_interactive.hpp"
#define DEFINE_CONSOLEV2_PROPERTIES
#include <stdio.h> #include <stdio.h>
#include <algorithm> #include <algorithm>
#include <csignal> #include <csignal>
#include <cstdlib>
#include <iostream> #include <iostream>
#include <stack> #include <stack>
#include <thread> #include <thread>
@ -18,7 +21,9 @@
#if defined(_WIN32) #if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h> #include <Windows.h>
#ifndef UNICODE #ifndef UNICODE
#error Must be compiled in UNICODE mode #error Must be compiled in UNICODE mode
@ -136,7 +141,7 @@ void OnExit(int signal) {
} }
if (signal == SIGINT) if (signal == SIGINT)
quick_exit(SIGINT); std::exit(SIGINT);
} }
auto install_signal_handler = [](int sig, SignalHandler handler) { 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(stdout_handle, out_mode); });
on_exit_functions.push([=] { SetConsoleMode(stdin_handle, in_mode); }); on_exit_functions.push([=] { SetConsoleMode(stdin_handle, in_mode); });
out_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; // https://docs.microsoft.com/en-us/windows/console/setconsolemode
out_mode |= DISABLE_NEWLINE_AUTO_RETURN; 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; // https://docs.microsoft.com/en-us/windows/console/setconsolemode
in_mode &= ~ENABLE_LINE_INPUT; const int enable_line_input = 0x0002;
in_mode |= ENABLE_VIRTUAL_TERMINAL_INPUT; const int enable_echo_input = 0x0004;
in_mode |= ENABLE_WINDOW_INPUT; 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(stdin_handle, in_mode);
SetConsoleMode(stdout_handle, out_mode); SetConsoleMode(stdout_handle, out_mode);

View File

@ -13,7 +13,9 @@
#if defined(_WIN32) #if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h> #include <Windows.h>
#endif #endif