mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 23:48:15 +08:00
Enable raw keyboard input (#832)
In order for applications to receive all keyboard inputs, including the Ctrl-C and Ctrl-Z, the raw input mode has been enabled. As result the SIGINT will no longer be used, instead the keyboard Ctrl-C event is used for exiting the framework, but only if no components has made use of it. Co-authored-by: Jørn Gustav Larsen <jgl@fasttracksoftware.com> Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:

committed by
GitHub

parent
d38b14ffb6
commit
d386df6f94
@@ -54,21 +54,52 @@ struct Event {
|
||||
static const Event Escape;
|
||||
static const Event Tab;
|
||||
static const Event TabReverse;
|
||||
static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
||||
|
||||
// --- Navigation keys ---
|
||||
static const Event Insert;
|
||||
static const Event Home;
|
||||
static const Event End;
|
||||
|
||||
static const Event PageUp;
|
||||
static const Event PageDown;
|
||||
|
||||
// --- Function keys ---
|
||||
static const Event F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
||||
|
||||
// --- Control keys ---
|
||||
static const Event a, A, CtrlA, AltA, CtrlAltA;
|
||||
static const Event b, B, CtrlB, AltB, CtrlAltB;
|
||||
static const Event c, C, CtrlC, AltC, CtrlAltC;
|
||||
static const Event d, D, CtrlD, AltD, CtrlAltD;
|
||||
static const Event e, E, CtrlE, AltE, CtrlAltE;
|
||||
static const Event f, F, CtrlF, AltF, CtrlAltF;
|
||||
static const Event g, G, CtrlG, AltG, CtrlAltG;
|
||||
static const Event h, H, CtrlH, AltH, CtrlAltH;
|
||||
static const Event i, I, CtrlI, AltI, CtrlAltI;
|
||||
static const Event j, J, CtrlJ, AltJ, CtrlAltJ;
|
||||
static const Event k, K, CtrlK, AltK, CtrlAltK;
|
||||
static const Event l, L, CtrlL, AltL, CtrlAltL;
|
||||
static const Event m, M, CtrlM, AltM, CtrlAltM;
|
||||
static const Event n, N, CtrlN, AltN, CtrlAltN;
|
||||
static const Event o, O, CtrlO, AltO, CtrlAltO;
|
||||
static const Event p, P, CtrlP, AltP, CtrlAltP;
|
||||
static const Event q, Q, CtrlQ, AltQ, CtrlAltQ;
|
||||
static const Event r, R, CtrlR, AltR, CtrlAltR;
|
||||
static const Event s, S, CtrlS, AltS, CtrlAltS;
|
||||
static const Event t, T, CtrlT, AltT, CtrlAltT;
|
||||
static const Event u, U, CtrlU, AltU, CtrlAltU;
|
||||
static const Event v, V, CtrlV, AltV, CtrlAltV;
|
||||
static const Event w, W, CtrlW, AltW, CtrlAltW;
|
||||
static const Event x, X, CtrlX, AltX, CtrlAltX;
|
||||
static const Event y, Y, CtrlY, AltY, CtrlAltY;
|
||||
static const Event z, Z, CtrlZ, AltZ, CtrlAltZ;
|
||||
|
||||
// --- Custom ---
|
||||
static const Event Custom;
|
||||
|
||||
//--- Method section ---------------------------------------------------------
|
||||
bool operator==(const Event& other) const { return input_ == other.input_; }
|
||||
bool operator!=(const Event& other) const { return !operator==(other); }
|
||||
bool operator<(const Event& other) const { return input_ < other.input_; }
|
||||
|
||||
const std::string& input() const { return input_; }
|
||||
|
||||
@@ -86,6 +117,9 @@ struct Event {
|
||||
bool is_cursor_shape() const { return type_ == Type::CursorShape; }
|
||||
int cursor_shape() const { return data_.cursor_shape; }
|
||||
|
||||
// Debug
|
||||
std::string DebugString() const;
|
||||
|
||||
//--- State section ----------------------------------------------------------
|
||||
ScreenInteractive* screen_ = nullptr;
|
||||
|
||||
|
@@ -16,6 +16,8 @@ struct Mouse {
|
||||
None = 3,
|
||||
WheelUp = 4,
|
||||
WheelDown = 5,
|
||||
WheelLeft = 6, /// Supported terminal only.
|
||||
WheelRight = 7, /// Supported terminal only.
|
||||
};
|
||||
|
||||
enum Motion {
|
||||
|
@@ -59,6 +59,15 @@ class ScreenInteractive : public Screen {
|
||||
// temporarily uninstalled.
|
||||
Closure WithRestoredIO(Closure);
|
||||
|
||||
// FTXUI implements handlers for Ctrl-C and Ctrl-Z. By default, these handlers
|
||||
// are executed, even if the component catches the event. This avoid users
|
||||
// handling every event to be trapped in the application. However, in some
|
||||
// cases, the application may want to handle these events itself. In this
|
||||
// case, the application can force FTXUI to not handle these events by calling
|
||||
// the following functions with force=true.
|
||||
void ForceHandleCtrlC(bool force);
|
||||
void ForceHandleCtrlZ(bool force);
|
||||
|
||||
private:
|
||||
void ExitNow();
|
||||
|
||||
@@ -114,6 +123,9 @@ class ScreenInteractive : public Screen {
|
||||
|
||||
bool frame_valid_ = false;
|
||||
|
||||
bool force_handle_ctrl_c_ = true;
|
||||
bool force_handle_ctrl_z_ = true;
|
||||
|
||||
// The style of the cursor to restore on exit.
|
||||
int cursor_reset_shape_ = 1;
|
||||
|
||||
|
@@ -9,8 +9,8 @@
|
||||
#include <string> // for string
|
||||
#include <unordered_map> // for unordered_map
|
||||
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||
#include "ftxui/screen/color.hpp" // for Color
|
||||
#include "ftxui/screen/image.hpp" // for Pixel, Image
|
||||
|
||||
#ifdef DrawText
|
||||
// Workaround for WinUsr.h (via Windows.h) defining macros that break things.
|
||||
@@ -94,7 +94,7 @@ struct Canvas {
|
||||
void DrawText(int x, int y, const std::string& value);
|
||||
void DrawText(int x, int y, const std::string& value, const Color& color);
|
||||
void DrawText(int x, int y, const std::string& value, const Stylizer& style);
|
||||
|
||||
|
||||
// Draw using directly pixels or images --------------------------------------
|
||||
// x is considered to be a multiple of 2.
|
||||
// y is considered to be a multiple of 4.
|
||||
|
@@ -36,7 +36,8 @@ class Screen : public Image {
|
||||
// Print the Screen on to the terminal.
|
||||
void Print() const;
|
||||
|
||||
// Fill the screen with space and reset any screen state, like hyperlinks, and cursor
|
||||
// Fill the screen with space and reset any screen state, like hyperlinks, and
|
||||
// cursor
|
||||
void Clear();
|
||||
|
||||
// Move the terminal cursor n-lines up with n = dimy().
|
||||
|
Reference in New Issue
Block a user