diff --git a/Cargo.lock b/Cargo.lock index ba50f5fb37..551113bbed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2656,6 +2656,7 @@ dependencies = [ "nu-color-config", "nu-command", "nu-engine", + "nu-explore", "nu-json", "nu-parser", "nu-path", @@ -2829,7 +2830,6 @@ dependencies = [ "nu-cmd-lang", "nu-color-config", "nu-engine", - "nu-explore", "nu-glob", "nu-json", "nu-parser", diff --git a/Cargo.toml b/Cargo.toml index 0414144b6a..af2cc72bbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ nu-cmd-lang = { path = "./crates/nu-cmd-lang", version = "0.81.1" } nu-cmd-dataframe = { path = "./crates/nu-cmd-dataframe", version = "0.81.1", optional = true } nu-command = { path = "./crates/nu-command", version = "0.81.1" } nu-engine = { path = "./crates/nu-engine", version = "0.81.1" } +nu-explore = { path = "./crates/nu-explore", version = "0.81.1" } nu-json = { path = "./crates/nu-json", version = "0.81.1" } nu-parser = { path = "./crates/nu-parser", version = "0.81.1" } nu-path = { path = "./crates/nu-path", version = "0.81.1" } diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index d73dcf77f5..b93570dd00 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -18,7 +18,6 @@ nu-cmd-dataframe = { path = "../nu-cmd-dataframe", version = "0.81.1", optional nu-cmd-extra = { path = "../nu-cmd-extra", version = "0.81.1", optional = true } nu-color-config = { path = "../nu-color-config", version = "0.81.1" } nu-engine = { path = "../nu-engine", version = "0.81.1" } -nu-explore = { path = "../nu-explore", version = "0.81.1" } nu-glob = { path = "../nu-glob", version = "0.81.1" } nu-json = { path = "../nu-json", version = "0.81.1" } nu-parser = { path = "../nu-parser", version = "0.81.1" } diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index fbed3b3ffc..a1bed28e32 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -311,7 +311,6 @@ pub fn create_default_context() -> EngineState { bind_command! { Griddle, Table, - Explore, }; // Conversions diff --git a/crates/nu-command/src/viewers/mod.rs b/crates/nu-command/src/viewers/mod.rs index d48de600f2..6aa301e190 100644 --- a/crates/nu-command/src/viewers/mod.rs +++ b/crates/nu-command/src/viewers/mod.rs @@ -1,8 +1,6 @@ -mod explore; mod griddle; mod icons; mod table; -pub use explore::Explore; pub use griddle::Griddle; pub use table::Table; diff --git a/crates/nu-explore/src/default_context.rs b/crates/nu-explore/src/default_context.rs new file mode 100644 index 0000000000..4d80375a25 --- /dev/null +++ b/crates/nu-explore/src/default_context.rs @@ -0,0 +1,17 @@ +use nu_protocol::engine::{EngineState, StateWorkingSet}; + +use crate::explore::*; + +pub fn add_explore_context(mut engine_state: EngineState) -> EngineState { + let delta = { + let mut working_set = StateWorkingSet::new(&engine_state); + working_set.add_decl(Box::new(Explore)); + working_set.render() + }; + + if let Err(err) = engine_state.merge_delta(delta) { + eprintln!("Error creating explore command context: {err:?}"); + } + + engine_state +} diff --git a/crates/nu-command/src/viewers/explore.rs b/crates/nu-explore/src/explore.rs similarity index 98% rename from crates/nu-command/src/viewers/explore.rs rename to crates/nu-explore/src/explore.rs index d637a5e3b5..eb76cd9222 100644 --- a/crates/nu-command/src/viewers/explore.rs +++ b/crates/nu-explore/src/explore.rs @@ -1,12 +1,12 @@ +use crate::{ + run_pager, + util::{create_lscolors, create_map, map_into_value}, + PagerConfig, StyleConfig, +}; use ahash::HashMap; use nu_ansi_term::{Color, Style}; use nu_color_config::{get_color_map, StyleComputer}; use nu_engine::CallExt; -use nu_explore::{ - run_pager, - util::{create_map, map_into_value}, - PagerConfig, StyleConfig, -}; use nu_protocol::{ ast::Call, engine::{Command, EngineState, Stack}, @@ -82,7 +82,7 @@ impl Command for Explore { let style = style_from_config(&config); - let lscolors = nu_explore::util::create_lscolors(engine_state, stack); + let lscolors = create_lscolors(engine_state, stack); let mut config = PagerConfig::new(nu_config, &style_computer, &lscolors, config); config.style = style; diff --git a/crates/nu-explore/src/lib.rs b/crates/nu-explore/src/lib.rs index bf4890ce55..9ef32746da 100644 --- a/crates/nu-explore/src/lib.rs +++ b/crates/nu-explore/src/lib.rs @@ -1,9 +1,14 @@ mod commands; +mod default_context; +mod explore; mod nu_common; mod pager; mod registry; mod views; +pub use default_context::add_explore_context; +pub use explore::Explore; + use std::io; use commands::{ @@ -20,13 +25,13 @@ use registry::{Command, CommandRegistry}; use terminal_size::{Height, Width}; use views::{InformationView, Orientation, Preview, RecordView}; -pub use pager::{PagerConfig, StyleConfig}; +use pager::{PagerConfig, StyleConfig}; -pub mod util { +mod util { pub use super::nu_common::{create_lscolors, create_map, map_into_value}; } -pub fn run_pager( +fn run_pager( engine_state: &EngineState, stack: &mut Stack, ctrlc: CtrlC, @@ -83,7 +88,7 @@ fn information_view() -> Option { Some(Page::new(InformationView, true)) } -pub fn create_command_registry() -> CommandRegistry { +fn create_command_registry() -> CommandRegistry { let mut registry = CommandRegistry::new(); create_commands(&mut registry); create_aliases(&mut registry); @@ -101,7 +106,7 @@ pub fn create_command_registry() -> CommandRegistry { registry } -pub fn create_commands(registry: &mut CommandRegistry) { +fn create_commands(registry: &mut CommandRegistry) { registry.register_command_view(NuCmd::new(), false); registry.register_command_view(TableCmd::new(), false); @@ -115,7 +120,7 @@ pub fn create_commands(registry: &mut CommandRegistry) { registry.register_command_reactive(TweakCmd::default()); } -pub fn create_aliases(registry: &mut CommandRegistry) { +fn create_aliases(registry: &mut CommandRegistry) { registry.create_aliases("h", HelpCmd::NAME); registry.create_aliases("e", ExpandCmd::NAME); registry.create_aliases("q", QuitCmd::NAME); diff --git a/src/main.rs b/src/main.rs index 88878fc776..aae9617fdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,8 @@ fn main() -> Result<()> { // Get initial current working directory. let init_cwd = get_init_cwd(); - let mut engine_state = nu_cli::add_cli_context(create_default_context()); + let mut engine_state = + nu_explore::add_explore_context(nu_cli::add_cli_context(create_default_context())); // Custom additions let delta = {