Skip to content

Commit 2c29f50

Browse files
Add a keybinding to darwin-framework-tool to call exit(0).
Can be useful to test behavior if an application using the framework decides to exit().
1 parent 60b6beb commit 2c29f50

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
#include <platform/logging/LogV.h>
2424

2525
#include <editline.h>
26+
#include <stdlib.h>
2627

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

303+
el_status_t ExitFunction()
304+
{
305+
exit(0);
306+
return CSstay;
307+
}
308+
299309
CHIP_ERROR InteractiveStartCommand::RunCommand()
300310
{
301311
read_history(kInteractiveModeHistoryFilePath);
@@ -304,8 +314,13 @@ el_status_t StopFunction()
304314
// is dumped to stdout while the user is typing a command.
305315
chip::Logging::SetLogRedirectCallback(LoggingCallback);
306316

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

310325
char * command = nullptr;
311326
int status;

0 commit comments

Comments
 (0)