Refactored the ansi_parser into a class that can be reused between render calls.
This commit is contained in:
parent
e864e14eab
commit
fd8180bc61
6 changed files with 68 additions and 27 deletions
|
@ -87,26 +87,39 @@ static const int foo_en_main = 19;
|
|||
|
||||
#line 84 "ansi_parser.rl"
|
||||
|
||||
bool parse_ansi(std::wstring_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) {
|
||||
|
||||
ANSIParser::ANSIParser(sf::Color default_fg, sf::Color default_bg) :
|
||||
$default_fg(default_fg),
|
||||
$default_bg(default_bg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ANSIParser::parse(const std::string &screen, WriteCB write) {
|
||||
std::wstring screen_utf8 = $converter.from_bytes(screen);
|
||||
return parse(screen_utf8, write);
|
||||
}
|
||||
|
||||
bool ANSIParser::parse(std::wstring_view codes, WriteCB write) {
|
||||
const wchar_t *start = NULL;
|
||||
int cs = 0;
|
||||
unsigned int value = 0;
|
||||
const wchar_t *p = codes.data();
|
||||
const wchar_t *pe = p + codes.size();
|
||||
const wchar_t *eof = pe;
|
||||
sf::Color bgcolor(default_bg);
|
||||
sf::Color color(default_fg);
|
||||
sf::Color bgcolor($default_bg);
|
||||
sf::Color color($default_fg);
|
||||
sf::Color &target = color;
|
||||
|
||||
|
||||
#line 94 "ansi_parser.cpp"
|
||||
#line 107 "ansi_parser.cpp"
|
||||
{
|
||||
cs = foo_start;
|
||||
}
|
||||
|
||||
#line 97 "ansi_parser.rl"
|
||||
#line 110 "ansi_parser.rl"
|
||||
|
||||
#line 97 "ansi_parser.cpp"
|
||||
#line 110 "ansi_parser.cpp"
|
||||
{
|
||||
int _klen;
|
||||
unsigned int _trans;
|
||||
|
@ -233,11 +246,11 @@ _match:
|
|||
break;
|
||||
case 6:
|
||||
#line 52 "ansi_parser.rl"
|
||||
{ color = default_fg; }
|
||||
{ color = $default_fg; }
|
||||
break;
|
||||
case 7:
|
||||
#line 53 "ansi_parser.rl"
|
||||
{ bgcolor = default_bg; }
|
||||
{ bgcolor = $default_bg; }
|
||||
break;
|
||||
case 8:
|
||||
#line 55 "ansi_parser.rl"
|
||||
|
@ -259,7 +272,7 @@ _match:
|
|||
#line 59 "ansi_parser.rl"
|
||||
{ }
|
||||
break;
|
||||
#line 236 "ansi_parser.cpp"
|
||||
#line 249 "ansi_parser.cpp"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +292,7 @@ _again:
|
|||
#line 59 "ansi_parser.rl"
|
||||
{ }
|
||||
break;
|
||||
#line 254 "ansi_parser.cpp"
|
||||
#line 267 "ansi_parser.cpp"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +300,7 @@ _again:
|
|||
_out: {}
|
||||
}
|
||||
|
||||
#line 98 "ansi_parser.rl"
|
||||
#line 111 "ansi_parser.rl"
|
||||
|
||||
return p - pe == 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue