📄 esc_seq.hpp
字号:
#ifndef ESC_SEQ_HPP
#define ESC_SEQ_HPP
#include "debug.hpp"
// ------------------------------------------------------------------------
// EscapeSequence - VT 102 escape sequence parser
//
// $Id: esc_seq.hpp 2.1 1995/10/24 15:52:51 tsurace Beta $
// $Log: esc_seq.hpp $// Revision 2.1 1995/10/24 15:52:51 tsurace// Roll.//// Revision 1.4 1995/10/11 21:00:23 tsurace// Switched to my ASSERT macro.//
// Revision 1.3 1995/10/08 23:28:25 tsurace
// Modified to allow ANSI color/attributes.
//
//
// NEWLINE
// This is special parameters[0] = count of consecutive newlines, and
// parameters[1] is the next character
//
class EscapeSequence
{
public:
enum _Type {
NONE,
UNKNOWN,
CMOVE,
SCROLL,
REV_NEWLINE,
CLRSCR,
CLREOL,
ANSI_COLOR, // param(0) = bold? param(1) = color
};
// These are all the same as the ANSI codes
enum _TextAttribute {
CLEAR_ATTR = 0, // Reset all attributes to default
BOLD = 1, // Bold
UNDERLINE = 4,
BLINKING = 5,
REVERSE_VIDEO = 7,
INVISIBLE = 8,
FG_BLACK = 30, // Foreground colors
FG_RED = 31,
FG_GREEN = 32,
FG_YELLOW = 33,
FG_BLUE = 34,
FG_MAGENTA = 35,
FG_CYAN = 36,
FG_WHITE = 37,
};
EscapeSequence(char * buf);
_Type Type() const;
int IsComplete() const;
int IsEscapeSequence() const;
int Parameter(int which) const;
int ParameterCount() const;
protected:
_Type _type;
int _isComplete;
int _isEscapeSequence;
int _parameters[20]; // Up to 20 of 'em
int _nParameters;
// Helper functions
int _EndOfString(char * buf);
void _SetType(_Type type);
// Recursive descent parser for subset of VT102 escape code language:
// int _ParseNewlineSequence(char * buf); // Obsolete
int _ParseEscapeSequence(char * buf);
int _ScrollReverse(char * buf);
int _LeftSquareBracket(char * buf);
// Called from LeftSquareBracket:
int _ClearScreen(char * buf);
int _ClearEOL(char * buf);
int _GetParameters(char ** buf);
int _GetType(char terminator);
// Parameterized types
int _CursorMove(char * buf);
int _Scroll(char * buf);
};
// ------------------------------------------------------------------------
// Type - returns the type of escape sequence.
//
// Type is always NONE until the sequence IsComplete.
//
inline EscapeSequence::_Type EscapeSequence::Type() const
{
return _type;
};
// ------------------------------------------------------------------------
// IsComplete - returns nonzero if the sequence is complete. Extra
// characters after the escape sequence are ignored.
//
inline int EscapeSequence::IsComplete() const
{
return _isComplete;
}
// IsEscapeSequence - if this is not a valid escape sequence, this
// returns 0.
//
inline int EscapeSequence::IsEscapeSequence() const
{
return _isEscapeSequence;
}
inline int EscapeSequence::Parameter(int which) const
{
ASSERT(which >= 0, "Negative array index not allowed");
ASSERT(which < _nParameters, "Index past end of array");
return _parameters[which];
}
inline int EscapeSequence::ParameterCount() const
{
return _nParameters;
}
// ------------------------------------------------------------------------
// _EndOfString - returns nonzero at the NULL at the end of a string
//
inline int EscapeSequence::_EndOfString(char * buf)
{
return (*buf == '\0');
}
#endif // ESC_SEQ_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -