mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 15:39:06 +01:00
Make use of interruptible stream in various places
This commit is contained in:
parent
2a54ee0c54
commit
35dc7438a5
@ -9,7 +9,6 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{CallInfo, ReturnSuccess, Signature, SyntaxShape, UntaggedValue, Value};
|
||||
use nu_source::Tagged;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
const NAME: &str = "du";
|
||||
const GLOB_PARAMS: MatchOptions = MatchOptions {
|
||||
@ -142,7 +141,6 @@ fn du(args: DuArgs, ctx: &RunnablePerItemContext) -> Result<OutputStream, ShellE
|
||||
let max_depth = args.max_depth.map(|f| f.item);
|
||||
let min_size = args.min_size.map(|f| f.item);
|
||||
|
||||
let stream = async_stream! {
|
||||
let params = DirBuilder {
|
||||
tag: tag.clone(),
|
||||
min: min_size,
|
||||
@ -150,27 +148,22 @@ fn du(args: DuArgs, ctx: &RunnablePerItemContext) -> Result<OutputStream, ShellE
|
||||
ex: exclude,
|
||||
all,
|
||||
};
|
||||
for path in paths {
|
||||
if ctrl_c.load(Ordering::SeqCst) {
|
||||
break;
|
||||
}
|
||||
match path {
|
||||
|
||||
let stream = futures::stream::iter(paths)
|
||||
.interruptible(ctrl_c)
|
||||
.map(move |path| match path {
|
||||
Ok(p) => {
|
||||
if p.is_dir() {
|
||||
yield Ok(ReturnSuccess::Value(
|
||||
Ok(ReturnSuccess::Value(
|
||||
DirInfo::new(p, ¶ms, max_depth).into(),
|
||||
));
|
||||
))
|
||||
} else {
|
||||
match FileInfo::new(p, deref, tag.clone()) {
|
||||
Ok(f) => yield Ok(ReturnSuccess::Value(f.into())),
|
||||
Err(e) => yield Err(e)
|
||||
FileInfo::new(p, deref, tag.clone()).map(|v| ReturnSuccess::Value(v.into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => yield Err(e),
|
||||
}
|
||||
}
|
||||
};
|
||||
Err(e) => Err(e),
|
||||
});
|
||||
|
||||
Ok(stream.to_output_stream())
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ use rustyline::completion::FilenameCompleter;
|
||||
use rustyline::hint::{Hinter, HistoryHinter};
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
use std::sync::atomic::Ordering;
|
||||
use trash as SendToTrash;
|
||||
|
||||
#[cfg(unix)]
|
||||
@ -163,10 +162,6 @@ impl Shell for FilesystemShell {
|
||||
// Generated stream: impl Stream<Item = Result<ReturnSuccess, ShellError>
|
||||
let stream = async_stream::try_stream! {
|
||||
for path in paths {
|
||||
if ctrl_c.load(Ordering::SeqCst) {
|
||||
break;
|
||||
}
|
||||
|
||||
let path = path.map_err(|e| ShellError::from(e.into_error()))?;
|
||||
|
||||
if !all && is_hidden_dir(&path) {
|
||||
@ -196,7 +191,7 @@ impl Shell for FilesystemShell {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(stream.to_output_stream())
|
||||
Ok(stream.interruptible(ctrl_c).to_output_stream())
|
||||
}
|
||||
|
||||
fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
Loading…
Reference in New Issue
Block a user