mirror of
https://github.com/nushell/nushell
synced 2025-01-16 07:04:09 +00:00
Merge pull request #62 from elferherrera/lines
Better print out for stream output
This commit is contained in:
commit
d1da75d315
4 changed files with 23 additions and 18 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -234,9 +234,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.10"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d"
|
||||
checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
@ -625,8 +625,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "reedline"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/jntrnr/reedline?branch=main#22fc31c68d1da6a41a93b5cfa901143b4eca4051"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/jntrnr/reedline?branch=main#93c2146fcf4257c40426bc2f0c6903d4115caaf1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossterm",
|
||||
|
@ -772,9 +772,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.76"
|
||||
version = "1.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
|
||||
checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::rc::Rc;
|
|||
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EvaluationContext};
|
||||
use nu_protocol::{Signature, Span, Value, ValueStream};
|
||||
use nu_protocol::{ShellError, Signature, Span, Value, ValueStream};
|
||||
|
||||
pub struct Lines;
|
||||
|
||||
|
@ -25,10 +25,10 @@ impl Command for Lines {
|
|||
fn run(
|
||||
&self,
|
||||
_context: &EvaluationContext,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
input: Value,
|
||||
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
|
||||
let value = match input {
|
||||
match input {
|
||||
#[allow(clippy::needless_collect)]
|
||||
// Collect is needed because the string may not live long enough for
|
||||
// the Rc structure to continue using it. If split could take ownership
|
||||
|
@ -47,10 +47,10 @@ impl Command for Lines {
|
|||
}
|
||||
});
|
||||
|
||||
Value::Stream {
|
||||
Ok(Value::Stream {
|
||||
stream: ValueStream(Rc::new(RefCell::new(iter))),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
})
|
||||
}
|
||||
Value::Stream { stream, span: _ } => {
|
||||
let iter = stream
|
||||
|
@ -78,14 +78,15 @@ impl Command for Lines {
|
|||
})
|
||||
.flatten();
|
||||
|
||||
Value::Stream {
|
||||
Ok(Value::Stream {
|
||||
stream: ValueStream(Rc::new(RefCell::new(iter))),
|
||||
span: Span::unknown(),
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
Ok(value)
|
||||
val => Err(ShellError::UnsupportedInput(
|
||||
format!("Not supported input: {}", val.as_string()?),
|
||||
call.head,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ impl<'call, 'contex> ExternalCommand<'call, 'contex> {
|
|||
// If this external is not the last expression, then its output is piped to a channel
|
||||
// and we create a ValueStream that can be consumed
|
||||
let value = if !self.last_expression {
|
||||
let (tx, rx) = mpsc::sync_channel(0);
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let stdout = child.stdout.take().ok_or_else(|| {
|
||||
ShellError::ExternalCommand(
|
||||
"Error taking stdout from external".to_string(),
|
||||
|
|
|
@ -69,4 +69,8 @@ pub enum ShellError {
|
|||
#[error("External command")]
|
||||
#[diagnostic(code(nu::shell::external_command), url(docsrs))]
|
||||
ExternalCommand(String, #[label("{0}")] Span),
|
||||
|
||||
#[error("Unsupported input")]
|
||||
#[diagnostic(code(nu::shell::unsupported_input), url(docsrs))]
|
||||
UnsupportedInput(String, #[label("{0}")] Span),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue