restore BasicBuffer::write function
This commit is contained in:
@@ -130,3 +130,51 @@ std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width)
|
|||||||
result = s;
|
result = s;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeCyclicBuffer(const NC::WBuffer &buf, NC::Window &w, size_t &start_pos,
|
||||||
|
size_t width, const std::wstring &separator)
|
||||||
|
{
|
||||||
|
const auto &s = buf.str();
|
||||||
|
size_t len = wideLength(s);
|
||||||
|
if (len > width)
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
const auto &ps = buf.properties();
|
||||||
|
auto p = ps.begin();
|
||||||
|
|
||||||
|
// load attributes from before starting pos
|
||||||
|
for (; p != ps.end() && p->position() < start_pos; ++p)
|
||||||
|
w << *p;
|
||||||
|
|
||||||
|
auto write_buffer = [&](size_t start) {
|
||||||
|
for (size_t i = start; i < s.length() && len < width; ++i)
|
||||||
|
{
|
||||||
|
for (; p != ps.end() && p->position() == i; ++p)
|
||||||
|
w << *p;
|
||||||
|
len += wcwidth(s[i]);
|
||||||
|
if (len > width)
|
||||||
|
break;
|
||||||
|
w << s[i];
|
||||||
|
}
|
||||||
|
for (; p != ps.end(); ++p)
|
||||||
|
w << *p;
|
||||||
|
p = ps.begin();
|
||||||
|
};
|
||||||
|
|
||||||
|
write_buffer(start_pos);
|
||||||
|
for (size_t i = 0; i < separator.length() && len < width; ++i)
|
||||||
|
{
|
||||||
|
len += wcwidth(separator[i]);
|
||||||
|
if (len > width)
|
||||||
|
break;
|
||||||
|
w << separator[i];
|
||||||
|
}
|
||||||
|
write_buffer(0);
|
||||||
|
|
||||||
|
++start_pos;
|
||||||
|
if (start_pos >= s.length())
|
||||||
|
start_pos = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
w << buf;
|
||||||
|
}
|
||||||
|
|||||||
@@ -337,13 +337,6 @@ template <typename Iterator> std::string getSharedDirectory(Iterator first, Iter
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> struct StringConverter {
|
|
||||||
const char *operator()(const char *s) { return s; }
|
|
||||||
};
|
|
||||||
template <> struct StringConverter<NC::WBuffer> {
|
|
||||||
std::wstring operator()(const char *s) { return ToWString(s); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Iterator>
|
template <typename Iterator>
|
||||||
void stringToBuffer(Iterator first, Iterator last, NC::BasicBuffer<typename Iterator::value_type> &buf)
|
void stringToBuffer(Iterator first, Iterator last, NC::BasicBuffer<typename Iterator::value_type> &buf)
|
||||||
{
|
{
|
||||||
@@ -427,8 +420,6 @@ void stringToBuffer(const std::basic_string<CharT> &s, NC::BasicBuffer<CharT> &b
|
|||||||
|
|
||||||
template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
||||||
{
|
{
|
||||||
StringConverter<T> cnv;
|
|
||||||
|
|
||||||
const unsigned MINUTE = 60;
|
const unsigned MINUTE = 60;
|
||||||
const unsigned HOUR = 60*MINUTE;
|
const unsigned HOUR = 60*MINUTE;
|
||||||
const unsigned DAY = 24*HOUR;
|
const unsigned DAY = 24*HOUR;
|
||||||
@@ -437,37 +428,37 @@ template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
|
|||||||
unsigned years = length/YEAR;
|
unsigned years = length/YEAR;
|
||||||
if (years)
|
if (years)
|
||||||
{
|
{
|
||||||
buf << years << cnv(short_names ? "y" : (years == 1 ? " year" : " years"));
|
buf << years << (short_names ? "y" : (years == 1 ? " year" : " years"));
|
||||||
length -= years*YEAR;
|
length -= years*YEAR;
|
||||||
if (length)
|
if (length)
|
||||||
buf << cnv(", ");
|
buf << ", ";
|
||||||
}
|
}
|
||||||
unsigned days = length/DAY;
|
unsigned days = length/DAY;
|
||||||
if (days)
|
if (days)
|
||||||
{
|
{
|
||||||
buf << days << cnv(short_names ? "d" : (days == 1 ? " day" : " days"));
|
buf << days << (short_names ? "d" : (days == 1 ? " day" : " days"));
|
||||||
length -= days*DAY;
|
length -= days*DAY;
|
||||||
if (length)
|
if (length)
|
||||||
buf << cnv(", ");
|
buf << ", ";
|
||||||
}
|
}
|
||||||
unsigned hours = length/HOUR;
|
unsigned hours = length/HOUR;
|
||||||
if (hours)
|
if (hours)
|
||||||
{
|
{
|
||||||
buf << hours << cnv(short_names ? "h" : (hours == 1 ? " hour" : " hours"));
|
buf << hours << (short_names ? "h" : (hours == 1 ? " hour" : " hours"));
|
||||||
length -= hours*HOUR;
|
length -= hours*HOUR;
|
||||||
if (length)
|
if (length)
|
||||||
buf << cnv(", ");
|
buf << ", ";
|
||||||
}
|
}
|
||||||
unsigned minutes = length/MINUTE;
|
unsigned minutes = length/MINUTE;
|
||||||
if (minutes)
|
if (minutes)
|
||||||
{
|
{
|
||||||
buf << minutes << cnv(short_names ? "m" : (minutes == 1 ? " minute" : " minutes"));
|
buf << minutes << (short_names ? "m" : (minutes == 1 ? " minute" : " minutes"));
|
||||||
length -= minutes*MINUTE;
|
length -= minutes*MINUTE;
|
||||||
if (length)
|
if (length)
|
||||||
buf << cnv(", ");
|
buf << ", ";
|
||||||
}
|
}
|
||||||
if (length)
|
if (length)
|
||||||
buf << length << cnv(short_names ? "s" : (length == 1 ? " second" : " seconds"));
|
buf << length << (short_names ? "s" : (length == 1 ? " second" : " seconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
|
template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
|
||||||
@@ -486,5 +477,7 @@ std::string Timestamp(time_t t);
|
|||||||
void markSongsInPlaylist(ProxySongList pl);
|
void markSongsInPlaylist(ProxySongList pl);
|
||||||
|
|
||||||
std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width);
|
std::wstring Scroller(const std::wstring &str, size_t &pos, size_t width);
|
||||||
|
void writeCyclicBuffer(const NC::WBuffer &buf, NC::Window &w, size_t &start_pos,
|
||||||
|
size_t width, const std::wstring &separator);
|
||||||
|
|
||||||
#endif // NCMPCPP_HELPERS_H
|
#endif // NCMPCPP_HELPERS_H
|
||||||
|
|||||||
@@ -344,11 +344,11 @@ void Status::Changes::elapsedTime()
|
|||||||
if (!Global::SeekingInProgress)
|
if (!Global::SeekingInProgress)
|
||||||
*wHeader << NC::XY(0, 0) << wclrtoeol << tracklength;
|
*wHeader << NC::XY(0, 0) << wclrtoeol << tracklength;
|
||||||
*wHeader << NC::XY(first_start, 0);
|
*wHeader << NC::XY(first_start, 0);
|
||||||
first.write(*wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, L" ** ");
|
writeCyclicBuffer(first, *wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, L" ** ");
|
||||||
|
|
||||||
*wHeader << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd;
|
*wHeader << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd;
|
||||||
*wHeader << NC::XY(second_start, 1);
|
*wHeader << NC::XY(second_start, 1);
|
||||||
second.write(*wHeader, second_line_scroll_begin, COLS-player_state.length()-8-2, L" ** ");
|
writeCyclicBuffer(second, *wHeader, second_line_scroll_begin, COLS-player_state.length()-8-2, L" ** ");
|
||||||
|
|
||||||
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::clEnd;
|
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::clEnd;
|
||||||
|
|
||||||
@@ -384,7 +384,7 @@ void Status::Changes::elapsedTime()
|
|||||||
NC::WBuffer np_song;
|
NC::WBuffer np_song;
|
||||||
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.song_status_format, Config.tags_separator, "$"))), np_song);
|
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.song_status_format, Config.tags_separator, "$"))), np_song);
|
||||||
*wFooter << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd;
|
*wFooter << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd;
|
||||||
np_song.write(*wFooter, playing_song_scroll_begin, wFooter->getWidth()-player_state.length()-tracklength.length(), L" ** ");
|
writeCyclicBuffer(np_song, *wFooter, playing_song_scroll_begin, wFooter->getWidth()-player_state.length()-tracklength.length(), L" ** ");
|
||||||
*wFooter << NC::fmtBold << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength << NC::fmtBoldEnd;
|
*wFooter << NC::fmtBold << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength << NC::fmtBoldEnd;
|
||||||
}
|
}
|
||||||
if (Progressbar::isUnlocked())
|
if (Progressbar::isUnlocked())
|
||||||
|
|||||||
@@ -183,9 +183,6 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(GNUC_UNUSED Window &w, GNUC_UNUSED size_t &start_pos, GNUC_UNUSED size_t width,
|
|
||||||
GNUC_UNUSED const std::basic_string<CharT> &separator) const { }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StringType m_string;
|
StringType m_string;
|
||||||
Properties m_properties;
|
Properties m_properties;
|
||||||
@@ -217,68 +214,6 @@ Window operator<<(Window &w, const BasicBuffer<CharT> &buffer)
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
template <typename CharT> void BasicBuffer<CharT>::write(
|
|
||||||
Window &w,
|
|
||||||
size_t &start_pos,
|
|
||||||
size_t width,
|
|
||||||
const std::basic_string<CharT> &separator
|
|
||||||
) const
|
|
||||||
{
|
|
||||||
std::basic_string<CharT> s = m_string;
|
|
||||||
size_t len = wideLength(s);
|
|
||||||
|
|
||||||
if (len > width)
|
|
||||||
{
|
|
||||||
s += separator;
|
|
||||||
len = 0;
|
|
||||||
|
|
||||||
auto lb = m_properties.begin();
|
|
||||||
if (m_properties.back().Position > start_pos) // if there is no attributes from current position, don't load them
|
|
||||||
{
|
|
||||||
// load all attributes that are before start position
|
|
||||||
for (; lb->Position < start_pos; ++lb)
|
|
||||||
loadAttribute(w, lb->Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = start_pos; i < s.length() && len < width; ++i)
|
|
||||||
{
|
|
||||||
while (i == lb->Position && lb != m_properties.end())
|
|
||||||
{
|
|
||||||
loadAttribute(w, lb->Value);
|
|
||||||
++lb;
|
|
||||||
}
|
|
||||||
if ((len += wcwidth(s[i])) > width)
|
|
||||||
break;
|
|
||||||
w << s[i];
|
|
||||||
}
|
|
||||||
if (++start_pos >= s.length())
|
|
||||||
start_pos = 0;
|
|
||||||
|
|
||||||
if (len < width)
|
|
||||||
lb = m_properties.begin();
|
|
||||||
for (size_t i = 0; len < width; ++i)
|
|
||||||
{
|
|
||||||
while (i == lb->Position && lb != m_properties.end())
|
|
||||||
{
|
|
||||||
loadAttribute(w, lb->Value);
|
|
||||||
++lb;
|
|
||||||
}
|
|
||||||
if ((len += wcwidth(s[i])) > width)
|
|
||||||
break;
|
|
||||||
w << s[i];
|
|
||||||
}
|
|
||||||
// load all remained attributes to clean up
|
|
||||||
for (; lb != m_properties.end(); ++lb)
|
|
||||||
loadAttribute(w, lb->Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
w << *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NCMPCPP_STRBUFFER_H
|
#endif // NCMPCPP_STRBUFFER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user