display: improve showSongs a bit
This commit is contained in:
@@ -108,12 +108,14 @@ void showSongs(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen, const st
|
|||||||
bool separate_albums, is_now_playing, is_selected, discard_colors;
|
bool separate_albums, is_now_playing, is_selected, discard_colors;
|
||||||
setProperties(menu, s, screen, separate_albums, is_now_playing, is_selected, discard_colors);
|
setProperties(menu, s, screen, separate_albums, is_now_playing, is_selected, discard_colors);
|
||||||
|
|
||||||
|
size_t y = menu.getY();
|
||||||
std::string line = s.toString(format, "$");
|
std::string line = s.toString(format, "$");
|
||||||
for (auto it = line.begin(); it != line.end(); ++it)
|
for (auto it = line.begin(); it != line.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == '$')
|
if (*it == '$')
|
||||||
{
|
{
|
||||||
if (++it == line.end()) // end of format
|
++it;
|
||||||
|
if (it == line.end()) // end of format
|
||||||
{
|
{
|
||||||
menu << '$';
|
menu << '$';
|
||||||
break;
|
break;
|
||||||
@@ -125,25 +127,27 @@ void showSongs(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen, const st
|
|||||||
}
|
}
|
||||||
else if (*it == 'R') // right align
|
else if (*it == 'R') // right align
|
||||||
{
|
{
|
||||||
NC::WBuffer buf;
|
NC::Buffer buf;
|
||||||
buf << L" ";
|
buf << " ";
|
||||||
String2Buffer(ToWString(line.substr(it-line.begin()+1)), buf);
|
stringToBuffer(++it, line.end(), buf);
|
||||||
if (discard_colors)
|
if (discard_colors)
|
||||||
buf.removeFormatting();
|
buf.removeFormatting();
|
||||||
|
size_t x_off = menu.getWidth() - wideLength(ToWString(buf.str()));
|
||||||
if (is_now_playing)
|
if (is_now_playing)
|
||||||
buf << Config.now_playing_suffix;
|
x_off -= Config.now_playing_suffix_length;
|
||||||
menu << NC::XY(menu.getWidth()-buf.str().length()-(is_selected ? Config.selected_item_suffix_length : 0), menu.getY()) << buf;
|
if (is_selected)
|
||||||
if (separate_albums)
|
x_off -= Config.selected_item_suffix_length;
|
||||||
menu << NC::fmtUnderlineEnd;
|
menu << NC::XY(x_off, y) << buf;
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
else // not a color nor right align, just a random character
|
else // not a color nor right align, just a random character
|
||||||
menu << *--it;
|
menu << *--it;
|
||||||
}
|
}
|
||||||
else if (*it == MPD::Song::FormatEscapeCharacter)
|
else if (*it == MPD::Song::FormatEscapeCharacter)
|
||||||
{
|
{
|
||||||
|
++it;
|
||||||
// treat '$' as a normal character if song format escape char is prepended to it
|
// treat '$' as a normal character if song format escape char is prepended to it
|
||||||
if (++it == line.end() || *it != '$')
|
if (it == line.end() || *it != '$')
|
||||||
--it;
|
--it;
|
||||||
menu << *it;
|
menu << *it;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -327,15 +327,14 @@ template <> struct StringConverter<NC::Scrollpad> {
|
|||||||
std::wstring operator()(const char *s) { return ToWString(s); }
|
std::wstring operator()(const char *s) { return ToWString(s); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename CharT>
|
template <typename Iterator>
|
||||||
void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &buf)
|
void stringToBuffer(Iterator first, Iterator last, NC::basic_buffer<typename Iterator::value_type> &buf)
|
||||||
{
|
{
|
||||||
StringConverter< NC::basic_buffer<CharT> > cnv;
|
for (auto it = first; it != last; ++it)
|
||||||
for (auto it = s.begin(); it != s.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (*it == '$')
|
if (*it == '$')
|
||||||
{
|
{
|
||||||
if (++it == s.end())
|
if (++it == last)
|
||||||
{
|
{
|
||||||
buf << '$';
|
buf << '$';
|
||||||
break;
|
break;
|
||||||
@@ -361,9 +360,9 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
|
|||||||
buf << NC::fmtReverse;
|
buf << NC::fmtReverse;
|
||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
if (++it == s.end())
|
if (++it == last)
|
||||||
{
|
{
|
||||||
buf << cnv("$/");
|
buf << '$' << '/';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (*it)
|
switch (*it)
|
||||||
@@ -394,7 +393,7 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
|
|||||||
else if (*it == MPD::Song::FormatEscapeCharacter)
|
else if (*it == MPD::Song::FormatEscapeCharacter)
|
||||||
{
|
{
|
||||||
// treat '$' as a normal character if song format escape char is prepended to it
|
// treat '$' as a normal character if song format escape char is prepended to it
|
||||||
if (++it == s.end() || *it != '$')
|
if (++it == last || *it != '$')
|
||||||
--it;
|
--it;
|
||||||
buf << *it;
|
buf << *it;
|
||||||
}
|
}
|
||||||
@@ -403,6 +402,12 @@ void String2Buffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &b
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename CharT>
|
||||||
|
void stringToBuffer(const std::basic_string<CharT> &s, NC::basic_buffer<CharT> &buf)
|
||||||
|
{
|
||||||
|
stringToBuffer(s.begin(), s.end(), buf);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
StringConverter<T> cnv;
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ void Configuration::Read()
|
|||||||
if (song_status_format.find("$") != std::string::npos)
|
if (song_status_format.find("$") != std::string::npos)
|
||||||
{
|
{
|
||||||
NC::Buffer status_no_colors;
|
NC::Buffer status_no_colors;
|
||||||
String2Buffer(song_status_format, status_no_colors);
|
stringToBuffer(song_status_format, status_no_colors);
|
||||||
song_status_format_no_colors = status_no_colors.str();
|
song_status_format_no_colors = status_no_colors.str();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -509,7 +509,7 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
browser_playlist_prefix.clear();
|
browser_playlist_prefix.clear();
|
||||||
String2Buffer(v, browser_playlist_prefix);
|
stringToBuffer(v, browser_playlist_prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "progressbar_look")
|
else if (name == "progressbar_look")
|
||||||
@@ -545,7 +545,7 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
selected_item_prefix.clear();
|
selected_item_prefix.clear();
|
||||||
String2Buffer(v, selected_item_prefix);
|
stringToBuffer(v, selected_item_prefix);
|
||||||
selected_item_prefix_length = wideLength(ToWString(selected_item_prefix.str()));
|
selected_item_prefix_length = wideLength(ToWString(selected_item_prefix.str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,7 +554,7 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
selected_item_suffix.clear();
|
selected_item_suffix.clear();
|
||||||
String2Buffer(v, selected_item_suffix);
|
stringToBuffer(v, selected_item_suffix);
|
||||||
selected_item_suffix_length = wideLength(ToWString(selected_item_suffix.str()));
|
selected_item_suffix_length = wideLength(ToWString(selected_item_suffix.str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -563,7 +563,7 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
now_playing_prefix.clear();
|
now_playing_prefix.clear();
|
||||||
String2Buffer(v, now_playing_prefix);
|
stringToBuffer(v, now_playing_prefix);
|
||||||
now_playing_prefix_length = wideLength(ToWString(now_playing_prefix.str()));
|
now_playing_prefix_length = wideLength(ToWString(now_playing_prefix.str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -572,8 +572,8 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
now_playing_suffix.clear();
|
now_playing_suffix.clear();
|
||||||
String2Buffer(ToWString(v), now_playing_suffix);
|
stringToBuffer(v, now_playing_suffix);
|
||||||
now_playing_suffix_length = wideLength(now_playing_suffix.str());
|
now_playing_suffix_length = wideLength(ToWString(now_playing_suffix.str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "modified_item_prefix")
|
else if (name == "modified_item_prefix")
|
||||||
@@ -581,7 +581,7 @@ void Configuration::Read()
|
|||||||
if (!v.empty())
|
if (!v.empty())
|
||||||
{
|
{
|
||||||
modified_item_prefix.clear();
|
modified_item_prefix.clear();
|
||||||
String2Buffer(v, modified_item_prefix);
|
stringToBuffer(v, modified_item_prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (name == "color1")
|
else if (name == "color1")
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ struct Configuration
|
|||||||
NC::Buffer selected_item_prefix;
|
NC::Buffer selected_item_prefix;
|
||||||
NC::Buffer selected_item_suffix;
|
NC::Buffer selected_item_suffix;
|
||||||
NC::Buffer now_playing_prefix;
|
NC::Buffer now_playing_prefix;
|
||||||
NC::WBuffer now_playing_suffix;
|
NC::Buffer now_playing_suffix;
|
||||||
NC::Buffer modified_item_prefix;
|
NC::Buffer modified_item_prefix;
|
||||||
|
|
||||||
NC::Color color1;
|
NC::Color color1;
|
||||||
|
|||||||
@@ -345,8 +345,8 @@ void Status::Changes::elapsedTime()
|
|||||||
}
|
}
|
||||||
|
|
||||||
NC::WBuffer first, second;
|
NC::WBuffer first, second;
|
||||||
String2Buffer(ToWString(IConv::utf8ToLocale(np.toString(Config.new_header_first_line, "$"))), first);
|
stringToBuffer(ToWString(IConv::utf8ToLocale(np.toString(Config.new_header_first_line, "$"))), first);
|
||||||
String2Buffer(ToWString(IConv::utf8ToLocale(np.toString(Config.new_header_second_line, "$"))), second);
|
stringToBuffer(ToWString(IConv::utf8ToLocale(np.toString(Config.new_header_second_line, "$"))), second);
|
||||||
|
|
||||||
size_t first_len = wideLength(first.str());
|
size_t first_len = wideLength(first.str());
|
||||||
size_t first_margin = (std::max(tracklength.length()+1, VolumeState.length()))*2;
|
size_t first_margin = (std::max(tracklength.length()+1, VolumeState.length()))*2;
|
||||||
@@ -397,7 +397,7 @@ void Status::Changes::elapsedTime()
|
|||||||
tracklength += "]";
|
tracklength += "]";
|
||||||
}
|
}
|
||||||
NC::WBuffer np_song;
|
NC::WBuffer np_song;
|
||||||
String2Buffer(ToWString(IConv::utf8ToLocale(np.toString(Config.song_status_format, "$"))), np_song);
|
stringToBuffer(ToWString(IConv::utf8ToLocale(np.toString(Config.song_status_format, "$"))), 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" ** ");
|
np_song.write(*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;
|
||||||
|
|||||||
Reference in New Issue
Block a user