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

@@ -28,7 +28,7 @@ std::string Display::Columns()
if (Config.columns.empty())
return "";
std::string result, tag;
std::basic_string<my_char_t> 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<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)
{
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;
}

View File

@@ -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)

View File

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