First version of supporting extraction of the terminal id.

This commit is contained in:
Jørn Gustav Larsen
2025-06-24 11:27:35 +02:00
parent 68fc9b1212
commit 2715503516
13 changed files with 281 additions and 6 deletions

View File

@@ -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_;

View File

@@ -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:

View 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 */