diff options
author | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-20 17:11:01 +0100 |
---|---|---|
committer | Andrzej Rybczak <andrzej@rybczak.net> | 2020-12-20 17:11:01 +0100 |
commit | 0458c98baee39eb2d4df30576c6cb8227f6ba7b3 (patch) | |
tree | c875ba67f01c7ccdbbe750c89e5413fc4c3a3083 | |
parent | 948d168790aa5580e1bef8ff15e01b276925ccc6 (diff) |
Add run_external_console_command action for running terminal applications
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | doc/bindings | 4 | ||||
-rw-r--r-- | src/bindings.cpp | 9 | ||||
-rw-r--r-- | src/macro_utilities.cpp | 19 | ||||
-rw-r--r-- | src/macro_utilities.h | 10 |
5 files changed, 42 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d8731a0d..5a64d164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # ncmpcpp-0.9 (2020-12-??) -* Restore curses window after running external command. +* Add `run_external_console_command` action for running terminal applications. * Pass lyrics filename in single quotes to shell. * Add support for fetching lyrics from zeneszoveg.hu. * Add `Play` action for starting playback in stopped state. diff --git a/doc/bindings b/doc/bindings index 6f1c5363..52d53028 100644 --- a/doc/bindings +++ b/doc/bindings @@ -97,6 +97,10 @@ ## - run_external_command "command" - runs given command using ## system() function. ## +## - run_external_console_command "command" - runs given console +## command using system() function. +## +## ## 5) In addition to binding to a key, you can also bind actions ## or chains of actions to a command. If it comes to commands, ## syntax is very similar to defining keys. Here goes example diff --git a/src/bindings.cpp b/src/bindings.cpp index 0a560f2e..792dd637 100644 --- a/src/bindings.cpp +++ b/src/bindings.cpp @@ -201,6 +201,15 @@ std::shared_ptr<Actions::BaseAction> parseActionLine(const std::string &line, F else error() << "empty command passed to run_external_command\n"; } + else if (action_name == "run_external_console_command") + { + std::string command = getEnclosedString(line, '"', '"', 0); + if (!command.empty()) + result = std::static_pointer_cast<Actions::BaseAction>( + std::make_shared<Actions::RunExternalConsoleCommand>(std::move(command))); + else + error() << "empty command passed to run_external_console_command\n"; + } } return result; } diff --git a/src/macro_utilities.cpp b/src/macro_utilities.cpp index 9f72805e..6cd05550 100644 --- a/src/macro_utilities.cpp +++ b/src/macro_utilities.cpp @@ -88,7 +88,24 @@ RunExternalCommand::RunExternalCommand(std::string &&command) void RunExternalCommand::run() { GNUC_UNUSED int res; - res = std::system((m_command + " >/dev/null 2>&1").c_str()); + res = std::system(("nohup " + m_command + " >/dev/null 2>&1 &").c_str()); +} + +RunExternalConsoleCommand::RunExternalConsoleCommand(std::string &&command) + : BaseAction(Type::MacroUtility, "run_external_console_command") + , m_command(std::move(command)) +{ + m_name += " \""; + m_name += m_command; + m_name += "\""; +} + +void RunExternalConsoleCommand::run() +{ + GNUC_UNUSED int res; + NC::pauseScreen(); + res = std::system(m_command.c_str()); + NC::unpauseScreen(); } } diff --git a/src/macro_utilities.h b/src/macro_utilities.h index 660e6a53..0e6168d7 100644 --- a/src/macro_utilities.h +++ b/src/macro_utilities.h @@ -70,6 +70,16 @@ private: std::string m_command; }; +struct RunExternalConsoleCommand: BaseAction +{ + RunExternalConsoleCommand(std::string &&command); + +private: + virtual void run() override; + + std::string m_command; +}; + } #endif // NCMPCPP_MACRO_UTILITIES_H |