lix/tests/unit/libutil-support/tests/terminal-code-eater.hh
jade 18ed6c3bdf Implement a repl characterization test system
This allows for automating using the repl without needing a PTY, with
very easy to write test files.

Change-Id: Ia8d7854edd91f93477638942cb6fc261354e6035
2024-03-15 12:31:16 -07:00

30 lines
474 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,
};
State state = State::ExpectESC;
void transition(State new_state);
};
};