summaryrefslogtreecommitdiffstats
path: root/src/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/handler.rs2
-rw-r--r--src/repl/highlighter.rs16
-rw-r--r--src/repl/init.rs2
-rw-r--r--src/repl/mod.rs1
-rw-r--r--src/repl/prompt.rs56
5 files changed, 12 insertions, 65 deletions
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index afe016a..94f91a1 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -97,7 +97,7 @@ impl ReplCmdHandler {
}
ReplCmd::SessionInfo => {
if let Some(session) = &self.config.read().session {
- let render_options = self.config.read().get_render_options();
+ let render_options = self.config.read().get_render_options()?;
let mut markdown_render = MarkdownRender::init(render_options)?;
print_now!("{}\n\n", session.render(&mut markdown_render)?);
} else {
diff --git a/src/repl/highlighter.rs b/src/repl/highlighter.rs
index 103d198..cca6297 100644
--- a/src/repl/highlighter.rs
+++ b/src/repl/highlighter.rs
@@ -3,16 +3,13 @@ use crate::config::SharedConfig;
use nu_ansi_term::{Color, Style};
use reedline::{Highlighter, StyledText};
-const MATCH_COLOR: Color = Color::Green;
-
pub struct ReplHighlighter {
external_commands: Vec<String>,
config: SharedConfig,
}
impl ReplHighlighter {
- /// Construct the default highlighter with a given set of extern commands/keywords to detect and highlight
- pub fn new(config: SharedConfig, external_commands: Vec<String>) -> Self {
+ pub fn new(external_commands: Vec<String>, config: SharedConfig) -> Self {
Self {
external_commands,
config,
@@ -22,18 +19,15 @@ impl ReplHighlighter {
impl Highlighter for ReplHighlighter {
fn highlight(&self, line: &str, _cursor: usize) -> StyledText {
- let mut styled_text = StyledText::new();
- let color = if self.config.read().light_theme {
- Color::Black
- } else {
- Color::White
- };
+ let color = Color::Default;
let match_color = if self.config.read().highlight {
- MATCH_COLOR
+ Color::Green
} else {
color
};
+ let mut styled_text = StyledText::new();
+
if self
.external_commands
.clone()
diff --git a/src/repl/init.rs b/src/repl/init.rs
index 420f596..fbbcf22 100644
--- a/src/repl/init.rs
+++ b/src/repl/init.rs
@@ -26,7 +26,7 @@ impl Repl {
.collect();
let completer = Self::create_completer(&config, &commands);
- let highlighter = ReplHighlighter::new(config.clone(), commands);
+ let highlighter = ReplHighlighter::new(commands, config.clone());
let menu = Self::create_menu();
let edit_mode: Box<dyn EditMode> = if config.read().keybindings.is_vi() {
let mut normal_keybindings = default_vi_normal_keybindings();
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 4cf59f7..eb99fda 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -123,7 +123,6 @@ impl Repl {
}
".set" => {
handler.handle(ReplCmd::Set(args.unwrap_or_default().to_string()))?;
- self.prompt.sync_config();
}
".copy" => {
handler.handle(ReplCmd::Copy)?;
diff --git a/src/repl/prompt.rs b/src/repl/prompt.rs
index afc4bee..c73e586 100644
--- a/src/repl/prompt.rs
+++ b/src/repl/prompt.rs
@@ -12,57 +12,11 @@ const PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5);
#[derive(Clone)]
pub struct ReplPrompt {
config: SharedConfig,
- prompt_color: Color,
- prompt_multiline_color: nu_ansi_term::Color,
- indicator_color: Color,
- prompt_right_color: Color,
}
impl ReplPrompt {
pub fn new(config: SharedConfig) -> Self {
- let (prompt_color, prompt_multiline_color, indicator_color, prompt_right_color) =
- Self::get_colors(&config);
- Self {
- config,
- prompt_color,
- prompt_multiline_color,
- indicator_color,
- prompt_right_color,
- }
- }
- pub fn sync_config(&mut self) {
- let (prompt_color, prompt_multiline_color, indicator_color, prompt_right_color) =
- 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) {
- let render_options = config.read().get_render_options();
- if render_options.highlight {
- (
- PROMPT_COLOR,
- PROMPT_MULTILINE_COLOR,
- INDICATOR_COLOR,
- PROMPT_RIGHT_COLOR,
- )
- } else if render_options.light_theme {
- (
- Color::Black,
- nu_ansi_term::Color::Black,
- Color::Black,
- Color::Black,
- )
- } else {
- (
- Color::White,
- nu_ansi_term::Color::White,
- Color::White,
- Color::White,
- )
- }
+ Self { config }
}
}
@@ -114,18 +68,18 @@ impl Prompt for ReplPrompt {
}
fn get_prompt_color(&self) -> Color {
- self.prompt_color
+ PROMPT_COLOR
}
/// Get the default multiline prompt color
fn get_prompt_multiline_color(&self) -> nu_ansi_term::Color {
- self.prompt_multiline_color
+ PROMPT_MULTILINE_COLOR
}
/// Get the default indicator color
fn get_indicator_color(&self) -> Color {
- self.indicator_color
+ INDICATOR_COLOR
}
/// Get the default right prompt color
fn get_prompt_right_color(&self) -> Color {
- self.prompt_right_color
+ PROMPT_RIGHT_COLOR
}
}