From 33f5ba0b60a0d60bd63e3bde1e07fc2a2ffc456a Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Mon, 26 Jun 2017 03:51:53 +0200 Subject: Allow running arbitrary MPD commands --- liberty | 2 +- nncmpp.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/liberty b/liberty index 3835b6e..6e9217e 160000 --- a/liberty +++ b/liberty @@ -1 +1 @@ -Subproject commit 3835b6e49975039a9f72b8920238f3141e7becea +Subproject commit 6e9217e5d05d95849fbaa795f92eca4ad86b1507 diff --git a/nncmpp.c b/nncmpp.c index 65435d3..735d693 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -1555,6 +1555,7 @@ app_goto_tab (int tab_index) \ XX( MPD_ADD, "Add song to playlist" ) \ XX( MPD_REPLACE, "Replace playlist with song" ) \ + XX( MPD_COMMAND, "Send a raw command to MPD" ) \ \ XX( CHOOSE, "Choose item" ) \ XX( DELETE, "Delete item" ) \ @@ -1844,6 +1845,22 @@ app_setvol (int value) return result; } +static void +app_on_editor_end (bool confirmed) +{ + struct mpd_client *c = &g.client; + if (!confirmed) + return; + + size_t len; + char *u8 = (char *) u32_to_u8 (g.editor_line, g.editor_len + 1, NULL, &len); + mpd_client_send_command_raw (c, u8); + free (u8); + + mpd_client_add_task (c, mpd_on_simple_response, NULL); + mpd_client_idle (c, 0); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static bool @@ -1865,6 +1882,10 @@ app_process_action (enum action action) clear (); app_invalidate (); return true; + case ACTION_MPD_COMMAND: + app_editor_start (':'); + g.on_editor_end = app_on_editor_end; + return true; default: return false; @@ -2071,6 +2092,7 @@ g_default_bindings[] = { "Backspace", ACTION_UP, {}}, { "a", ACTION_MPD_ADD, {}}, { "r", ACTION_MPD_REPLACE, {}}, + { ":", ACTION_MPD_COMMAND, {}}, { "Left", ACTION_MPD_PREVIOUS, {}}, { "Right", ACTION_MPD_NEXT, {}}, -- cgit v1.2.3-70-g09d2