mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:55:40 +02:00
Restrict config.show_banner
to valid options (#15985)
This commit is contained in:
committed by
GitHub
parent
70aa7ad993
commit
cde8a629c5
@ -22,8 +22,8 @@ use nu_color_config::StyleComputer;
|
|||||||
use nu_engine::env_to_strings;
|
use nu_engine::env_to_strings;
|
||||||
use nu_engine::exit::cleanup_exit;
|
use nu_engine::exit::cleanup_exit;
|
||||||
use nu_parser::{lex, parse, trim_quotes_str};
|
use nu_parser::{lex, parse, trim_quotes_str};
|
||||||
use nu_protocol::shell_error;
|
|
||||||
use nu_protocol::shell_error::io::IoError;
|
use nu_protocol::shell_error::io::IoError;
|
||||||
|
use nu_protocol::{BannerKind, shell_error};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
HistoryConfig, HistoryFileFormat, PipelineData, ShellError, Span, Spanned, Value,
|
HistoryConfig, HistoryFileFormat, PipelineData, ShellError, Span, Spanned, Value,
|
||||||
config::NuCursorShape,
|
config::NuCursorShape,
|
||||||
@ -145,8 +145,8 @@ pub fn evaluate_repl(
|
|||||||
|
|
||||||
if load_std_lib.is_none() {
|
if load_std_lib.is_none() {
|
||||||
match engine_state.get_config().show_banner {
|
match engine_state.get_config().show_banner {
|
||||||
Value::Bool { val: false, .. } => {}
|
BannerKind::None => {}
|
||||||
Value::String { ref val, .. } if val == "short" => {
|
BannerKind::Short => {
|
||||||
eval_source(
|
eval_source(
|
||||||
engine_state,
|
engine_state,
|
||||||
&mut unique_stack,
|
&mut unique_stack,
|
||||||
@ -156,7 +156,7 @@ pub fn evaluate_repl(
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
BannerKind::Full => {
|
||||||
eval_source(
|
eval_source(
|
||||||
engine_state,
|
engine_state,
|
||||||
&mut unique_stack,
|
&mut unique_stack,
|
||||||
|
@ -17,7 +17,7 @@ pub use helper::extract_value;
|
|||||||
pub use history::{HistoryConfig, HistoryFileFormat};
|
pub use history::{HistoryConfig, HistoryFileFormat};
|
||||||
pub use hooks::Hooks;
|
pub use hooks::Hooks;
|
||||||
pub use ls::LsConfig;
|
pub use ls::LsConfig;
|
||||||
pub use output::ErrorStyle;
|
pub use output::{BannerKind, ErrorStyle};
|
||||||
pub use plugin_gc::{PluginGcConfig, PluginGcConfigs};
|
pub use plugin_gc::{PluginGcConfig, PluginGcConfigs};
|
||||||
pub use reedline::{CursorShapeConfig, EditBindings, NuCursorShape, ParsedKeybinding, ParsedMenu};
|
pub use reedline::{CursorShapeConfig, EditBindings, NuCursorShape, ParsedKeybinding, ParsedMenu};
|
||||||
pub use rm::RmConfig;
|
pub use rm::RmConfig;
|
||||||
@ -61,7 +61,7 @@ pub struct Config {
|
|||||||
pub rm: RmConfig,
|
pub rm: RmConfig,
|
||||||
pub shell_integration: ShellIntegrationConfig,
|
pub shell_integration: ShellIntegrationConfig,
|
||||||
pub buffer_editor: Value,
|
pub buffer_editor: Value,
|
||||||
pub show_banner: Value,
|
pub show_banner: BannerKind,
|
||||||
pub bracketed_paste: bool,
|
pub bracketed_paste: bool,
|
||||||
pub render_right_prompt_on_last_line: bool,
|
pub render_right_prompt_on_last_line: bool,
|
||||||
pub explore: HashMap<String, Value>,
|
pub explore: HashMap<String, Value>,
|
||||||
@ -84,7 +84,7 @@ pub struct Config {
|
|||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config {
|
||||||
show_banner: Value::bool(true, Span::unknown()),
|
show_banner: BannerKind::default(),
|
||||||
|
|
||||||
table: TableConfig::default(),
|
table: TableConfig::default(),
|
||||||
rm: RmConfig::default(),
|
rm: RmConfig::default(),
|
||||||
|
@ -25,3 +25,71 @@ impl UpdateFromValue for ErrorStyle {
|
|||||||
config_update_string_enum(self, value, path, errors)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -70,7 +70,10 @@ $env.config.history.isolation = true
|
|||||||
# Miscellaneous Settings
|
# 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
|
$env.config.show_banner = true
|
||||||
|
|
||||||
# rm.always_trash (bool):
|
# rm.always_trash (bool):
|
||||||
|
Reference in New Issue
Block a user