mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-27 21:58:29 +08:00
d386df6f94
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>
67 lines
2.0 KiB
C++
67 lines
2.0 KiB
C++
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
// the LICENSE file.
|
|
|
|
#include <stddef.h> // for size_t
|
|
#include <algorithm> // for max
|
|
#include <memory> // for allocator, shared_ptr
|
|
#include <string> // for char_traits, operator+, string, basic_string, to_string
|
|
#include <utility> // for move
|
|
#include <vector> // for vector
|
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
|
#include "ftxui/component/component.hpp" // for CatchEvent, Renderer
|
|
#include "ftxui/component/event.hpp" // for Event
|
|
#include "ftxui/component/mouse.hpp" // for Mouse, Mouse::Left, Mouse::Middle, Mouse::None, Mouse::Pressed, Mouse::Released, Mouse::Right, Mouse::WheelDown, Mouse::WheelUp
|
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
|
#include "ftxui/dom/elements.hpp" // for text, vbox, window, Element, Elements
|
|
|
|
using namespace ftxui;
|
|
|
|
std::string Code(Event event) {
|
|
std::string codes;
|
|
for (auto& it : event.input()) {
|
|
codes += " " + std::to_string((unsigned int)it);
|
|
}
|
|
return codes;
|
|
}
|
|
|
|
int main() {
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
|
|
|
std::vector<Event> keys;
|
|
|
|
auto left_column = Renderer([&] {
|
|
Elements children = {
|
|
text("Codes"),
|
|
separator(),
|
|
};
|
|
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) {
|
|
children.push_back(text(keys[i].DebugString()));
|
|
}
|
|
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 false;
|
|
});
|
|
|
|
screen.Loop(component);
|
|
}
|