new feature: customizable columns' names

This commit is contained in:
Andrzej Rybczak
2010-05-17 20:11:50 +02:00
parent 9adb762036
commit 53dfda0f98
5 changed files with 92 additions and 58 deletions

View File

@@ -208,7 +208,9 @@
## - r - column will be right aligned ## - r - column will be right aligned
## - E - if tag is empty, empty tag marker won't be displayed ## - 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}" #song_columns_list_format = "(7f)[green]{l} (25)[cyan]{a} (40)[]{t} (30)[red]{b}"

View File

@@ -28,7 +28,7 @@ std::string Display::Columns()
if (Config.columns.empty()) if (Config.columns.empty())
return ""; return "";
std::string result, tag; std::basic_string<my_char_t> result, tag;
size_t where = 0; size_t where = 0;
int width; int width;
@@ -46,71 +46,79 @@ std::string Display::Columns()
else else
width = it->width*(it->fixed ? 1 : COLS/100.0); width = it->width*(it->fixed ? 1 : COLS/100.0);
switch (it->type) if (it->name.empty())
{ {
case 'l': switch (it->type)
tag = "Time"; {
break; case 'l':
case 'f': tag = U("Time");
tag = "Filename"; break;
break; case 'f':
case 'D': tag = U("Filename");
tag = "Directory"; break;
break; case 'D':
case 'a': tag = U("Directory");
tag = "Artist"; break;
break; case 'a':
case 'A': tag = U("Artist");
tag = "Album Artist"; break;
break; case 'A':
case 't': tag = U("Album Artist");
tag = "Title"; break;
break; case 't':
case 'b': tag = U("Title");
tag = "Album"; break;
break; case 'b':
case 'y': tag = U("Album");
tag = "Year"; break;
break; case 'y':
case 'n': tag = U("Year");
case 'N': break;
tag = "Track"; case 'n':
break; case 'N':
case 'g': tag = U("Track");
tag = "Genre"; break;
break; case 'g':
case 'c': tag = U("Genre");
tag = "Composer"; break;
break; case 'c':
case 'p': tag = U("Composer");
tag = "Performer"; break;
break; case 'p':
case 'd': tag = U("Performer");
tag = "Disc"; break;
break; case 'd':
case 'C': tag = U("Disc");
tag = "Comment"; break;
break; case 'C':
default: tag = U("Comment");
tag.clear(); break;
break; default:
tag.clear();
break;
}
} }
else
tag = it->name;
if (it->right_alignment) if (it->right_alignment)
{ {
long i = width-tag.length()-(it != Config.columns.begin()); long i = width-tag.length()-(it != Config.columns.begin());
if (i > 0) if (i > 0)
result += std::string(i, ' '); result.resize(result.length()+i, ' ');
} }
where += width; where += width;
result += tag; result += tag;
if (result.length() > where) if (result.length() > where)
result = result.substr(0, where); {
result.resize(where);
result += ' ';
}
else 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<MPD::Song> *menu) void Display::SongsInColumns(const MPD::Song &s, void *, Menu<MPD::Song> *menu)

View File

@@ -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) std::string GetLineValue(std::string &line, char a, char b, bool once)
{ {
int pos[2] = { -1, -1 }; int pos[2] = { -1, -1 };
size_t i; char x = a;
for (i = line.find(a); i != std::string::npos && pos[1] < 0; i = line.find(b, i)) size_t i = 0;
while ((i = line.find(x, i)) != std::string::npos && pos[1] < 0)
{ {
if (i && line[i-1] == '\\') if (i && line[i-1] == '\\')
{ {
@@ -349,10 +350,22 @@ std::string GetLineValue(std::string &line, char a, char b, bool once)
if (once) if (once)
line[i] = 0; line[i] = 0;
pos[pos[0] >= 0] = i++; 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]) : ""; 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; return result;
} }

View File

@@ -1143,7 +1143,8 @@ void NcmpcppConfig::Read()
} }
f.close(); 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; Column col;
col.color = IntoColor(GetLineValue(song_list_columns_format, '[', ']', 1)); col.color = IntoColor(GetLineValue(song_list_columns_format, '[', ']', 1));
@@ -1156,6 +1157,15 @@ void NcmpcppConfig::Read()
col.display_empty_tag = 0; col.display_empty_tag = 0;
} }
col.fixed = *width.rbegin() == 'f'; 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) for (std::string::const_iterator it = tag_type.begin()+(tag_type.length() > 0); it != tag_type.end(); ++it)
{ {
switch (*it) switch (*it)

View File

@@ -42,6 +42,7 @@ struct Column
{ {
Column() : right_alignment(0), display_empty_tag(1) { } Column() : right_alignment(0), display_empty_tag(1) { }
std::basic_string<my_char_t> name;
unsigned width; unsigned width;
Color color; Color color;
char type; char type;