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