13 : out_(std::move(out)) {}
31unsigned char TerminalInputParser::Current() {
32 return pending_[position_];
35bool TerminalInputParser::Eat() {
37 return position_ < (int)pending_.size();
40void TerminalInputParser::Send(TerminalInputParser::Output output) {
41 switch (output.type) {
50 out_->Send(Event::Character(std::move(pending_)));
60 out_->Send(Event::Mouse(std::move(pending_), output.mouse));
64 case CURSOR_REPORTING:
65 out_->Send(Event::CursorReporting(std::move(pending_), output.cursor.x,
73TerminalInputParser::Output TerminalInputParser::Parse() {
113TerminalInputParser::Output TerminalInputParser::ParseUTF8() {
114 unsigned char head =
static_cast<unsigned char>(Current());
115 unsigned char selector = 0b1000'0000;
118 unsigned char mask = selector;
122 for (
int i = 0; i < 8; ++i) {
124 if (head & selector) {
133 uint32_t value = head & ~mask;
136 if (first_zero == 1 || first_zero >= 5)
140 for (
int i = 2; i <= first_zero; ++i) {
145 head =
static_cast<unsigned char>(Current());
146 if ((head & 0b1100'0000) != 0b1000'0000)
149 value += head & 0b0011'1111;
154 if (value <= 0b000'0000'0111'1111) {
156 }
else if (value <= 0b000'0111'1111'1111) {
158 }
else if (value <= 0b1111'1111'1111'1111) {
160 }
else if (value <= 0b1'0000'1111'1111'1111'1111) {
166 if (extra_byte != position_)
172TerminalInputParser::Output TerminalInputParser::ParseESC() {
189TerminalInputParser::Output TerminalInputParser::ParseDCS() {
195 if (Current() !=
'\x1B')
201 if (Current() !=
'\\')
208TerminalInputParser::Output TerminalInputParser::ParseCSI() {
209 bool altered =
false;
211 std::vector<int> arguments;
216 if (Current() ==
'<') {
221 if (Current() >=
'0' && Current() <=
'9') {
223 argument += int(Current() -
'0');
227 if (Current() ==
';') {
228 arguments.push_back(argument);
233 if (Current() >=
' ' && Current() <=
'~' && Current() !=
'<') {
234 arguments.push_back(argument);
238 return ParseMouse(altered,
true, std::move(arguments));
240 return ParseMouse(altered,
false, std::move(arguments));
242 return ParseCursorReporting(std::move(arguments));
249 if (Current() ==
'\x1B')
254TerminalInputParser::Output TerminalInputParser::ParseOSC() {
259 if (Current() !=
'\x1B')
263 if (Current() !=
'\\')
269TerminalInputParser::Output TerminalInputParser::ParseMouse(
272 std::vector<int> arguments) {
273 if (arguments.size() != 3)
278 Output output(MOUSE);
280 ((arguments[0] & 64) >> 4));
282 output.mouse.shift = bool(arguments[0] & 4);
283 output.mouse.meta = bool(arguments[0] & 8);
284 output.mouse.x = arguments[1];
285 output.mouse.y = arguments[2];
289TerminalInputParser::Output TerminalInputParser::ParseCursorReporting(
290 std::vector<int> arguments) {
291 if (arguments.size() != 2)
293 Output output(CURSOR_REPORTING);
294 output.cursor.y = arguments[0];
295 output.cursor.x = arguments[1];
std::unique_ptr< SenderImpl< T > > Sender
static Event Special(std::string)