Skip to content

Commit

Permalink
Add a keybinding to darwin-framework-tool to call exit(0).
Browse files Browse the repository at this point in the history
Can be useful to test behavior if an application using the framework decides to
exit().
  • Loading branch information
bzbarsky-apple committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 60b6beb commit 2c29f50
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -23,8 +23,12 @@
#include <platform/logging/LogV.h>

#include <editline.h>
#include <stdlib.h>

constexpr char kInteractiveModePrompt[] = "Stop and restart stack: [Ctrl+_] & [Ctrl+^] \nQuit Interactive: 'quit()'\n>>> ";
constexpr char kInteractiveModePrompt[] = "Stop and restart stack: [Ctrl+_] & [Ctrl+^]\n"
"Trigger exit(0): [Ctrl+@]\n"
"Quit Interactive: 'quit()'\n"
">>> ";
constexpr char kInteractiveModeHistoryFilePath[] = "/tmp/darwin_framework_tool_history";
constexpr char kInteractiveModeStopCommand[] = "quit()";
constexpr char kCategoryError[] = "Error";
@@ -296,6 +300,12 @@ el_status_t StopFunction()
return CSstay;
}

el_status_t ExitFunction()
{
exit(0);
return CSstay;
}

CHIP_ERROR InteractiveStartCommand::RunCommand()
{
read_history(kInteractiveModeHistoryFilePath);
@@ -304,8 +314,13 @@ el_status_t StopFunction()
// is dumped to stdout while the user is typing a command.
chip::Logging::SetLogRedirectCallback(LoggingCallback);

// The valid keys to bind are listed at
// https://github.com/troglobit/editline/blob/425584840c09f83bb8fedbf76b599d3a917621ba/src/editline.c#L1941
// but note that some bindings (like Ctrl+Q) might be captured by terminals
// and not make their way to this code.
el_bind_key(CTL('^'), RestartFunction);
el_bind_key(CTL('_'), StopFunction);
el_bind_key(CTL('@'), ExitFunction);

char * command = nullptr;
int status;

0 comments on commit 2c29f50

Please sign in to comment.