explore: pass config to views at creation time (#13312)

cc: @zhiburt

This is an internal refactoring for `explore`.

Previously, views inside `explore` were created with default/incorrect
configuration and then the correct configuration was passed to them
using a function called `setup()`. I believe this was because
configuration was dynamic and could change while `explore` was running.

After https://github.com/nushell/nushell/pull/10259, configuration can
no longer be changed on the fly. So we can clean this up by removing
`setup()` and passing configuration to views when they are created.
This commit is contained in:
Reilly Wood
2024-07-07 06:09:59 -07:00
committed by GitHub
parent 6ce5530fc2
commit 83081f9852
13 changed files with 93 additions and 150 deletions

View File

@ -10,6 +10,7 @@ use anyhow::Result;
use commands::{ExpandCmd, HelpCmd, NuCmd, QuitCmd, TableCmd, TryCmd};
pub use default_context::add_explore_context;
pub use explore::Explore;
use explore::ExploreConfig;
use nu_common::{collect_pipeline, has_simple_value, CtrlC};
use nu_protocol::{
engine::{EngineState, Stack},
@ -43,7 +44,7 @@ fn run_pager(
if is_binary {
p.show_message("For help type :help");
let view = binary_view(input)?;
let view = binary_view(input, config.explore_config)?;
return p.run(engine_state, stack, ctrlc, Some(view), commands);
}
@ -73,7 +74,7 @@ fn create_record_view(
is_record: bool,
config: PagerConfig,
) -> Option<Page> {
let mut view = RecordView::new(columns, data);
let mut view = RecordView::new(columns, data, config.explore_config.clone());
if is_record {
view.set_top_layer_orientation(Orientation::Left);
}
@ -91,14 +92,14 @@ fn help_view() -> Option<Page> {
Some(Page::new(HelpCmd::view(), false))
}
fn binary_view(input: PipelineData) -> Result<Page> {
fn binary_view(input: PipelineData, config: &ExploreConfig) -> 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);
let view = BinaryView::new(data, config);
Ok(Page::new(view, true))
}