You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using this asciichart on a ESP32 micro controller. Resources are limited and the current implementation generates a lot of unnessary styling set & unset sequences.
We can omit styling when two consecutive text elements share the same style. C++ has a stream state API, that we can use to store information about the current style.
This works for me
Here's my implementation: (Note that you need to un-set the style at each line-end: std::cout << ascii::Decoration::From(ascii::Decoration::RESET) << "\n";):
text.h:
friend std::ostream &operator<<(std::ostream &os, const Text &val) {
std::stringstream ss;
ss << val.style_;
std::hash<std::string> hasher;
auto textStyleHash = (long)hasher(ss.str());
auto &streamStyleHash = os.iword(get_style_stream_iword());
if(textStyleHash == streamStyleHash)
os << val.text_;
else {
os << val.style_ << val.text_; // << Decoration::From(Decoration::RESET);
streamStyleHash = textStyleHash;
}
return os;
}
inline int get_style_stream_iword() {
static int i = std::ios_base::xalloc();
return i;
}
The text was updated successfully, but these errors were encountered:
Hi,
I am using this asciichart on a ESP32 micro controller. Resources are limited and the current implementation generates a lot of unnessary styling set & unset sequences.
We can omit styling when two consecutive text elements share the same style. C++ has a stream state API, that we can use to store information about the current style.
This works for me
Here's my implementation: (Note that you need to un-set the style at each line-end:
std::cout << ascii::Decoration::From(ascii::Decoration::RESET) << "\n";
):text.h:
The text was updated successfully, but these errors were encountered: