mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 14:52:12 +02:00
Remove old nushell/merge engine-q
This commit is contained in:
66
crates/nu-pretty-hex/src/lib.rs
Normal file
66
crates/nu-pretty-hex/src/lib.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
// #![no_std]
|
||||
|
||||
//! A Rust library providing pretty hex dump.
|
||||
//!
|
||||
//! A `simple_hex()` way renders one-line hex dump, and a `pretty_hex()` way renders
|
||||
//! columned multi-line hex dump with addressing and ASCII representation.
|
||||
//! A `config_hex()` way renders hex dump in specified format.
|
||||
//!
|
||||
//! ## Example of `simple_hex()`
|
||||
//! ```
|
||||
//! use pretty_hex::*;
|
||||
//!
|
||||
//! let v = vec![222, 173, 190, 239, 202, 254, 32, 24];
|
||||
//! # #[cfg(feature = "alloc")]
|
||||
//! assert_eq!(simple_hex(&v), format!("{}", v.hex_dump()));
|
||||
//!
|
||||
//! println!("{}", v.hex_dump());
|
||||
//! ```
|
||||
//! Output:
|
||||
//!
|
||||
//! ```text
|
||||
//! de ad be ef ca fe 20 18
|
||||
//! ```
|
||||
//! ## Example of `pretty_hex()`
|
||||
//! ```
|
||||
//! use pretty_hex::*;
|
||||
//!
|
||||
//! let v = &include_bytes!("../tests/data");
|
||||
//! # #[cfg(feature = "alloc")]
|
||||
//! assert_eq!(pretty_hex(&v), format!("{:?}", v.hex_dump()));
|
||||
//!
|
||||
//! println!("{:?}", v.hex_dump());
|
||||
//! ```
|
||||
//! Output:
|
||||
//!
|
||||
//! ```text
|
||||
//! Length: 30 (0x1e) bytes
|
||||
//! 0000: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83 kN......~s......
|
||||
//! 0010: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee ....#gKH...5..
|
||||
//! ```
|
||||
//! ## Example of `config_hex()`
|
||||
//! ```
|
||||
//! use pretty_hex::*;
|
||||
//!
|
||||
//! let cfg = HexConfig {title: false, width: 8, group: 0, ..HexConfig::default() };
|
||||
//!
|
||||
//! let v = &include_bytes!("../tests/data");
|
||||
//! # #[cfg(feature = "alloc")]
|
||||
//! assert_eq!(config_hex(&v, cfg), format!("{:?}", v.hex_conf(cfg)));
|
||||
//!
|
||||
//! println!("{:?}", v.hex_conf(cfg));
|
||||
//! ```
|
||||
//! Output:
|
||||
//!
|
||||
//! ```text
|
||||
//! 0000: 6b 4e 1a c3 af 03 d2 1e kN......
|
||||
//! 0008: 7e 73 ba c8 bd 84 0f 83 ~s......
|
||||
//! 0010: 89 d5 cf 90 23 67 4b 48 ....#gKH
|
||||
//! 0018: db b1 bc 35 bf ee ...5..
|
||||
//! ```
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
||||
mod pretty_hex;
|
||||
pub use pretty_hex::*;
|
@@ -7,10 +7,7 @@ fn main() {
|
||||
width: 16,
|
||||
group: 4,
|
||||
chunk: 1,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
address_offset: 0,
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
skip: Some(10),
|
||||
// length: Some(5),
|
||||
// length: None,
|
||||
|
@@ -57,11 +57,8 @@ pub struct HexConfig {
|
||||
pub group: usize,
|
||||
/// Source bytes per chunk (word). 0 for single word.
|
||||
pub chunk: usize,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
/// Offset to start counting addresses from
|
||||
pub address_offset: usize,
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
/// Bytes from 0 to skip
|
||||
pub skip: Option<usize>,
|
||||
/// Length to return
|
||||
@@ -78,10 +75,7 @@ impl Default for HexConfig {
|
||||
width: 16,
|
||||
group: 4,
|
||||
chunk: 1,
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
address_offset: 0,
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
skip: None,
|
||||
length: None,
|
||||
}
|
||||
@@ -173,11 +167,8 @@ where
|
||||
|
||||
let skip = cfg.skip.unwrap_or(0);
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
let address_offset = cfg.address_offset;
|
||||
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
let source_part_vec: Vec<u8> = source
|
||||
.as_ref()
|
||||
.iter()
|
||||
@@ -219,19 +210,11 @@ where
|
||||
writer,
|
||||
"{}{:08x}{}: ",
|
||||
style.prefix(),
|
||||
<<<<<<< HEAD
|
||||
i * cfg.width + skip,
|
||||
style.suffix()
|
||||
)?;
|
||||
} else {
|
||||
write!(writer, "{:08x}: ", i * cfg.width + skip,)?;
|
||||
=======
|
||||
i * cfg.width + skip + address_offset,
|
||||
style.suffix()
|
||||
)?;
|
||||
} else {
|
||||
write!(writer, "{:08x}: ", i * cfg.width + skip + address_offset,)?;
|
||||
>>>>>>> 9259a56a28f1dd3a4b720ad815aa19c6eaf6adce
|
||||
}
|
||||
}
|
||||
for (i, x) in row.as_ref().iter().enumerate() {
|
||||
|
Reference in New Issue
Block a user