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:
Reilly Wood
2024-05-20 13:03:21 -07:00
committed by GitHub
parent 905e3d0715
commit 6e050f5634
6 changed files with 98 additions and 142 deletions

View File

@@ -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 {