changeset 37:76d774822dac

mpc: support args in all commands
author David Demelier <markand@malikania.fr>
date Tue, 01 May 2018 12:36:51 +0200
parents b970ba24bdef
children b8ee1540e065
files dmenu-mpc/main.cpp
diffstat 1 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/dmenu-mpc/main.cpp	Tue May 01 12:32:16 2018 +0200
+++ b/dmenu-mpc/main.cpp	Tue May 01 12:36:51 2018 +0200
@@ -135,9 +135,24 @@
 
 // }}}
 
+// {{{ args
+
+auto args() -> std::vector<std::string>
+{
+    const auto section = dmenu::config("mpc");
+    const auto it = section.find("args");
+
+    if (it == section.end())
+        return { "-p mpc", "-l 16" };
+
+    return *it;
+}
+
+// }}}
+
 // {{{ connect
 
-connection connect()
+auto connect() -> connection
 {
     const auto section = dmenu::config("mpc");
     const auto host = section.get("host").get_value();
@@ -159,7 +174,7 @@
 
 // {{{ add
 
-std::vector<std::string> add_list_all(struct mpd_connection* conn)
+auto add_list_all(struct mpd_connection* conn) -> std::vector<std::string>
 {
     using song = std::unique_ptr<struct mpd_song, void (*)(struct mpd_song*)>;
 
@@ -176,7 +191,7 @@
     return result;
 }
 
-std::string add_select(const tree& tree, bool is_root)
+auto add_select(const tree& tree, bool is_root) -> std::string
 {
     std::vector<std::string> lines{"."};
 
@@ -187,7 +202,7 @@
     for (const auto& child : tree.children)
         lines.push_back(child.first);
 
-    return dmenu::run({ "-l 16" }, lines);
+    return dmenu::run(args(), lines);
 }
 
 void add(struct mpd_connection* conn)
@@ -280,18 +295,7 @@
 
 // {{{ menu
 
-auto menu_args() -> std::vector<std::string>
-{
-    const auto section = dmenu::config("mpc");
-    const auto it = section.find("args");
-
-    if (it == section.end())
-        return { "-p mpc", "-l 16" };
-
-    return *it;
-}
-
-boost::optional<std::string> menu()
+auto menu() -> boost::optional<std::string>
 {
     static const std::vector<std::string> lines{
         "add",
@@ -303,7 +307,7 @@
         "clear"
     };
 
-    const auto selection = dmenu::run(menu_args(), lines);
+    const auto selection = dmenu::run(args(), lines);
 
     if (selection.empty())
         return boost::none;