new feature: right aligned columns

This commit is contained in:
Andrzej Rybczak
2009-08-12 20:58:24 +02:00
parent c30fec4ee6
commit a6f3fa0c0c
4 changed files with 43 additions and 28 deletions

View File

@@ -131,6 +131,10 @@
## ##
## - color is optional (if you want the default one, type []) ## - color is optional (if you want the default one, type [])
## ##
## Note: If you want a column to be right aligned, put 'r' character
## after displayed tag character, e.g. {lr} will give you right aligned
## column of lengths.
##
# #
#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; std::string result, tag;
size_t where = 0; size_t where = 0;
int width; int width;
@@ -39,56 +39,57 @@ std::string Display::Columns()
for (std::vector<Column>::const_iterator it = Config.columns.begin(); it != Config.columns.end(); ++it) for (std::vector<Column>::const_iterator it = Config.columns.begin(); it != Config.columns.end(); ++it)
{ {
width = it->width*(it->fixed ? 1 : COLS/100.0); width = last_fixed && it == next2last ? COLS-where-(++next2last)->width : (it->width*(it->fixed ? 1 : COLS/100.0));
switch (it->type) switch (it->type)
{ {
case 'l': case 'l':
result += "Time"; tag = "Time";
break; break;
case 'f': case 'f':
result += "Filename"; tag = "Filename";
break; break;
case 'F': case 'F':
result += "Full filename"; tag = "Full filename";
break; break;
case 'a': case 'a':
result += "Artist"; tag = "Artist";
break; break;
case 't': case 't':
result += "Title"; tag = "Title";
break; break;
case 'b': case 'b':
result += "Album"; tag = "Album";
break; break;
case 'y': case 'y':
result += "Year"; tag = "Year";
break; break;
case 'n': case 'n':
result += "Track"; tag = "Track";
break; break;
case 'g': case 'g':
result += "Genre"; tag = "Genre";
break; break;
case 'c': case 'c':
result += "Composer"; tag = "Composer";
break; break;
case 'p': case 'p':
result += "Performer"; tag = "Performer";
break; break;
case 'd': case 'd':
result += "Disc"; tag = "Disc";
break; break;
case 'C': case 'C':
result += "Comment"; tag = "Comment";
break; break;
default: default:
break; break;
} }
if (last_fixed && it == next2last) if (it->right_alignment)
where = COLS-(++next2last)->width; for (long i = 0; i < long(width-tag.length()-(it != Config.columns.begin())); ++i, result += ' ') { }
else
where += width; where += width;
result += tag;
if (result.length() > where) if (result.length() > where)
result = result.substr(0, where); result = result.substr(0, where);
@@ -124,7 +125,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu<MPD::Song> *menu)
*menu << clEnd; *menu << clEnd;
} }
width = it->width*(it->fixed ? 1 : COLS/100.0); width = last_fixed && it == next2last ? COLS-where-(++next2last)->width : (it->width*(it->fixed ? 1 : COLS/100.0));
MPD::Song::GetFunction get = 0; MPD::Song::GetFunction get = 0;
switch (it->type) switch (it->type)
@@ -178,14 +179,21 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu<MPD::Song> *menu)
*menu << it->color; *menu << it->color;
whline(menu->Raw(), 32, menu->GetWidth()-where); whline(menu->Raw(), 32, menu->GetWidth()-where);
std::string tag = (s.*get)(); std::string tag = (s.*get)();
if (!tag.empty()) if (it->right_alignment)
*menu << tag; {
int x, y;
menu->GetXY(x, y);
std::basic_string<my_char_t> wtag = TO_WSTRING(tag.empty() ? Config.empty_tag : tag).substr(0, width-!!x);
*menu << XY(x+width-Window::Length(wtag)-!!x, y) << wtag;
}
else else
*menu << Config.empty_tag; {
if (last_fixed && it == next2last) if (!tag.empty())
where = COLS-(++next2last)->width; *menu << tag;
else else
where += width; *menu << Config.empty_tag;
}
where += width;
} }
if ((--it)->color != clDefault) if ((--it)->color != clDefault)
*menu << clEnd; *menu << clEnd;

View File

@@ -823,8 +823,10 @@ void ReadConfiguration(ncmpcpp_config &conf)
{ {
Column col; Column col;
col.color = IntoColor(GetLineValue(conf.song_list_columns_format, '[', ']', 1)); col.color = IntoColor(GetLineValue(conf.song_list_columns_format, '[', ']', 1));
col.type = GetLineValue(conf.song_list_columns_format, '{', '}', 1)[0]; std::string tag_type = GetLineValue(conf.song_list_columns_format, '{', '}', 1);
col.type = tag_type.at(0);
col.fixed = *width.rbegin() == 'f'; col.fixed = *width.rbegin() == 'f';
col.right_alignment = tag_type.length() > 1 && tag_type[1] == 'r';
col.width = StrToInt(width); col.width = StrToInt(width);
conf.columns.push_back(col); conf.columns.push_back(col);
} }

View File

@@ -43,6 +43,7 @@ struct Column
Color color; Color color;
char type; char type;
bool fixed; bool fixed;
bool right_alignment;
}; };
struct ncmpcpp_keys struct ncmpcpp_keys