"maybe text codec" version 2 (#871)

* Add a RawStream that can be binary or string

* Finish up updating the into's
This commit is contained in:
JT
2022-01-28 13:32:33 -05:00
committed by GitHub
parent 3f9fa28ae3
commit 020ad24b25
26 changed files with 326 additions and 433 deletions

View File

@ -17,7 +17,7 @@ use nu_parser::parse;
use nu_protocol::{
ast::{Call, Expr, Expression, Pipeline, Statement},
engine::{Command, EngineState, Stack, StateWorkingSet},
ByteStream, Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Span,
Category, Example, IntoPipelineData, PipelineData, RawStream, ShellError, Signature, Span,
Spanned, SyntaxShape, Value, CONFIG_VARIABLE_ID,
};
use std::{
@ -119,11 +119,8 @@ fn main() -> Result<()> {
let stdin = std::io::stdin();
let buf_reader = BufReader::new(stdin);
PipelineData::ByteStream(
ByteStream {
stream: Box::new(BufferedReader::new(buf_reader)),
ctrlc: Some(ctrlc),
},
PipelineData::RawStream(
RawStream::new(Box::new(BufferedReader::new(buf_reader)), Some(ctrlc)),
redirect_stdin.span,
None,
)

View File

@ -198,36 +198,13 @@ fn print_pipeline_data(
let config = stack.get_config().unwrap_or_default();
match input {
PipelineData::StringStream(stream, _, _) => {
for s in stream {
print!("{}", s?);
let _ = std::io::stdout().flush();
}
return Ok(());
}
PipelineData::ByteStream(stream, _, _) => {
let mut address_offset = 0;
for v in stream {
let cfg = nu_pretty_hex::HexConfig {
title: false,
address_offset,
..Default::default()
};
let mut stdout = std::io::stdout();
let v = v?;
address_offset += v.len();
let s = if v.iter().all(|x| x.is_ascii()) {
format!("{}", String::from_utf8_lossy(&v))
} else {
nu_pretty_hex::config_hex(&v, cfg)
};
println!("{}", s);
}
return Ok(());
if let PipelineData::RawStream(stream, _, _) = input {
for s in stream {
let _ = stdout.write(s?.as_binary()?);
}
_ => {}
return Ok(());
}
match engine_state.find_decl("table".as_bytes()) {