mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-12-16 01:48:56 +08:00
First version of supporting extraction of the terminal id.
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
#ifndef FTXUI_COMPONENT_EVENT_HPP
|
||||
#define FTXUI_COMPONENT_EVENT_HPP
|
||||
|
||||
#include <ftxui/component/mouse.hpp> // for Mouse
|
||||
#include <string> // for string, operator==
|
||||
#include <ftxui/component/mouse.hpp> // for Mouse
|
||||
#include <ftxui/component/terminal_id.hpp> // for TerminalID
|
||||
#include <string> // for string, operator==
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -35,6 +36,7 @@ struct Event {
|
||||
static Event Mouse(std::string, Mouse mouse);
|
||||
static Event CursorPosition(std::string, int x, int y); // Internal
|
||||
static Event CursorShape(std::string, int shape); // Internal
|
||||
static Event TerminalID(std::string input, enum TerminalID terminal_id); // Internal
|
||||
|
||||
// --- Arrow ---
|
||||
static const Event ArrowLeft;
|
||||
@@ -117,6 +119,9 @@ struct Event {
|
||||
bool is_cursor_shape() const { return type_ == Type::CursorShape; }
|
||||
int cursor_shape() const { return data_.cursor_shape; }
|
||||
|
||||
bool is_terminal_id() const { return type_ == Type::TerminalID; }
|
||||
enum TerminalID terminal_id() const { return data_.terminal_id; }
|
||||
|
||||
// Debug
|
||||
std::string DebugString() const;
|
||||
|
||||
@@ -132,6 +137,7 @@ struct Event {
|
||||
Mouse,
|
||||
CursorPosition,
|
||||
CursorShape,
|
||||
TerminalID
|
||||
};
|
||||
Type type_ = Type::Unknown;
|
||||
|
||||
@@ -144,6 +150,7 @@ struct Event {
|
||||
struct Mouse mouse;
|
||||
struct Cursor cursor;
|
||||
int cursor_shape;
|
||||
enum TerminalID terminal_id;
|
||||
} data_ = {};
|
||||
|
||||
std::string input_;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <memory> // for shared_ptr
|
||||
#include <string> // for string
|
||||
#include <thread> // for thread
|
||||
#include <list>
|
||||
|
||||
#include "ftxui/component/animation.hpp" // for TimePoint
|
||||
#include "ftxui/component/captured_mouse.hpp" // for CapturedMouse
|
||||
@@ -72,6 +73,13 @@ class ScreenInteractive : public Screen {
|
||||
void ForceHandleCtrlC(bool force);
|
||||
void ForceHandleCtrlZ(bool force);
|
||||
|
||||
TerminalID TerminalId() const;
|
||||
|
||||
typedef std::function<void(TerminalID const& terminal_id)> TerminalIDUpdateCallback;
|
||||
|
||||
void OnTerminalIDUpdate(
|
||||
TerminalIDUpdateCallback const& callback);
|
||||
|
||||
// Selection API.
|
||||
std::string GetSelection();
|
||||
void SelectionChange(std::function<void()> callback);
|
||||
@@ -156,6 +164,11 @@ class ScreenInteractive : public Screen {
|
||||
std::unique_ptr<Selection> selection_;
|
||||
std::function<void()> selection_on_change_;
|
||||
|
||||
TerminalID m_terminal_id;
|
||||
|
||||
typedef std::list<TerminalIDUpdateCallback> TerminalIDUpdateCallbackContainer;
|
||||
TerminalIDUpdateCallbackContainer m_terminal_id_update_callbacks;
|
||||
|
||||
friend class Loop;
|
||||
|
||||
public:
|
||||
|
||||
35
include/ftxui/component/terminal_id.hpp
Normal file
35
include/ftxui/component/terminal_id.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2025 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
||||
|
||||
#ifndef FTXUI_COMPONENT_TERMINAL_ID_HPP
|
||||
#define FTXUI_COMPONENT_TERMINAL_ID_HPP
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
std::string const TERMINAL_ID_REQUEST("\x1b[0c");
|
||||
|
||||
/// @brief A mouse event. It contains the coordinate of the mouse, the button
|
||||
/// pressed and the modifier (shift, ctrl, meta).
|
||||
/// @ingroup component
|
||||
|
||||
enum class TerminalID
|
||||
{
|
||||
UNKNOWN,
|
||||
XTERM,
|
||||
KONSOLE,
|
||||
URXVT,
|
||||
VTE,
|
||||
LINUXVC
|
||||
};
|
||||
|
||||
std::ostream& operator<<(
|
||||
std::ostream& os,
|
||||
TerminalID terminal_id);
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
#endif /* end of include guard: FTXUI_COMPONENT_TERMINAL_ID_HPP */
|
||||
Reference in New Issue
Block a user