This is a useful piece of functionality to being able to eat URL hyperlinks, for instance, which is a bug that Lix has while dealing with terminal output today. Change-Id: I77b2de107b2525cad7ea5dea28bfba2cc78b9e6d
32 lines
512 B
C++
32 lines
512 B
C++
#pragma once
|
|
/// @file
|
|
|
|
#include <functional>
|
|
|
|
namespace nix {
|
|
|
|
/** DFA that eats terminal escapes
|
|
*
|
|
* See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
|
*/
|
|
class TerminalCodeEater
|
|
{
|
|
public:
|
|
void feed(char c, std::function<void(char)> on_char);
|
|
|
|
private:
|
|
enum class State {
|
|
ExpectESC,
|
|
ExpectESCSeq,
|
|
InCSIParams,
|
|
InCSIIntermediates,
|
|
InOSCParams,
|
|
InOSCST,
|
|
};
|
|
|
|
State state = State::ExpectESC;
|
|
|
|
void transition(State new_state);
|
|
};
|
|
};
|