diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 3767aa37..375c2c69 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -99,6 +99,8 @@ void * GetArtistInfo(void *ptr) first = 0; } input.close(); + sInfo->SetFormatting(fmtBold, "\n\nSimilar artists:\n", fmtBoldEnd, 0); + sInfo->SetFormatting(Config.color2, "\n * ", clEnd); artist_info_ready = 1; pthread_exit(NULL); } diff --git a/src/scrollpad.cpp b/src/scrollpad.cpp index ca7c5e2a..7f5cde4d 100644 --- a/src/scrollpad.cpp +++ b/src/scrollpad.cpp @@ -101,6 +101,11 @@ void Scrollpad::Flush() itsBuffer.SetTemp(0); } +void Scrollpad::SetFormatting(short vb, const std::basic_string &s, short ve, bool for_each) +{ + itsBuffer.SetFormatting(vb, s, ve, for_each); +} + void Scrollpad::Recreate() { delwin(itsWindow); diff --git a/src/scrollpad.h b/src/scrollpad.h index c1daa71c..8199db11 100644 --- a/src/scrollpad.h +++ b/src/scrollpad.h @@ -32,6 +32,7 @@ class Scrollpad: public Window virtual ~Scrollpad() { } void Flush(); + void SetFormatting(short, const std::basic_string &, short, bool for_each = 1); std::basic_string Content() { return itsBuffer.Str(); } virtual void Refresh(); @@ -50,6 +51,7 @@ class Scrollpad: public Window Scrollpad &operator<<(std::ostream &(*os)(std::ostream &)); # ifdef _UTF8 + void SetFormatting(short vb, const std::string &s, short ve, bool for_each = 1) { SetFormatting(vb, ToWString(s), ve, for_each); } Scrollpad &operator<<(const char *s); Scrollpad &operator<<(const std::string &s); # endif // _UTF8 diff --git a/src/strbuffer.h b/src/strbuffer.h index 35558c54..efe22341 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -47,6 +47,7 @@ template class basic_buffer basic_buffer() : itsTempString(0) { } std::basic_string Str() const; + void SetFormatting(short vb, const std::basic_string &s, short ve, bool for_each = 1); void SetTemp(std::basic_string *); void Clear(); @@ -72,6 +73,25 @@ template std::basic_string basic_buffer::Str() const return itsString.str(); } +template void basic_buffer::SetFormatting(short vb, const std::basic_string &s, short ve, bool for_each) +{ + std::basic_string base = itsString.str(); + FormatPos fp; + + for (size_t i = base.find(s); i != std::basic_string::npos; i = base.find(s)) + { + base[i] = 0; + fp.Value = vb; + fp.Position = i; + itsFormat.push_back(fp); + fp.Value = ve; + fp.Position = i+s.length(); + itsFormat.push_back(fp); + if (!for_each) + break; + } +} + template void basic_buffer::SetTemp(std::basic_string *tmp) { itsTempString = tmp;