mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
nu-explore/ Use hex-dump for binary data (#12184)
Hi there So as 2 minute thing we could show `hex-dump` as it is as a string (no-coloring). But I'd do some more things around,. Probably will take a few days (WIP). ``` ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ─────────────────────────────────────────────────────────────────────────────────────┬───────────────────────────────────────────────────────────── 00000000: 6d 6f 64 20 63 6f 6d 6d 61 6e 64 3b 0a 6d 6f 64 mod command;_mod │ 00000010: 20 63 6f 6e 66 69 67 5f 66 69 6c 65 73 3b 0a 6d config_files;_m │ 00000020: 6f 64 20 69 64 65 3b 0a 6d 6f 64 20 6c 6f 67 67 od ide;_mod logg │ 00000030: 65 72 3b 0a 6d 6f 64 20 72 75 6e 3b 0a 6d 6f 64 er;_mod run;_mod │ 00000040: 20 73 69 67 6e 61 6c 73 3b 0a 23 5b 63 66 67 28 signals;_#[cfg( │ 00000050: 75 6e 69 78 29 5d 0a 6d 6f 64 20 74 65 72 6d 69 unix)]_mod termi │ 00000060: 6e 61 6c 3b 0a 6d 6f 64 20 74 65 73 74 5f 62 69 nal;_mod test_bi │ 00000070: 6e 73 3b 0a 23 5b 63 66 67 28 74 65 73 74 29 5d ns;_#[cfg(test)] │ 00000080: 0a 6d 6f 64 20 74 65 73 74 73 3b 0a 0a 23 5b 63 _mod tests;__#[c │ 00000090: 66 67 28 66 65 61 74 75 72 65 20 3d 20 22 6d 69 fg(feature = "mi │ 000000a0: 6d 61 6c 6c 6f 63 22 29 5d 0a 23 5b 67 6c 6f 62 malloc")]_#[glob │ 000000b0: 61 6c 5f 61 6c 6c 6f 63 61 74 6f 72 5d 0a 73 74 al_allocator]_st │ 000000c0: 61 74 69 63 20 47 4c 4f 42 41 4c 3a 20 6d 69 6d atic GLOBAL: mim │ 000000d0: 61 6c 6c 6f 63 3a 3a 4d 69 4d 61 6c 6c 6f 63 20 alloc::MiMalloc │ 000000e0: 3d 20 6d 69 6d 61 6c 6c 6f 63 3a 3a 4d 69 4d 61 = mimalloc::MiMa │ 000000f0: 6c 6c 6f 63 3b 0a 0a 75 73 65 20 63 72 61 74 65 lloc;__use crate │ 00000100: 3a 3a 7b 0a 20 20 20 20 63 6f 6d 6d 61 6e 64 3a ::{_ command: │ 00000110: 3a 70 61 72 73 65 5f 63 6f 6d 6d 61 6e 64 6c 69 :parse_commandli │ 00000120: 6e 65 5f 61 72 67 73 2c 0a 20 20 20 20 63 6f 6e ne_args,_ con │ 00000130: 66 69 67 5f 66 69 6c 65 73 3a 3a 73 65 74 5f 63 fig_files::set_c │ 00000140: 6f 6e 66 69 67 5f 70 61 74 68 2c 0a 20 20 20 20 onfig_path,_ │ 00000150: 6c 6f 67 67 65 72 3a 3a 7b 63 6f 6e 66 69 67 75 logger::{configu │ 00000160: 72 65 2c 20 6c 6f 67 67 65 72 7d 2c 0a 7d 3b 0a re, logger},_};_ │ 00000170: 75 73 65 20 63 6f 6d 6d 61 6e 64 3a 3a 67 61 74 use command::gat │ 00000180: 68 65 72 5f 63 6f 6d 6d 61 6e 64 6c 69 6e 65 5f her_commandline_ │ 00000190: 61 72 67 73 3b 0a 75 73 65 20 6c 6f 67 3a 3a 4c args;_use log::L │ 000001a0: 65 76 65 6c 3b 0a 75 73 65 20 6d 69 65 74 74 65 evel;_use miette │ 000001b0: 3a 3a 52 65 73 75 6c 74 3b 0a 75 73 65 20 6e 75 ::Result;_use nu │ 000001c0: 5f 63 6c 69 3a 3a 67 61 74 68 65 72 5f 70 61 72 _cli::gather_par │ ``` ref: #12157 cc: @fdncred @lrdickson
This commit is contained in:
@ -20,7 +20,7 @@ use nu_protocol::{
|
||||
use pager::{Page, Pager};
|
||||
use registry::{Command, CommandRegistry};
|
||||
use terminal_size::{Height, Width};
|
||||
use views::{InformationView, Orientation, Preview, RecordView};
|
||||
use views::{BinaryView, InformationView, Orientation, Preview, RecordView};
|
||||
|
||||
use pager::{PagerConfig, StyleConfig};
|
||||
|
||||
@ -36,11 +36,19 @@ fn run_pager(
|
||||
config: PagerConfig,
|
||||
) -> io::Result<Option<Value>> {
|
||||
let mut p = Pager::new(config.clone());
|
||||
let commands = create_command_registry();
|
||||
|
||||
let is_record = matches!(input, PipelineData::Value(Value::Record { .. }, ..));
|
||||
let (columns, data) = collect_pipeline(input);
|
||||
let is_binary = matches!(input, PipelineData::Value(Value::Binary { .. }, ..));
|
||||
|
||||
let commands = create_command_registry();
|
||||
if is_binary {
|
||||
p.show_message("For help type :help");
|
||||
|
||||
let view = binary_view(input);
|
||||
return p.run(engine_state, stack, ctrlc, view, commands);
|
||||
}
|
||||
|
||||
let (columns, data) = collect_pipeline(input);
|
||||
|
||||
let has_no_input = columns.is_empty() && data.is_empty();
|
||||
if has_no_input {
|
||||
@ -83,6 +91,17 @@ fn information_view() -> Option<Page> {
|
||||
Some(Page::new(InformationView, true))
|
||||
}
|
||||
|
||||
fn binary_view(input: PipelineData) -> Option<Page> {
|
||||
let data = match input {
|
||||
PipelineData::Value(Value::Binary { val, .. }, _) => val,
|
||||
_ => unreachable!("checked beforehand"),
|
||||
};
|
||||
|
||||
let view = BinaryView::new(data);
|
||||
|
||||
Some(Page::new(view, false))
|
||||
}
|
||||
|
||||
fn create_command_registry() -> CommandRegistry {
|
||||
let mut registry = CommandRegistry::new();
|
||||
create_commands(&mut registry);
|
||||
|
Reference in New Issue
Block a user