Feat: listen for signal on glob command (#9088)

Fixes : #9002 

listen for signal cancel .
other way is in listening parallel for ctrl+c wit Arc and mps channels
if this way is not a profit
This commit is contained in:
Amirhossein Akhlaghpour 2023-05-03 23:21:25 +03:30 committed by GitHub
parent 345cdef113
commit 5fcbefb7b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,6 +115,7 @@ impl Command for Glob {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let ctrlc = engine_state.ctrlc.clone();
let span = call.head;
let path = current_dir(engine_state, stack)?;
let glob_pattern: Spanned<String> = call.req(engine_state, stack, 0)?;
@ -154,7 +155,7 @@ impl Command for Glob {
};
#[allow(clippy::needless_collect)]
let glob_results: Vec<Value> = glob
let glob_results = glob
.walk_with_behavior(
path,
WalkBehavior {
@ -162,21 +163,27 @@ impl Command for Glob {
..Default::default()
},
)
.flatten()
.filter(|entry| {
.flatten();
let mut result: Vec<Value> = Vec::new();
for entry in glob_results {
if nu_utils::ctrl_c::was_pressed(&ctrlc) {
result.clear();
break;
}
let file_type = entry.file_type();
!(no_dirs && file_type.is_dir()
if !(no_dirs && file_type.is_dir()
|| no_files && file_type.is_file()
|| no_symlinks && file_type.is_symlink())
})
.map(|entry| Value::String {
{
result.push(Value::String {
val: entry.into_path().to_string_lossy().to_string(),
span,
})
.collect();
});
}
}
Ok(glob_results
Ok(result
.into_iter()
.into_pipeline_data(engine_state.ctrlc.clone()))
}