/** * @file EscapeSequence.h * @author apio (cloudapio.eu) * @brief ANSI escape sequence parsing. * * @copyright Copyright (c) 2023, the Luna authors. * */ #pragma once #include enum class EscapeCode { SaveCursor, RestoreCursor, CursorUp, CursorDown, CursorForward, CursorBack, CursorNextLine, CursorPreviousLine, CursorHorizontalAbsolute, SetCursorPosition, SelectGraphicRendition, }; class EscapeSequenceParser { public: EscapeSequenceParser(u8 begin); Result advance(u8 byte); bool valid() const { return m_valid; } const Vector& parameters() const { return m_parameters; } EscapeCode code() const { return m_escape_code; } private: enum class SequenceType { ESC, CSI, DCS, OSC, }; Vector m_parameter; Vector m_parameters; SequenceType m_sequence_type; bool m_parsing_parameter { false }; bool m_valid { false }; EscapeCode m_escape_code; };