mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Move explore
command out of nu-command
deps (#9421)
# Description For better parallel compilation, make sure that `nu-command` doesn't depend on `nu-explore`. Moves the `nu_protocol::Command` implementation into `nu-explore`. Adds `nu_explore::add_explore_context()` which is used in `main.rs` to add the `explore` command. Minor improvement in compile time ~0.5 sec observed as `nu-command` still blocks on `nu-cmd-lang` as well. ## `cargo build --timings` before ![grafik](https://github.com/nushell/nushell/assets/15833959/583aa56e-6a1e-47b9-ba00-6a86293a38db) ## `cargo build --timings` after ![grafik](https://github.com/nushell/nushell/assets/15833959/30687575-c1c8-4635-bcdd-7ce9488fcfff) # User-Facing Changes None
This commit is contained in:
parent
2b181bf69c
commit
604aadc938
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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",
|
||||
|
@ -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" }
|
||||
|
@ -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" }
|
||||
|
@ -311,7 +311,6 @@ pub fn create_default_context() -> EngineState {
|
||||
bind_command! {
|
||||
Griddle,
|
||||
Table,
|
||||
Explore,
|
||||
};
|
||||
|
||||
// Conversions
|
||||
|
@ -1,8 +1,6 @@
|
||||
mod explore;
|
||||
mod griddle;
|
||||
mod icons;
|
||||
mod table;
|
||||
|
||||
pub use explore::Explore;
|
||||
pub use griddle::Griddle;
|
||||
pub use table::Table;
|
||||
|
17
crates/nu-explore/src/default_context.rs
Normal file
17
crates/nu-explore/src/default_context.rs
Normal file
@ -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
|
||||
}
|
@ -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;
|
@ -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<Page> {
|
||||
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);
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user