From 97fc7de6754c8b5c383d7d5e3f9e26b3bbfb08fb Mon Sep 17 00:00:00 2001 From: Anthony Rubick <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Sun, 9 Jul 2023 20:07:09 -0700 Subject: fix: minor code cleanup and pedantic lints (#134) --- src/repl/prompt.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/repl/prompt.rs') diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs index 8c670f4..c9fa005 100644 --- a/src/repl/prompt.rs +++ b/src/repl/prompt.rs @@ -9,6 +9,7 @@ const PROMPT_MULTILINE_COLOR: nu_ansi_term::Color = nu_ansi_term::Color::LightBl const INDICATOR_COLOR: Color = Color::Cyan; const PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5); +#[allow(clippy::module_name_repetitions)] #[derive(Clone)] pub struct ReplPrompt { config: SharedConfig, @@ -21,7 +22,7 @@ pub struct ReplPrompt { impl ReplPrompt { pub fn new(config: SharedConfig) -> Self { let (prompt_color, prompt_multiline_color, indicator_color, prompt_right_color) = - Self::get_colors(config.clone()); + Self::get_colors(&config); Self { config, prompt_color, @@ -32,14 +33,14 @@ impl ReplPrompt { } pub fn sync_config(&mut self) { let (prompt_color, prompt_multiline_color, indicator_color, prompt_right_color) = - Self::get_colors(self.config.clone()); + Self::get_colors(&self.config); self.prompt_color = prompt_color; self.prompt_multiline_color = prompt_multiline_color; self.indicator_color = indicator_color; self.prompt_right_color = prompt_right_color; } - pub fn get_colors(config: SharedConfig) -> (Color, nu_ansi_term::Color, Color, Color) { + pub fn get_colors(config: &SharedConfig) -> (Color, nu_ansi_term::Color, Color, Color) { let (highlight, light_theme) = config.read().get_render_options(); if highlight { ( @@ -68,11 +69,11 @@ impl ReplPrompt { impl Prompt for ReplPrompt { fn render_prompt_left(&self) -> Cow { - if let Some(role) = self.config.read().role.as_ref() { - role.name.to_string().into() - } else { - Cow::Borrowed("") - } + self.config + .read() + .role + .as_ref() + .map_or(Cow::Borrowed(""), |role| Cow::Owned(role.name.clone())) } fn render_prompt_right(&self) -> Cow { -- cgit v1.2.3