diff --git a/doc/config b/doc/config index 387303b3..2641e70f 100644 --- a/doc/config +++ b/doc/config @@ -131,6 +131,10 @@ ## ## - 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}" # diff --git a/src/display.cpp b/src/display.cpp index 74e39a9d..f0499fe9 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; + std::string result, tag; size_t where = 0; int width; @@ -39,56 +39,57 @@ std::string Display::Columns() for (std::vector::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) { case 'l': - result += "Time"; + tag = "Time"; break; case 'f': - result += "Filename"; + tag = "Filename"; break; case 'F': - result += "Full filename"; + tag = "Full filename"; break; case 'a': - result += "Artist"; + tag = "Artist"; break; case 't': - result += "Title"; + tag = "Title"; break; case 'b': - result += "Album"; + tag = "Album"; break; case 'y': - result += "Year"; + tag = "Year"; break; case 'n': - result += "Track"; + tag = "Track"; break; case 'g': - result += "Genre"; + tag = "Genre"; break; case 'c': - result += "Composer"; + tag = "Composer"; break; case 'p': - result += "Performer"; + tag = "Performer"; break; case 'd': - result += "Disc"; + tag = "Disc"; break; case 'C': - result += "Comment"; + tag = "Comment"; break; default: break; } - if (last_fixed && it == next2last) - where = COLS-(++next2last)->width; - else - where += width; + if (it->right_alignment) + for (long i = 0; i < long(width-tag.length()-(it != Config.columns.begin())); ++i, result += ' ') { } + + where += width; + result += tag; if (result.length() > where) result = result.substr(0, where); @@ -124,7 +125,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) *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; switch (it->type) @@ -178,14 +179,21 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) *menu << it->color; whline(menu->Raw(), 32, menu->GetWidth()-where); std::string tag = (s.*get)(); - if (!tag.empty()) - *menu << tag; - else - *menu << Config.empty_tag; - if (last_fixed && it == next2last) - where = COLS-(++next2last)->width; + if (it->right_alignment) + { + int x, y; + menu->GetXY(x, y); + std::basic_string wtag = TO_WSTRING(tag.empty() ? Config.empty_tag : tag).substr(0, width-!!x); + *menu << XY(x+width-Window::Length(wtag)-!!x, y) << wtag; + } else - where += width; + { + if (!tag.empty()) + *menu << tag; + else + *menu << Config.empty_tag; + } + where += width; } if ((--it)->color != clDefault) *menu << clEnd; diff --git a/src/settings.cpp b/src/settings.cpp index 55697b9a..d0b82360 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -823,8 +823,10 @@ void ReadConfiguration(ncmpcpp_config &conf) { Column col; 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.right_alignment = tag_type.length() > 1 && tag_type[1] == 'r'; col.width = StrToInt(width); conf.columns.push_back(col); } diff --git a/src/settings.h b/src/settings.h index 4bf46caa..4c1e5c53 100644 --- a/src/settings.h +++ b/src/settings.h @@ -43,6 +43,7 @@ struct Column Color color; char type; bool fixed; + bool right_alignment; }; struct ncmpcpp_keys