Renderer of ANSI codes to SFML is now working. Does seem to be a little slow but that'll be easy to fix later.
This commit is contained in:
parent
ae484bf425
commit
a36b187879
8 changed files with 96 additions and 62 deletions
|
@ -9,14 +9,32 @@ using namespace fmt;
|
|||
|
||||
%%{
|
||||
machine foo;
|
||||
alphtype int;
|
||||
|
||||
action tstart {
|
||||
start = fpc;
|
||||
}
|
||||
|
||||
action number {
|
||||
auto [ptr, ec] = std::from_chars(start, fpc, value);
|
||||
dbc::check(ec == std::errc(), "error in number parsing");
|
||||
value = 0;
|
||||
size_t len = fpc - start;
|
||||
dbc::check(start[0] != '-', "negative numbers not supported");
|
||||
|
||||
switch(len) {
|
||||
case 10: value += (start[len-10] - '0') * 1000000000;
|
||||
case 9: value += (start[len- 9] - '0') * 100000000;
|
||||
case 8: value += (start[len- 8] - '0') * 10000000;
|
||||
case 7: value += (start[len- 7] - '0') * 1000000;
|
||||
case 6: value += (start[len- 6] - '0') * 100000;
|
||||
case 5: value += (start[len- 5] - '0') * 10000;
|
||||
case 4: value += (start[len- 4] - '0') * 1000;
|
||||
case 3: value += (start[len- 3] - '0') * 100;
|
||||
case 2: value += (start[len- 2] - '0') * 10;
|
||||
case 1: value += (start[len- 1] - '0');
|
||||
break;
|
||||
default:
|
||||
dbc::sentinel("can't process > 10 digits");
|
||||
}
|
||||
}
|
||||
|
||||
action color24b { }
|
||||
|
@ -60,13 +78,13 @@ using namespace fmt;
|
|||
|
||||
%% write data;
|
||||
|
||||
bool parse_ansi(std::string_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) {
|
||||
const char *start = NULL;
|
||||
bool parse_ansi(std::wstring_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) {
|
||||
const wchar_t *start = NULL;
|
||||
int cs = 0;
|
||||
unsigned int value = 0;
|
||||
const char *p = codes.data();
|
||||
const char *pe = p + codes.size();
|
||||
const char *eof = pe;
|
||||
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 &target = bgcolor;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue