From 652b51509d461d2121e94304d6f00e714ebd0f9f Mon Sep 17 00:00:00 2001 From: sigoden Date: Thu, 2 Nov 2023 15:33:22 +0800 Subject: refactor: improve repl completer (#199) --- src/repl/highlighter.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/repl/highlighter.rs') diff --git a/src/repl/highlighter.rs b/src/repl/highlighter.rs index 37df659..7d3c197 100644 --- a/src/repl/highlighter.rs +++ b/src/repl/highlighter.rs @@ -1,18 +1,18 @@ +use super::REPL_COMMANDS; + use crate::config::GlobalConfig; use nu_ansi_term::{Color, Style}; use reedline::{Highlighter, StyledText}; pub struct ReplHighlighter { - external_commands: Vec, config: GlobalConfig, } impl ReplHighlighter { - pub fn new(external_commands: Vec, config: GlobalConfig) -> Self { + pub fn new(config: &GlobalConfig) -> Self { Self { - external_commands, - config, + config: config.clone(), } } } @@ -28,17 +28,11 @@ impl Highlighter for ReplHighlighter { let mut styled_text = StyledText::new(); - if self - .external_commands - .clone() - .iter() - .any(|x| line.contains(x)) - { - let matches: Vec<&str> = self - .external_commands + if REPL_COMMANDS.iter().any(|(cmd, _)| line.contains(cmd)) { + let matches: Vec<&str> = REPL_COMMANDS .iter() - .filter(|c| line.contains(*c)) - .map(std::ops::Deref::deref) + .filter(|(cmd, _)| line.contains(*cmd)) + .map(|(cmd, _)| *cmd) .collect(); let longest_match = matches.iter().fold(String::new(), |acc, &item| { if item.len() > acc.len() { -- cgit v1.2.3