diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 168ee78027..df704fe369 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -354,6 +354,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState { ConfigFlatten, ConfigMeta, ConfigReset, + ConfigUseColors, }; // Math diff --git a/crates/nu-command/src/env/config/config_use_colors.rs b/crates/nu-command/src/env/config/config_use_colors.rs new file mode 100644 index 0000000000..28537535ee --- /dev/null +++ b/crates/nu-command/src/env/config/config_use_colors.rs @@ -0,0 +1,41 @@ +use nu_engine::command_prelude::*; + +#[derive(Clone)] +pub struct ConfigUseColors; + +impl Command for ConfigUseColors { + fn name(&self) -> &str { + "config use-colors" + } + + fn signature(&self) -> Signature { + Signature::build(self.name()) + .category(Category::Env) + .input_output_type(Type::Nothing, Type::Bool) + } + + fn description(&self) -> &str { + "Get the configuration for color output." + } + + fn extra_description(&self) -> &str { + r#"Use this command instead of checking `$env.config.use_ansi_coloring` to properly handle the "auto" setting, including environment variables that influence its behavior."# + } + + fn run( + &self, + engine_state: &EngineState, + _stack: &mut Stack, + call: &Call, + _input: PipelineData, + ) -> Result { + let use_ansi_coloring = engine_state + .get_config() + .use_ansi_coloring + .get(engine_state); + Ok(PipelineData::Value( + Value::bool(use_ansi_coloring, call.head), + None, + )) + } +} diff --git a/crates/nu-command/src/env/config/mod.rs b/crates/nu-command/src/env/config/mod.rs index d596eb57b9..2981aff313 100644 --- a/crates/nu-command/src/env/config/mod.rs +++ b/crates/nu-command/src/env/config/mod.rs @@ -3,9 +3,11 @@ mod config_env; mod config_flatten; mod config_nu; mod config_reset; +mod config_use_colors; pub use config_::ConfigMeta; pub use config_env::ConfigEnv; pub use config_flatten::ConfigFlatten; pub use config_nu::ConfigNu; pub use config_reset::ConfigReset; +pub use config_use_colors::ConfigUseColors; diff --git a/crates/nu-command/src/env/mod.rs b/crates/nu-command/src/env/mod.rs index 3f9312ed13..62a9e4d116 100644 --- a/crates/nu-command/src/env/mod.rs +++ b/crates/nu-command/src/env/mod.rs @@ -9,6 +9,7 @@ pub use config::ConfigFlatten; pub use config::ConfigMeta; pub use config::ConfigNu; pub use config::ConfigReset; +pub use config::ConfigUseColors; pub use export_env::ExportEnv; pub use load_env::LoadEnv; pub use source_env::SourceEnv;