mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 06:39:33 +02:00
Cleanup binary stream print a little (#637)
This commit is contained in:
parent
7fa1ad010b
commit
4383b372f5
@ -7,6 +7,7 @@ fn main() {
|
|||||||
width: 16,
|
width: 16,
|
||||||
group: 4,
|
group: 4,
|
||||||
chunk: 1,
|
chunk: 1,
|
||||||
|
address_offset: 0,
|
||||||
skip: Some(10),
|
skip: Some(10),
|
||||||
// length: Some(5),
|
// length: Some(5),
|
||||||
// length: None,
|
// length: None,
|
||||||
|
@ -57,6 +57,8 @@ pub struct HexConfig {
|
|||||||
pub group: usize,
|
pub group: usize,
|
||||||
/// Source bytes per chunk (word). 0 for single word.
|
/// Source bytes per chunk (word). 0 for single word.
|
||||||
pub chunk: usize,
|
pub chunk: usize,
|
||||||
|
/// Offset to start counting addresses from
|
||||||
|
pub address_offset: usize,
|
||||||
/// Bytes from 0 to skip
|
/// Bytes from 0 to skip
|
||||||
pub skip: Option<usize>,
|
pub skip: Option<usize>,
|
||||||
/// Length to return
|
/// Length to return
|
||||||
@ -73,6 +75,7 @@ impl Default for HexConfig {
|
|||||||
width: 16,
|
width: 16,
|
||||||
group: 4,
|
group: 4,
|
||||||
chunk: 1,
|
chunk: 1,
|
||||||
|
address_offset: 0,
|
||||||
skip: None,
|
skip: None,
|
||||||
length: None,
|
length: None,
|
||||||
}
|
}
|
||||||
@ -164,6 +167,8 @@ where
|
|||||||
|
|
||||||
let skip = cfg.skip.unwrap_or(0);
|
let skip = cfg.skip.unwrap_or(0);
|
||||||
|
|
||||||
|
let address_offset = cfg.address_offset;
|
||||||
|
|
||||||
let source_part_vec: Vec<u8> = source
|
let source_part_vec: Vec<u8> = source
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
@ -205,11 +210,11 @@ where
|
|||||||
writer,
|
writer,
|
||||||
"{}{:08x}{}: ",
|
"{}{:08x}{}: ",
|
||||||
style.prefix(),
|
style.prefix(),
|
||||||
i * cfg.width + skip,
|
i * cfg.width + skip + address_offset,
|
||||||
style.suffix()
|
style.suffix()
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
write!(writer, "{:08x}: ", i * cfg.width + skip,)?;
|
write!(writer, "{:08x}: ", i * cfg.width + skip + address_offset,)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i, x) in row.as_ref().iter().enumerate() {
|
for (i, x) in row.as_ref().iter().enumerate() {
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -635,11 +635,21 @@ fn print_pipeline_data(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
PipelineData::ByteStream(stream, _, _) => {
|
PipelineData::ByteStream(stream, _, _) => {
|
||||||
|
let mut address_offset = 0;
|
||||||
for v in stream {
|
for v in stream {
|
||||||
|
let cfg = nu_pretty_hex::HexConfig {
|
||||||
|
title: false,
|
||||||
|
address_offset,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let v = v?;
|
||||||
|
address_offset += v.len();
|
||||||
|
|
||||||
let s = if v.iter().all(|x| x.is_ascii()) {
|
let s = if v.iter().all(|x| x.is_ascii()) {
|
||||||
format!("{}", String::from_utf8_lossy(&v?))
|
format!("{}", String::from_utf8_lossy(&v))
|
||||||
} else {
|
} else {
|
||||||
format!("{}\n", nu_pretty_hex::pretty_hex(&v?))
|
nu_pretty_hex::config_hex(&v, cfg)
|
||||||
};
|
};
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user