mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 08:01:07 +02:00
Restrict config.show_banner
to valid options (#15985)
This commit is contained in:
committed by
GitHub
parent
70aa7ad993
commit
cde8a629c5
@ -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(),
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user