Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurSonzogni committed Apr 6, 2024
1 parent 2b5f6d8 commit 0bc1b0f
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 136 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<img src="https://codecov.io/gh/ArthurSonzogni/FTXUI/branch/master/graph/badge.svg?token=C41FdRpNVA"/>
</a>


<br/>
<a href="https://arthursonzogni.github.io/FTXUI/">Documentation</a> ·
<a href="https://github.com/ArthurSonzogni/FTXUI/issues">Report a Bug</a> ·
Expand Down
30 changes: 17 additions & 13 deletions examples/component/print_key_press.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <string> // for char_traits, operator+, string, basic_string, to_string
#include <utility> // for move
#include <vector> // for vector
#include <map> // for map

#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
Expand All @@ -32,30 +31,35 @@ int main() {

std::vector<Event> keys;

auto component = Renderer([&] {
Elements left_column = {
auto left_column = Renderer([&] {
Elements children = {
text("Codes"),
separator(),
};
Elements right_column {
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
children.push_back(text(Code(keys[i])));
}
return vbox(children);
});

auto right_column = Renderer([&] {
Elements children = {
text("Event"),
separator(),
};
for (size_t i = std::max(0, (int)keys.size() - 20); i < keys.size(); ++i) {
left_column.push_back(text(Code(keys[i])));
right_column.push_back(text(keys[i].DebugString()));
children.push_back(text(keys[i].DebugString()));
}
return window(text("keys"), hbox({
vbox(left_column) | flex,
separator(),
vbox(right_column) | flex,
}));
return vbox(children);
});

int split_size = 40;
auto component = ResizableSplitLeft(left_column, right_column, &split_size);
component |= border;

component |= CatchEvent([&](Event event) {
keys.push_back(event);

return event != Event::CtrlC;
return false;
});

screen.Loop(component);
Expand Down
125 changes: 29 additions & 96 deletions include/ftxui/component/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,110 +55,43 @@ struct Event {
static const Event Tab;
static const Event TabReverse;

// --- Function keys ---
static const Event F1;
static const Event F2;
static const Event F3;
static const Event F4;
static const Event F5;
static const Event F6;
static const Event F7;
static const Event F8;
static const Event F9;
static const Event F10;
static const Event F11;
static const Event 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 CtrlA;
static const Event CtrlB;
static const Event CtrlC;
static const Event CtrlD;
static const Event CtrlE;
static const Event CtrlF;
static const Event CtrlG;
static const Event CtrlH;
static const Event CtrlI;
static const Event CtrlJ;
static const Event CtrlK;
static const Event CtrlL;
static const Event CtrlM;
static const Event CtrlN;
static const Event CtrlO;
static const Event CtrlP;
static const Event CtrlQ;
static const Event CtrlR;
static const Event CtrlS;
static const Event CtrlT;
static const Event CtrlU;
static const Event CtrlV;
static const Event CtrlW;
static const Event CtrlX;
static const Event CtrlY;
static const Event CtrlZ;

// --- Alt keys ---
static const Event AltA;
static const Event AltB;
static const Event AltC;
static const Event AltD;
static const Event AltE;
static const Event AltF;
static const Event AltG;
static const Event AltH;
static const Event AltI;
static const Event AltJ;
static const Event AltK;
static const Event AltL;
static const Event AltM;
static const Event AltN;
static const Event AltO;
static const Event AltP;
static const Event AltQ;
static const Event AltR;
static const Event AltS;
static const Event AltT;
static const Event AltU;
static const Event AltV;
static const Event AltW;
static const Event AltX;
static const Event AltY;
static const Event AltZ;

// --- Ctrl+Alt keys ---
static const Event CtrlAltA;
static const Event CtrlAltB;
static const Event CtrlAltC;
static const Event CtrlAltD;
static const Event CtrlAltE;
static const Event CtrlAltF;
static const Event CtrlAltG;
static const Event CtrlAltH;
static const Event CtrlAltI;
static const Event CtrlAltJ;
static const Event CtrlAltK;
static const Event CtrlAltL;
static const Event CtrlAltM;
static const Event CtrlAltN;
static const Event CtrlAltO;
static const Event CtrlAltP;
static const Event CtrlAltQ;
static const Event CtrlAltR;
static const Event CtrlAltS;
static const Event CtrlAltT;
static const Event CtrlAltU;
static const Event CtrlAltV;
static const Event CtrlAltW;
static const Event CtrlAltX;
static const Event CtrlAltY;
static const Event CtrlAltZ;
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;
Expand Down
106 changes: 80 additions & 26 deletions src/ftxui/component/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,60 @@ const Event Event::End = Event::Special({27, 91, 70}); // NOLINT
const Event Event::PageUp = Event::Special({27, 91, 53, 126}); // NOLINT
const Event Event::PageDown = Event::Special({27, 91, 54, 126}); // NOLINT
const Event Event::Custom = Event::Special({0}); // NOLINT
//
const Event Event::a = Event::Character("a"); // NOLINT
const Event Event::b = Event::Character("b"); // NOLINT
const Event Event::c = Event::Character("c"); // NOLINT
const Event Event::d = Event::Character("d"); // NOLINT
const Event Event::e = Event::Character("e"); // NOLINT
const Event Event::f = Event::Character("f"); // NOLINT
const Event Event::g = Event::Character("g"); // NOLINT
const Event Event::h = Event::Character("h"); // NOLINT
const Event Event::i = Event::Character("i"); // NOLINT
const Event Event::j = Event::Character("j"); // NOLINT
const Event Event::k = Event::Character("k"); // NOLINT
const Event Event::l = Event::Character("l"); // NOLINT
const Event Event::m = Event::Character("m"); // NOLINT
const Event Event::n = Event::Character("n"); // NOLINT
const Event Event::o = Event::Character("o"); // NOLINT
const Event Event::p = Event::Character("p"); // NOLINT
const Event Event::q = Event::Character("q"); // NOLINT
const Event Event::r = Event::Character("r"); // NOLINT
const Event Event::s = Event::Character("s"); // NOLINT
const Event Event::t = Event::Character("t"); // NOLINT
const Event Event::u = Event::Character("u"); // NOLINT
const Event Event::v = Event::Character("v"); // NOLINT
const Event Event::w = Event::Character("w"); // NOLINT
const Event Event::x = Event::Character("x"); // NOLINT
const Event Event::y = Event::Character("y"); // NOLINT
const Event Event::z = Event::Character("z"); // NOLINT

const Event Event::A = Event::Character("A"); // NOLINT
const Event Event::B = Event::Character("B"); // NOLINT
const Event Event::C = Event::Character("C"); // NOLINT
const Event Event::D = Event::Character("D"); // NOLINT
const Event Event::E = Event::Character("E"); // NOLINT
const Event Event::F = Event::Character("F"); // NOLINT
const Event Event::G = Event::Character("G"); // NOLINT
const Event Event::H = Event::Character("H"); // NOLINT
const Event Event::I = Event::Character("I"); // NOLINT
const Event Event::J = Event::Character("J"); // NOLINT
const Event Event::K = Event::Character("K"); // NOLINT
const Event Event::L = Event::Character("L"); // NOLINT
const Event Event::M = Event::Character("M"); // NOLINT
const Event Event::N = Event::Character("N"); // NOLINT
const Event Event::O = Event::Character("O"); // NOLINT
const Event Event::P = Event::Character("P"); // NOLINT
const Event Event::Q = Event::Character("Q"); // NOLINT
const Event Event::R = Event::Character("R"); // NOLINT
const Event Event::S = Event::Character("S"); // NOLINT
const Event Event::T = Event::Character("T"); // NOLINT
const Event Event::U = Event::Character("U"); // NOLINT
const Event Event::V = Event::Character("V"); // NOLINT
const Event Event::W = Event::Character("W"); // NOLINT
const Event Event::X = Event::Character("X"); // NOLINT
const Event Event::Y = Event::Character("Y"); // NOLINT
const Event Event::Z = Event::Character("Z"); // NOLINT

const Event Event::CtrlA = Event::Special("\x01"); // NOLINT
const Event Event::CtrlB = Event::Special("\x02"); // NOLINT
Expand Down Expand Up @@ -338,32 +392,32 @@ const Event Event::CtrlX = Event::Special("\x18"); // NOLINT
const Event Event::CtrlY = Event::Special("\x19"); // NOLINT
const Event Event::CtrlZ = Event::Special("\x1a"); // NOLINT

const Event Event::AltA = Event::Special("\x1b\x61"); // NOLINT
const Event Event::AltB = Event::Special("\x1b\x62"); // NOLINT
const Event Event::AltC = Event::Special("\x1b\x63"); // NOLINT
const Event Event::AltD = Event::Special("\x1b\x64"); // NOLINT
const Event Event::AltE = Event::Special("\x1b\x65"); // NOLINT
const Event Event::AltF = Event::Special("\x1b\x66"); // NOLINT
const Event Event::AltG = Event::Special("\x1b\x67"); // NOLINT
const Event Event::AltH = Event::Special("\x1b\x68"); // NOLINT
const Event Event::AltI = Event::Special("\x1b\x69"); // NOLINT
const Event Event::AltJ = Event::Special("\x1b\x6a"); // NOLINT
const Event Event::AltK = Event::Special("\x1b\x6b"); // NOLINT
const Event Event::AltL = Event::Special("\x1b\x6c"); // NOLINT
const Event Event::AltM = Event::Special("\x1b\x6d"); // NOLINT
const Event Event::AltN = Event::Special("\x1b\x6e"); // NOLINT
const Event Event::AltO = Event::Special("\x1b\x6f"); // NOLINT
const Event Event::AltP = Event::Special("\x1b\x70"); // NOLINT
const Event Event::AltQ = Event::Special("\x1b\x71"); // NOLINT
const Event Event::AltR = Event::Special("\x1b\x72"); // NOLINT
const Event Event::AltS = Event::Special("\x1b\x73"); // NOLINT
const Event Event::AltT = Event::Special("\x1b\x74"); // NOLINT
const Event Event::AltU = Event::Special("\x1b\x75"); // NOLINT
const Event Event::AltV = Event::Special("\x1b\x76"); // NOLINT
const Event Event::AltW = Event::Special("\x1b\x77"); // NOLINT
const Event Event::AltX = Event::Special("\x1b\x78"); // NOLINT
const Event Event::AltY = Event::Special("\x1b\x79"); // NOLINT
const Event Event::AltZ = Event::Special("\x1b\x7a"); // NOLINT
const Event Event::AltA = Event::Special("\x1b""a"); // NOLINT
const Event Event::AltB = Event::Special("\x1b""b"); // NOLINT
const Event Event::AltC = Event::Special("\x1b""c"); // NOLINT
const Event Event::AltD = Event::Special("\x1b""d"); // NOLINT
const Event Event::AltE = Event::Special("\x1b""e"); // NOLINT
const Event Event::AltF = Event::Special("\x1b""f"); // NOLINT
const Event Event::AltG = Event::Special("\x1b""g"); // NOLINT
const Event Event::AltH = Event::Special("\x1b""h"); // NOLINT
const Event Event::AltI = Event::Special("\x1b""i"); // NOLINT
const Event Event::AltJ = Event::Special("\x1b""j"); // NOLINT
const Event Event::AltK = Event::Special("\x1b""k"); // NOLINT
const Event Event::AltL = Event::Special("\x1b""l"); // NOLINT
const Event Event::AltM = Event::Special("\x1b""m"); // NOLINT
const Event Event::AltN = Event::Special("\x1b""n"); // NOLINT
const Event Event::AltO = Event::Special("\x1b""o"); // NOLINT
const Event Event::AltP = Event::Special("\x1b""p"); // NOLINT
const Event Event::AltQ = Event::Special("\x1b""q"); // NOLINT
const Event Event::AltR = Event::Special("\x1b""r"); // NOLINT
const Event Event::AltS = Event::Special("\x1b""s"); // NOLINT
const Event Event::AltT = Event::Special("\x1b""t"); // NOLINT
const Event Event::AltU = Event::Special("\x1b""u"); // NOLINT
const Event Event::AltV = Event::Special("\x1b""v"); // NOLINT
const Event Event::AltW = Event::Special("\x1b""w"); // NOLINT
const Event Event::AltX = Event::Special("\x1b""x"); // NOLINT
const Event Event::AltY = Event::Special("\x1b""y"); // NOLINT
const Event Event::AltZ = Event::Special("\x1b""z"); // NOLINT

const Event Event::CtrlAltA = Event::Special("\x1b\x01"); // NOLINT
const Event Event::CtrlAltB = Event::Special("\x1b\x02"); // NOLINT
Expand Down

0 comments on commit 0bc1b0f

Please sign in to comment.