diff --git a/doc/config b/doc/config index 4109f6eb..bcef80e7 100644 --- a/doc/config +++ b/doc/config @@ -208,7 +208,9 @@ ## - r - column will be right aligned ## - E - if tag is empty, empty tag marker won't be displayed ## -## E.g. {lr} will give you right aligned column of lengths. +## You can also give a column custom name by putting it after +## attributes, separated with character ':', e.g. {lr:Length} +## gives you right aligned column of lengths named "Length". ## # #song_columns_list_format = "(7f)[green]{l} (25)[cyan]{a} (40)[]{t} (30)[red]{b}" diff --git a/src/display.cpp b/src/display.cpp index 0e6464a2..c934857c 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -28,7 +28,7 @@ std::string Display::Columns() if (Config.columns.empty()) return ""; - std::string result, tag; + std::basic_string result, tag; size_t where = 0; int width; @@ -46,71 +46,79 @@ std::string Display::Columns() else width = it->width*(it->fixed ? 1 : COLS/100.0); - switch (it->type) + if (it->name.empty()) { - case 'l': - tag = "Time"; - break; - case 'f': - tag = "Filename"; - break; - case 'D': - tag = "Directory"; - break; - case 'a': - tag = "Artist"; - break; - case 'A': - tag = "Album Artist"; - break; - case 't': - tag = "Title"; - break; - case 'b': - tag = "Album"; - break; - case 'y': - tag = "Year"; - break; - case 'n': - case 'N': - tag = "Track"; - break; - case 'g': - tag = "Genre"; - break; - case 'c': - tag = "Composer"; - break; - case 'p': - tag = "Performer"; - break; - case 'd': - tag = "Disc"; - break; - case 'C': - tag = "Comment"; - break; - default: - tag.clear(); - break; + switch (it->type) + { + case 'l': + tag = U("Time"); + break; + case 'f': + tag = U("Filename"); + break; + case 'D': + tag = U("Directory"); + break; + case 'a': + tag = U("Artist"); + break; + case 'A': + tag = U("Album Artist"); + break; + case 't': + tag = U("Title"); + break; + case 'b': + tag = U("Album"); + break; + case 'y': + tag = U("Year"); + break; + case 'n': + case 'N': + tag = U("Track"); + break; + case 'g': + tag = U("Genre"); + break; + case 'c': + tag = U("Composer"); + break; + case 'p': + tag = U("Performer"); + break; + case 'd': + tag = U("Disc"); + break; + case 'C': + tag = U("Comment"); + break; + default: + tag.clear(); + break; + } } + else + tag = it->name; if (it->right_alignment) { long i = width-tag.length()-(it != Config.columns.begin()); if (i > 0) - result += std::string(i, ' '); + result.resize(result.length()+i, ' '); } where += width; result += tag; if (result.length() > where) - result = result.substr(0, where); + { + result.resize(where); + result += ' '; + } else - for (size_t i = result.length(); i <= where && i < size_t(COLS); ++i, result += ' ') { } + result.resize(std::min(where+1, size_t(COLS)), ' '); } - return result; + return TO_STRING(result); } void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) diff --git a/src/helpers.cpp b/src/helpers.cpp index 356ad5f7..9e1893d5 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -338,8 +338,9 @@ std::string FindSharedDir(const std::string &one, const std::string &two) std::string GetLineValue(std::string &line, char a, char b, bool once) { int pos[2] = { -1, -1 }; - size_t i; - for (i = line.find(a); i != std::string::npos && pos[1] < 0; i = line.find(b, i)) + char x = a; + size_t i = 0; + while ((i = line.find(x, i)) != std::string::npos && pos[1] < 0) { if (i && line[i-1] == '\\') { @@ -349,10 +350,22 @@ std::string GetLineValue(std::string &line, char a, char b, bool once) if (once) line[i] = 0; pos[pos[0] >= 0] = i++; + if (x == a) + x = b; } - pos[0]++; + ++pos[0]; std::string result = pos[0] >= 0 && pos[1] >= 0 ? line.substr(pos[0], pos[1]-pos[0]) : ""; - Replace(result, "\\\"", "\""); + + // replace \a and \b to a and b respectively + char r1[] = "\\ ", r2[] = " "; + r1[1] = r2[0] = a; + Replace(result, r1, r2); + if (a != b) + { + r1[1] = r2[0] = b; + Replace(result, r1, r2); + } + return result; } diff --git a/src/settings.cpp b/src/settings.cpp index adb4a87c..7e23eadb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1143,7 +1143,8 @@ void NcmpcppConfig::Read() } f.close(); - for (std::string width = GetLineValue(song_list_columns_format, '(', ')', 1); !width.empty(); width = GetLineValue(song_list_columns_format, '(', ')', 1)) + std::string width; + while (!(width = GetLineValue(song_list_columns_format, '(', ')', 1)).empty()) { Column col; col.color = IntoColor(GetLineValue(song_list_columns_format, '[', ']', 1)); @@ -1156,6 +1157,15 @@ void NcmpcppConfig::Read() col.display_empty_tag = 0; } col.fixed = *width.rbegin() == 'f'; + + // alternative name + size_t tag_type_colon_pos = tag_type.find(':'); + if (tag_type_colon_pos != std::string::npos) + { + col.name = TO_WSTRING(tag_type.substr(tag_type_colon_pos+1)); + tag_type.resize(tag_type_colon_pos); + } + for (std::string::const_iterator it = tag_type.begin()+(tag_type.length() > 0); it != tag_type.end(); ++it) { switch (*it) diff --git a/src/settings.h b/src/settings.h index 4040d43c..f9264f6e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -42,6 +42,7 @@ struct Column { Column() : right_alignment(0), display_empty_tag(1) { } + std::basic_string name; unsigned width; Color color; char type;