ANSI code renderer starts working but I have to make it utf8/wchar_t friendly.
This commit is contained in:
parent
6ca4614fcb
commit
ae484bf425
9 changed files with 136 additions and 139 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <charconv>
|
||||
#include "dbc.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "ansi_parser.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
|
||||
|
@ -16,34 +17,30 @@ using namespace fmt;
|
|||
action number {
|
||||
auto [ptr, ec] = std::from_chars(start, fpc, value);
|
||||
dbc::check(ec == std::errc(), "error in number parsing");
|
||||
println("NUM: {}", value);
|
||||
}
|
||||
|
||||
action color24b {
|
||||
println("color24b");
|
||||
action color24b { }
|
||||
action is_fg { target = color; }
|
||||
action is_bg { target = bgcolor; }
|
||||
|
||||
action out {
|
||||
write(bgcolor, color, fc);
|
||||
}
|
||||
|
||||
action is_fg { is_fg = true; }
|
||||
action is_bg { is_fg = false; }
|
||||
|
||||
action any {
|
||||
println("ANY: {}:{}", int(fc), fc);
|
||||
}
|
||||
|
||||
action red { color.r = value; }
|
||||
action blue { color.g = value; }
|
||||
action green { color.b = value; }
|
||||
action reset_fg { color = default_fg; }
|
||||
action reset_bg { bgcolor = default_bg; }
|
||||
|
||||
action red { target.r = value; }
|
||||
action blue { target.g = value; }
|
||||
action green { target.b = value; }
|
||||
action start { value = 0; }
|
||||
action end { }
|
||||
|
||||
action end {
|
||||
println("fg? {}, sf:Color: {},{},{},{}", is_fg, color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
start = 0x1B "[";
|
||||
ESC = 0x1B;
|
||||
start = ESC "[";
|
||||
fg = "38;" %is_fg;
|
||||
bg = "48;" %is_bg;
|
||||
reset = ("39" | "49");
|
||||
reset = ("39" %reset_fg | "49" %reset_bg);
|
||||
num = digit+ >tstart %number;
|
||||
color256 = "5;";
|
||||
color24b = "2;";
|
||||
|
@ -56,27 +53,26 @@ using namespace fmt;
|
|||
) "m" %end
|
||||
);
|
||||
|
||||
other = (any+ @any -- 0x1B)*;
|
||||
other = (any+ @out -- ESC)*;
|
||||
|
||||
main := (other :> ansi)**;
|
||||
}%%
|
||||
|
||||
%% write data;
|
||||
|
||||
bool parse_ansi(std::string_view codes) {
|
||||
bool parse_ansi(std::string_view codes, sf::Color default_fg, sf::Color default_bg, WriteCB write) {
|
||||
const char *start = NULL;
|
||||
int cs = 0;
|
||||
unsigned int value = 0;
|
||||
const char *p = codes.data();
|
||||
const char *pe = p + codes.size();
|
||||
const char *eof = pe;
|
||||
bool is_fg = false;
|
||||
sf::Color color;
|
||||
sf::Color bgcolor(default_bg);
|
||||
sf::Color color(default_fg);
|
||||
sf::Color &target = bgcolor;
|
||||
|
||||
%% write init;
|
||||
%% write exec;
|
||||
|
||||
print("PROCESSED {} CHARS of {}: {}", p - codes.data(), codes.size(), p);
|
||||
|
||||
return true;
|
||||
return p - pe == 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue