mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:24:58 +02:00
Add pretty binary viewing
This commit is contained in:
@ -6,7 +6,7 @@ use crate::prelude::*;
|
||||
pub fn autoview(args: SinkCommandArgs) -> Result<(), ShellError> {
|
||||
if args.input.len() > 0 {
|
||||
if let Value::Binary(_) = args.input[0] {
|
||||
println!("Binary");
|
||||
args.ctx.get_sink("binaryview").run(args)?;
|
||||
} else if equal_shapes(&args.input) {
|
||||
args.ctx.get_sink("table").run(args)?;
|
||||
} else {
|
||||
|
46
src/plugins/binaryview.rs
Normal file
46
src/plugins/binaryview.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use indexmap::IndexMap;
|
||||
use nu::{serve_plugin, Args, CommandConfig, Plugin, Primitive, ShellError, Value};
|
||||
|
||||
struct BinaryView;
|
||||
|
||||
impl BinaryView {
|
||||
fn new() -> BinaryView {
|
||||
BinaryView
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for BinaryView {
|
||||
fn config(&mut self) -> Result<CommandConfig, ShellError> {
|
||||
Ok(CommandConfig {
|
||||
name: "binaryview".to_string(),
|
||||
mandatory_positional: vec![],
|
||||
optional_positional: vec![],
|
||||
can_load: vec![],
|
||||
can_save: vec![],
|
||||
is_filter: false,
|
||||
is_sink: true,
|
||||
named: IndexMap::new(),
|
||||
rest_positional: true,
|
||||
})
|
||||
}
|
||||
|
||||
fn sink(&mut self, _args: Args, input: Vec<Value>) {
|
||||
for v in input {
|
||||
match v {
|
||||
Value::Binary(b) => {
|
||||
view_binary(&b);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view_binary(b: &[u8]) {
|
||||
use pretty_hex::*;
|
||||
println!("{:?}", b.hex_dump());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
serve_plugin(&mut BinaryView::new());
|
||||
}
|
Reference in New Issue
Block a user