Fix while ctrlc behavior (#7195)

Currently while didn't respect ctrl-c, and thus non-terminating loops
couldn't be interrupted. This patch fixes this.
This commit is contained in:
Kamil Koczurek 2022-11-22 15:47:12 +01:00 committed by GitHub
parent eb875ea949
commit c9f9078726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
use std::sync::atomic::Ordering;
use nu_engine::{eval_block, eval_expression, CallExt};
use nu_protocol::ast::Call;
use nu_protocol::engine::{Block, Command, EngineState, Stack};
@ -46,6 +48,12 @@ impl Command for While {
let block: Block = call.req(engine_state, stack, 1)?;
loop {
if let Some(ctrlc) = &engine_state.ctrlc {
if ctrlc.load(Ordering::SeqCst) {
break;
}
}
let result = eval_expression(engine_state, stack, cond)?;
match &result {
Value::Bool { val, .. } => {