Add simple stdin input command (#754)

* Add simple stdin input command

* Add binary input

* Tweak binary view
This commit is contained in:
JT
2022-01-15 23:28:28 -05:00
committed by GitHub
parent b78924c777
commit fa5aab8170
4 changed files with 131 additions and 5 deletions

View File

@ -78,11 +78,15 @@ impl Command for Table {
)),
PipelineData::Value(Value::Binary { val, .. }, ..) => Ok(PipelineData::StringStream(
StringStream::from_stream(
vec![Ok(if val.iter().all(|x| x.is_ascii()) {
format!("{}", String::from_utf8_lossy(&val))
} else {
format!("{}\n", nu_pretty_hex::pretty_hex(&val))
})]
vec![Ok(
if val.iter().all(|x| {
*x < 128 && (*x >= b' ' || *x == b'\t' || *x == b'\r' || *x == b'\n')
}) {
format!("{}", String::from_utf8_lossy(&val))
} else {
format!("{}\n", nu_pretty_hex::pretty_hex(&val))
},
)]
.into_iter(),
ctrlc,
),