From ead5255df177dc3b05f1198246e2c2e71036de80 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 21 Sep 2009 01:17:54 +0200 Subject: [PATCH] new feature: support for custom prefix/suffix of now playing song --- doc/config | 23 ++++++++++++++++------- doc/ncmpcpp.1 | 6 ++++++ src/display.cpp | 12 +++++++----- src/settings.cpp | 18 ++++++++++++++++++ src/settings.h | 2 ++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/doc/config b/doc/config index 3f425ca8..f1e9d273 100644 --- a/doc/config +++ b/doc/config @@ -115,12 +115,6 @@ # #tag_editor_album_format = "{(%y) }%b" # -#browser_playlist_prefix = "$2playlist$9 " -# -#selected_item_prefix = "$6" -# -#selected_item_suffix = "$9" -# ## ## Note: Below variables are for alternative version of user's interface. ## Their syntax supports all tags and colors listed above plus some extra @@ -128,7 +122,7 @@ ## After that you can put: ## ## - b - bold text -## - u - underlined text +## - u - underline text ## - r - reverse colors ## - a - use alternative character set ## @@ -142,6 +136,21 @@ # #alternative_header_second_line_format = "{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}" # +## +## Note: Below variables also supports +## text attributes listed above. +## +# +#now_playing_prefix = "$b" +# +#now_playing_suffix = "$/b" +# +#browser_playlist_prefix = "$2playlist$9 " +# +#selected_item_prefix = "$6" +# +#selected_item_suffix = "$9" +# ## colors are not supported for below variable # #song_window_title_format = "{%a - }{%t}|{%f}" diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index bfd310ed..316023c2 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -114,6 +114,12 @@ Prefix for playlists in Browser. .B default_tag_editor_pattern = TEXT Deafult pattern used by Tag editor's parser. .TP +.B now_playing_prefix = TEXT +Prefix for currently playing song. +.TP +.B now_playing_suffix = TEXT +Suffix for currently playing song. +.TP .B selected_item_prefix = TEXT Prefix for selected items. .TP diff --git a/src/display.cpp b/src/display.cpp index d96a18d1..c07d01e7 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -107,7 +107,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) bool is_now_playing = menu == myPlaylist->Items && menu->CurrentlyDrawedPosition() == myPlaylist->NowPlaying; if (is_now_playing) - *menu << fmtBold; + *menu << Config.now_playing_prefix; if (Config.columns.empty()) return; @@ -209,7 +209,7 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu *menu) if ((--it)->color != clDefault) *menu << clEnd; if (is_now_playing) - *menu << fmtBoldEnd; + *menu << Config.now_playing_suffix; } void Display::Songs(const MPD::Song &s, void *data, Menu *menu) @@ -219,7 +219,7 @@ void Display::Songs(const MPD::Song &s, void *data, Menu *menu) bool is_now_playing = menu == myPlaylist->Items && menu->CurrentlyDrawedPosition() == myPlaylist->NowPlaying; if (is_now_playing) - *menu << fmtBold; + *menu << Config.now_playing_prefix; std::string line = s.toString(*static_cast(data)); for (std::string::const_iterator it = line.begin(); it != line.end(); ++it) @@ -235,8 +235,10 @@ void Display::Songs(const MPD::Song &s, void *data, Menu *menu) basic_buffer buf; buf << U(" "); String2Buffer(TO_WSTRING(line.substr(it-line.begin()+1)), buf); + if (is_now_playing) + buf << Config.now_playing_suffix; *menu << XY(menu->GetWidth()-buf.Str().length(), menu->Y()) << buf; - break; + return; } else *menu << *it; @@ -245,7 +247,7 @@ void Display::Songs(const MPD::Song &s, void *data, Menu *menu) *menu << *it; } if (is_now_playing) - *menu << fmtBoldEnd; + *menu << Config.now_playing_suffix; } void Display::Tags(const MPD::Song &s, void *data, Menu *menu) diff --git a/src/settings.cpp b/src/settings.cpp index 931a8899..ca7684df 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -262,6 +262,8 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.pattern = "%n - %t"; conf.selected_item_prefix << clMagenta; conf.selected_item_suffix << clEnd; + conf.now_playing_prefix << fmtBold; + conf.now_playing_suffix << fmtBoldEnd; conf.color1 = clWhite; conf.color2 = clGreen; conf.empty_tags_color = clCyan; @@ -670,6 +672,22 @@ void ReadConfiguration(ncmpcpp_config &conf) String2Buffer(v, conf.selected_item_suffix); } } + else if (cl.find("now_playing_prefix") != std::string::npos) + { + if (!v.empty()) + { + conf.now_playing_prefix.Clear(); + String2Buffer(v, conf.now_playing_prefix); + } + } + else if (cl.find("now_playing_suffix") != std::string::npos) + { + if (!v.empty()) + { + conf.now_playing_suffix.Clear(); + String2Buffer(TO_WSTRING(v), conf.now_playing_suffix); + } + } else if (cl.find("color1") != std::string::npos) { if (!v.empty()) diff --git a/src/settings.h b/src/settings.h index c45c06d7..1c1290e0 100644 --- a/src/settings.h +++ b/src/settings.h @@ -150,6 +150,8 @@ struct ncmpcpp_config Buffer browser_playlist_prefix; Buffer selected_item_prefix; Buffer selected_item_suffix; + Buffer now_playing_prefix; + basic_buffer now_playing_suffix; Color color1; Color color2;