diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-05-13 14:24:11 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-13 15:07:44 +0200 |
commit | 6cd4d136a0fe7b98a05f2ffe1037dc38cd84ba6e (patch) | |
tree | 632a7194f8785f7b9c0ecd26c179a78f990caaa9 | |
parent | 98d25324fd8cb4c6710b1a57cd661bd68cae5ba9 (diff) | |
download | serenity-6cd4d136a0fe7b98a05f2ffe1037dc38cd84ba6e.zip |
Shell: Break out of continuation when ^C is pressed
This fixes the little issue with Shell not allowing cancellation of
commands once they were in continuation mode
```
$ ls '
$ # No matter what we do here, we cannot escape 'ls'
```
-rw-r--r-- | Shell/main.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index a0e96e352c..0b9a5cedfc 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -1540,8 +1540,25 @@ int main(int argc, char** argv) StringBuilder complete_line_builder; + bool should_break_current_command { false }; + + editor.on_interrupt_handled = [&] { + if (s_should_continue != ExitCodeOrContinuationRequest::ContinuationRequest::Nothing) { + should_break_current_command = true; + editor.finish(); + } + }; + for (;;) { auto line = editor.get_line(prompt()); + + if (should_break_current_command) { + complete_line_builder.clear(); + s_should_continue = ExitCodeOrContinuationRequest::ContinuationRequest::Nothing; + should_break_current_command = false; + continue; + } + if (line.is_empty()) continue; |