FTXUI/src/ftxui/component/terminal_input_parser.hpp

73 lines
1.5 KiB
C++
Raw Normal View History

#ifndef FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
#define FTXUI_COMPONENT_TERMINAL_INPUT_PARSER
2021-05-02 02:40:35 +08:00
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
2021-05-15 04:00:49 +08:00
#include "ftxui/component/event.hpp" // for Event (ptr only)
2021-05-02 02:40:35 +08:00
#include "ftxui/component/mouse.hpp" // for Mouse
2021-05-15 04:00:49 +08:00
#include "ftxui/component/receiver.hpp" // for Sender
namespace ftxui {
2021-05-15 04:00:49 +08:00
struct Event;
// Parse a sequence of |char| accross |time|. Produces |Event|.
class TerminalInputParser {
public:
TerminalInputParser(Sender<Event> out);
void Timeout(int time);
void Add(char c);
private:
unsigned char Current();
bool Eat();
enum Type {
2021-04-19 00:32:38 +08:00
UNCOMPLETED,
DROP,
CHARACTER,
SPECIAL,
2021-04-25 21:22:38 +08:00
MOUSE,
CURSOR_REPORTING,
};
2021-04-19 00:32:38 +08:00
2021-04-25 21:22:38 +08:00
struct CursorReporting {
2021-04-19 00:32:38 +08:00
int x;
int y;
};
struct Output {
Type type;
union {
Mouse mouse;
2021-04-25 21:22:38 +08:00
CursorReporting cursor;
2021-04-19 00:32:38 +08:00
};
Output(Type t) : type(t) {}
2021-04-19 00:32:38 +08:00
};
void Send(Output type);
Output Parse();
Output ParseUTF8();
Output ParseESC();
Output ParseDCS();
Output ParseCSI();
Output ParseOSC();
2021-04-25 21:22:38 +08:00
Output ParseMouse(bool altered, bool pressed, std::vector<int> arguments);
Output ParseCursorReporting(std::vector<int> arguments);
Sender<Event> out_;
int position_ = -1;
int timeout_ = 0;
std::string pending_;
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_TERMINAL_INPUT_PARSER */
// 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.