Restrict config.show_banner to valid options (#15985)

This commit is contained in:
Stefan Holderbach
2025-06-18 10:49:40 +02:00
committed by GitHub
parent 70aa7ad993
commit cde8a629c5
4 changed files with 79 additions and 8 deletions

View File

@ -22,8 +22,8 @@ use nu_color_config::StyleComputer;
use nu_engine::env_to_strings;
use nu_engine::exit::cleanup_exit;
use nu_parser::{lex, parse, trim_quotes_str};
use nu_protocol::shell_error;
use nu_protocol::shell_error::io::IoError;
use nu_protocol::{BannerKind, shell_error};
use nu_protocol::{
HistoryConfig, HistoryFileFormat, PipelineData, ShellError, Span, Spanned, Value,
config::NuCursorShape,
@ -145,8 +145,8 @@ pub fn evaluate_repl(
if load_std_lib.is_none() {
match engine_state.get_config().show_banner {
Value::Bool { val: false, .. } => {}
Value::String { ref val, .. } if val == "short" => {
BannerKind::None => {}
BannerKind::Short => {
eval_source(
engine_state,
&mut unique_stack,
@ -156,7 +156,7 @@ pub fn evaluate_repl(
false,
);
}
_ => {
BannerKind::Full => {
eval_source(
engine_state,
&mut unique_stack,

View File

@ -17,7 +17,7 @@ pub use helper::extract_value;
pub use history::{HistoryConfig, HistoryFileFormat};
pub use hooks::Hooks;
pub use ls::LsConfig;
pub use output::ErrorStyle;
pub use output::{BannerKind, ErrorStyle};
pub use plugin_gc::{PluginGcConfig, PluginGcConfigs};
pub use reedline::{CursorShapeConfig, EditBindings, NuCursorShape, ParsedKeybinding, ParsedMenu};
pub use rm::RmConfig;
@ -61,7 +61,7 @@ pub struct Config {
pub rm: RmConfig,
pub shell_integration: ShellIntegrationConfig,
pub buffer_editor: Value,
pub show_banner: Value,
pub show_banner: BannerKind,
pub bracketed_paste: bool,
pub render_right_prompt_on_last_line: bool,
pub explore: HashMap<String, Value>,
@ -84,7 +84,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Config {
Config {
show_banner: Value::bool(true, Span::unknown()),
show_banner: BannerKind::default(),
table: TableConfig::default(),
rm: RmConfig::default(),

View File

@ -25,3 +25,71 @@ impl UpdateFromValue for ErrorStyle {
config_update_string_enum(self, value, path, errors)
}
}
/// Option: show_banner
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum BannerKind {
/// No banner on startup
None,
/// Abbreviated banner just containing the startup-time
Short,
/// The full banner including Ellie
#[default]
Full,
}
impl IntoValue for BannerKind {
fn into_value(self, span: Span) -> Value {
match self {
// This uses a custom implementation to reflect common config
// bool: true, false was used for a long time
// string: short was added later
BannerKind::None => Value::bool(false, span),
BannerKind::Short => Value::string("short", span),
BannerKind::Full => Value::bool(true, span),
}
}
}
impl UpdateFromValue for BannerKind {
fn update<'a>(
&mut self,
value: &'a Value,
path: &mut ConfigPath<'a>,
errors: &mut ConfigErrors,
) {
match value {
Value::Bool { val, .. } => match val {
true => {
*self = BannerKind::Full;
}
false => {
*self = BannerKind::None;
}
},
Value::String { val, .. } => match val.as_str() {
"true" => {
*self = BannerKind::Full;
}
"full" => {
*self = BannerKind::Full;
}
"short" => {
*self = BannerKind::Short;
}
"false" => {
*self = BannerKind::None;
}
"none" => {
*self = BannerKind::None;
}
_ => {
errors.invalid_value(path, "true/'full', 'short', false/'none'", value);
}
},
_ => {
errors.invalid_value(path, "true/'full', 'short', false/'none'", value);
}
}
}
}

View File

@ -70,7 +70,10 @@ $env.config.history.isolation = true
# Miscellaneous Settings
# ----------------------
# show_banner (bool): Enable or disable the welcome banner at startup
# show_banner (bool|string): Enable or disable the welcome banner at startup
# true | "full": show the full banner
# "short": just show the start-up time
# false | "none": don't show a banner
$env.config.show_banner = true
# rm.always_trash (bool):