Skip to content

Commit

Permalink
Add a --no-stdin cli argument to avoid cin (surge-synthesizer#7725)
Browse files Browse the repository at this point in the history
cin requires a stdin which in daemon mode you dont have
so make an option to only terminate in SIGINT/SIGTERM

Closes surge-synthesizer#7724
  • Loading branch information
baconpaul committed Aug 8, 2024
1 parent 7ee9ba7 commit 3a9bbb8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/surge-xt/cli/cli-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ int main(int argc, char **argv)
std::string initPatch{};
app.add_flag("--init-patch", initPatch, "Choose this file path as the initial patch.");

bool noStdIn{false};
app.add_flag("--no-stdin", noStdIn,
"Do not assume stdin and do not poll keyboard for quit or ctrl-d. Useful for "
"daemon modes.");

CLI11_PARSE(app, argc, argv);

if (listDevices)
Expand Down Expand Up @@ -612,15 +617,22 @@ int main(int argc, char **argv)

if (needsMessageLoop)
{
LOG(BASIC, "Beginning message loop...");
LOG(BASIC, "Running CLI with message loop");
}
else
{
LOG(BASIC, "Running");
LOG(BASIC, "Running CLI without message loop");
}

std::thread keyboardInputThread([]() { isQuitPressed(); });
keyboardInputThread.detach();
if (!noStdIn)
{
std::thread keyboardInputThread([]() { isQuitPressed(); });
keyboardInputThread.detach();
}
else
{
LOG(BASIC, "Daemon mode without stdin. Send SIGINT or SIGTERM to cleanly stop execution.");
}

#ifndef WINDOWS
signal(SIGINT, ctrlc_callback_handler);
Expand Down

0 comments on commit 3a9bbb8

Please sign in to comment.