Library to convert limited part of SGR (Select Graphic Rendition) sequence of ANSI escape sequences to HTML.
See more info on wiki.
src/ansi_esc2html.h
src/ansi_esc2html.cpp
to your projectansi_esc2html
libraryANSI_SGR2HTML ansisgr2html;
std::string ansi = "\x1b[48;5;141m background color \x1b[49m";
std::string html = ansisgr2html.simpleParse(ansi);
//or
std::string html_strict = ansisgr2html.strictParse(ansi);
result HTML will be:
<body style="background-color:#111111;font-family:'Consolas','Droid Sans Mono',monospace; color:#eeeeee; white-space:pre"><span style="background-color:#af87ff"> background color </span></body>
Can only disable SGR parameters in reverse order they where enabled. Terminal emulators can disable them in any order. See example on wiki
This function is suitable for ANSI code generated from markup languages like XML or Markdown.
Can disable SGR parameters in any order. However it is ~40% slower than simpleParse.
This will produce release versions of static and dynamic libraries and test executable:
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Release ..
# or for Windows
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make
Tested on:
Results:
simpleParse
~ 1082 µsstrictParse
~ 1400 µs