mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 04:00:25 +02:00
explore
: consolidate padding config, handle ByteStream, tweak naming+comments (#12915)
Some minor changes to `explore`, continuing on my mission to simplify the command in preparation for a larger UX overhaul: 1. Consolidate padding configuration. I don't think we need separate config points for the (optional) index column and regular data columns in the normal pager, they can share padding configuration. Likewise, in the binary viewer all 3 columns (index, data, ASCII) had their left+right padding configured independently. 2. Update `explore` so we use the binary viewer for the new `ByteStream` type. `cat foo.txt | into binary | explore` was not using the binary viewer after the `ByteStream` changes. 3. Tweak the naming of a few helper functions, add a comment I've put the changes in separate commits to make them easier to review. --------- Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
@@ -35,13 +35,16 @@ fn run_pager(
|
||||
let commands = create_command_registry();
|
||||
|
||||
let is_record = matches!(input, PipelineData::Value(Value::Record { .. }, ..));
|
||||
let is_binary = matches!(input, PipelineData::Value(Value::Binary { .. }, ..));
|
||||
let is_binary = matches!(
|
||||
input,
|
||||
PipelineData::Value(Value::Binary { .. }, ..) | PipelineData::ByteStream(..)
|
||||
);
|
||||
|
||||
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 view = binary_view(input)?;
|
||||
return p.run(engine_state, stack, ctrlc, Some(view), commands);
|
||||
}
|
||||
|
||||
let (columns, data) = collect_pipeline(input)?;
|
||||
@@ -88,15 +91,16 @@ fn help_view() -> Option<Page> {
|
||||
Some(Page::new(HelpCmd::view(), false))
|
||||
}
|
||||
|
||||
fn binary_view(input: PipelineData) -> Option<Page> {
|
||||
fn binary_view(input: PipelineData) -> Result<Page> {
|
||||
let data = match input {
|
||||
PipelineData::Value(Value::Binary { val, .. }, _) => val,
|
||||
PipelineData::ByteStream(bs, _) => bs.into_bytes()?,
|
||||
_ => unreachable!("checked beforehand"),
|
||||
};
|
||||
|
||||
let view = BinaryView::new(data);
|
||||
|
||||
Some(Page::new(view, true))
|
||||
Ok(Page::new(view, true))
|
||||
}
|
||||
|
||||
fn create_command_registry() -> CommandRegistry {
|
||||
|
Reference in New Issue
Block a user