Merge pull request #12 from mauve/master

Assorted win32 cleanups
This commit is contained in:
Arthur Sonzogni 2020-03-25 18:29:52 +01:00 committed by GitHub
commit 86007c8d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 63 deletions

View File

@ -107,6 +107,7 @@ foreach(lib screen dom component)
target_compile_options(${lib} PRIVATE "/W4") target_compile_options(${lib} PRIVATE "/W4")
target_compile_options(${lib} PRIVATE "/WX") target_compile_options(${lib} PRIVATE "/WX")
target_compile_options(${lib} PRIVATE "/wd4244") target_compile_options(${lib} PRIVATE "/wd4244")
target_compile_options(${lib} PRIVATE "/wd4267")
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")

View File

@ -1,55 +0,0 @@
#ifndef FTXUI_COMPONENT_EVENT_INPUT_LISTENER_HPP
#define FTXUI_COMPONENT_EVENT_INPUT_LISTENER_HPP
#include <atomic>
#include <functional>
#include <thread>
#include "event.hpp"
#ifdef WIN32
#include <condition_variable>
#include <deque>
#include <mutex>
#endif
namespace ftxui {
// Receives input events from the OS and turns them into
// Event objects and sends to a consumer
//
// On NIX systems:
// - uses SIGWINCH for resize
// - uses getchar() for keypresses
//
// On Windows systems:
// - Uses ReadConsoleInput for resize and keypresses
class EventInputListener {
public:
EventInputListener(std::function<void(Event)> consumer);
~EventInputListener();
void stop();
private:
char readchar();
void readchar_thread_func(std::function<void(Event)> consumer);
std::atomic<bool> quit_{false};
std::thread readchar_thread_;
#ifndef _WIN32
using signal_handler_t = void (*)(int);
signal_handler_t old_sigwinch_handler_;
#else
void input_thread_func(std::function<void(Event)> consumer);
std::mutex input_queue_mutex_;
std::condition_variable input_queue_condvar_;
std::deque<char> input_queue_;
std::thread input_event_thread_;
#endif
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_EVENT_INPUT_LISTENER_HPP */

View File

@ -13,7 +13,8 @@
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
#if defined(WIN32)
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
@ -39,7 +40,7 @@ void CharToEventStream(Receiver<char> receiver, Sender<Event> sender) {
Event::Convert(receiver, sender, c); Event::Convert(receiver, sender, c);
} }
#if defined(WIN32) #if defined(_WIN32)
void Win32EventListener(std::atomic<bool>* quit, void Win32EventListener(std::atomic<bool>* quit,
Sender<char> char_sender, Sender<char> char_sender,
@ -162,7 +163,7 @@ void ScreenInteractive::PostEvent(Event event) {
void ScreenInteractive::Loop(Component* component) { void ScreenInteractive::Loop(Component* component) {
// Save the old terminal configuration and restore it on exit. // Save the old terminal configuration and restore it on exit.
#if defined(WIN32) #if defined(_WIN32)
// Enable VT processing on stdout and stdin // Enable VT processing on stdout and stdin
auto stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); auto stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
auto stdin_handle = GetStdHandle(STD_INPUT_HANDLE); auto stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
@ -217,7 +218,7 @@ void ScreenInteractive::Loop(Component* component) {
CharToEventStream, std::move(char_receiver), std::move(event_sender_1)); CharToEventStream, std::move(char_receiver), std::move(event_sender_1));
// Depending on the OS, start a thread that will produce events and/or chars. // Depending on the OS, start a thread that will produce events and/or chars.
#if defined(WIN32) #if defined(_WIN32)
auto event_sender_2 = event_receiver_->MakeSender(); auto event_sender_2 = event_receiver_->MakeSender();
auto event_listener = auto event_listener =
std::thread(&Win32EventListener, &quit_, std::move(char_sender), std::thread(&Win32EventListener, &quit_, std::move(char_sender),

View File

@ -7,7 +7,8 @@
#include "ftxui/screen/string.hpp" #include "ftxui/screen/string.hpp"
#include "ftxui/screen/terminal.hpp" #include "ftxui/screen/terminal.hpp"
#if defined(WIN32)
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
@ -75,7 +76,7 @@ Screen::Screen(int dimx, int dimy)
dimx_(dimx), dimx_(dimx),
dimy_(dimy), dimy_(dimy),
pixels_(dimy, std::vector<Pixel>(dimx)) { pixels_(dimy, std::vector<Pixel>(dimx)) {
#if defined(WIN32) #if defined(_WIN32)
// The placement of this call is a bit weird, however we can assume that // The placement of this call is a bit weird, however we can assume that
// anybody who instantiates a Screen object eventually wants to output // anybody who instantiates a Screen object eventually wants to output
// something to the console. // something to the console.

View File

@ -2,7 +2,8 @@
#include <stdio.h> #include <stdio.h>
#if defined(WIN32)
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
@ -18,7 +19,7 @@ namespace ftxui {
Terminal::Dimensions Terminal::Size() { Terminal::Dimensions Terminal::Size() {
#if defined(__EMSCRIPTEN__) #if defined(__EMSCRIPTEN__)
return Dimensions{80, 43}; return Dimensions{80, 43};
#elif defined(WIN32) #elif defined(_WIN32)
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
int columns, rows; int columns, rows;