Don't emit a newline in autoview. (#1466)

The extra newline character makes it hard to use nu as part of an
external processing pipeline, since the extra character could taint the
results. For example:

```
$ nu -c 'echo test | xxd'
00000000: 7465 7374                                test
```

versus

```
nu -c 'echo test' | xxd
00000000: 7465 7374 0a                             test.
```
This commit is contained in:
Jason Gedge 2020-03-08 15:18:24 -04:00 committed by GitHub
parent 50fb97f6b7
commit 01dd358a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 11 deletions

View File

@ -112,14 +112,14 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
let result = text.run(command_args, &context.commands); let result = text.run(command_args, &context.commands);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
outln!("{}", s); out!("{}", s);
} }
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::String(s)), value: UntaggedValue::Primitive(Primitive::String(s)),
.. ..
} => { } => {
outln!("{}", s); out!("{}", s);
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::Line(ref s)), value: UntaggedValue::Primitive(Primitive::Line(ref s)),
@ -132,32 +132,32 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
let result = text.run(command_args, &context.commands); let result = text.run(command_args, &context.commands);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
outln!("{}\n", s); out!("{}\n", s);
} }
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::Line(s)), value: UntaggedValue::Primitive(Primitive::Line(s)),
.. ..
} => { } => {
outln!("{}\n", s); out!("{}\n", s);
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::Path(s)), value: UntaggedValue::Primitive(Primitive::Path(s)),
.. ..
} => { } => {
outln!("{}", s.display()); out!("{}", s.display());
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::Int(n)), value: UntaggedValue::Primitive(Primitive::Int(n)),
.. ..
} => { } => {
outln!("{}", n); out!("{}", n);
} }
Value { Value {
value: UntaggedValue::Primitive(Primitive::Decimal(n)), value: UntaggedValue::Primitive(Primitive::Decimal(n)),
.. ..
} => { } => {
outln!("{}", n); out!("{}", n);
} }
Value { value: UntaggedValue::Primitive(Primitive::Binary(ref b)), .. } => { Value { value: UntaggedValue::Primitive(Primitive::Binary(ref b)), .. } => {
@ -169,7 +169,7 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
use pretty_hex::*; use pretty_hex::*;
outln!("{:?}", b.hex_dump()); out!("{:?}", b.hex_dump());
} }
} }
@ -184,7 +184,7 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
let result = table.run(command_args, &context.commands); let result = table.run(command_args, &context.commands);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
outln!("{:?}", item); out!("{:?}", item);
} }
} }
} }
@ -192,7 +192,7 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
} }
} }
_ => { _ => {
//outln!("<no results>"); //out!("<no results>");
} }
} }

View File

@ -68,7 +68,7 @@ macro_rules! trace_out_stream {
}}; }};
} }
pub(crate) use nu_protocol::{errln, outln}; pub(crate) use nu_protocol::{errln, out, outln};
use nu_source::HasFallibleSpan; use nu_source::HasFallibleSpan;
pub(crate) use crate::commands::command::{ pub(crate) use crate::commands::command::{

View File

@ -3,6 +3,15 @@
/// Note: this exists to differentiate between intentional writing to stdout /// Note: this exists to differentiate between intentional writing to stdout
/// and stray printlns left by accident /// and stray printlns left by accident
#[macro_export] #[macro_export]
macro_rules! out {
($($tokens:tt)*) => { print!($($tokens)*) }
}
/// Outputs to standard out with a newline added
///
/// Note: this exists to differentiate between intentional writing to stdout
/// and stray printlns left by accident
#[macro_export]
macro_rules! outln { macro_rules! outln {
($($tokens:tt)*) => { println!($($tokens)*) } ($($tokens:tt)*) => { println!($($tokens)*) }
} }