mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 18:59:59 +08:00
commit
86007c8d00
@ -107,6 +107,7 @@ foreach(lib screen dom component)
|
||||
target_compile_options(${lib} PRIVATE "/W4")
|
||||
target_compile_options(${lib} PRIVATE "/WX")
|
||||
target_compile_options(${lib} PRIVATE "/wd4244")
|
||||
target_compile_options(${lib} PRIVATE "/wd4267")
|
||||
else()
|
||||
target_compile_options(${lib} PRIVATE "-Wall")
|
||||
target_compile_options(${lib} PRIVATE "-Wextra")
|
||||
|
@ -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 */
|
@ -13,7 +13,8 @@
|
||||
#include "ftxui/screen/string.hpp"
|
||||
#include "ftxui/screen/terminal.hpp"
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
@ -39,7 +40,7 @@ void CharToEventStream(Receiver<char> receiver, Sender<Event> sender) {
|
||||
Event::Convert(receiver, sender, c);
|
||||
}
|
||||
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
|
||||
void Win32EventListener(std::atomic<bool>* quit,
|
||||
Sender<char> char_sender,
|
||||
@ -162,7 +163,7 @@ void ScreenInteractive::PostEvent(Event event) {
|
||||
|
||||
void ScreenInteractive::Loop(Component* component) {
|
||||
// Save the old terminal configuration and restore it on exit.
|
||||
#if defined(WIN32)
|
||||
#if defined(_WIN32)
|
||||
// Enable VT processing on stdout and stdin
|
||||
auto stdout_handle = GetStdHandle(STD_OUTPUT_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));
|
||||
|
||||
// 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_listener =
|
||||
std::thread(&Win32EventListener, &quit_, std::move(char_sender),
|
||||
|
@ -7,7 +7,8 @@
|
||||
#include "ftxui/screen/string.hpp"
|
||||
#include "ftxui/screen/terminal.hpp"
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
@ -75,7 +76,7 @@ Screen::Screen(int dimx, int dimy)
|
||||
dimx_(dimx),
|
||||
dimy_(dimy),
|
||||
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
|
||||
// anybody who instantiates a Screen object eventually wants to output
|
||||
// something to the console.
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
@ -18,7 +19,7 @@ namespace ftxui {
|
||||
Terminal::Dimensions Terminal::Size() {
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
return Dimensions{80, 43};
|
||||
#elif defined(WIN32)
|
||||
#elif defined(_WIN32)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
int columns, rows;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user