Add run_external_console_command action for running terminal applications
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user