From 5e6f91fe6976509656d1a15d195e71ddddb26ab8 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Fri, 21 Jun 2024 23:43:58 +0200 Subject: [PATCH 1/9] Add struct Theme --- src/engine.rs | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 6b323c1e..256f8039 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -132,15 +132,12 @@ pub struct Reedline { // Highlight the edit buffer highlighter: Box, - // Style used for visual selection - visual_selection_style: Style, - // Showcase hints based on various strategies (history, language-completion, spellcheck, etc) hinter: Option>, hide_hints: bool, // Use ansi coloring or not - use_ansi_coloring: bool, + theme: Theme, // Engine Menus menus: Vec, @@ -182,6 +179,20 @@ impl Drop for Reedline { } } +struct Theme { + visual_selection: Style, + use_ansi_coloring: bool, +} + +impl Default for Theme { + fn default() -> Self { + Self { + visual_selection: Style::new().on(Color::LightGray), + use_ansi_coloring: true, + } + } +} + impl Reedline { const FILTERED_ITEM_ID: HistoryItemId = HistoryItemId(i64::MAX); @@ -191,7 +202,6 @@ impl Reedline { let history = Box::::default(); let painter = Painter::new(std::io::BufWriter::new(std::io::stderr())); let buffer_highlighter = Box::::default(); - let visual_selection_style = Style::new().on(Color::LightGray); let completer = Box::::default(); let hinter = None; let validator = None; @@ -219,11 +229,10 @@ impl Reedline { quick_completions: false, partial_completions: false, highlighter: buffer_highlighter, - visual_selection_style, hinter, hide_hints: false, validator, - use_ansi_coloring: true, + theme: Theme::default(), menus: Vec::new(), buffer_editor: None, cursor_shapes: None, @@ -356,7 +365,7 @@ impl Reedline { /// and in the command line syntax highlighting. #[must_use] pub fn with_ansi_colors(mut self, use_ansi_coloring: bool) -> Self { - self.use_ansi_coloring = use_ansi_coloring; + self.theme.use_ansi_coloring = use_ansi_coloring; self } @@ -385,7 +394,7 @@ impl Reedline { /// A builder that configures the style used for visual selection #[must_use] pub fn with_visual_selection_style(mut self, style: Style) -> Self { - self.visual_selection_style = style; + self.theme.visual_selection = style; self } @@ -1682,7 +1691,7 @@ impl Reedline { let res_string = self.history_cursor.string_at_cursor().unwrap_or_default(); // Highlight matches - let res_string = if self.use_ansi_coloring { + let res_string = if self.theme.use_ansi_coloring { let match_highlighter = SimpleMatchHighlighter::new(substring); let styled = match_highlighter.highlight(&res_string, 0); styled.render_simple() @@ -1704,7 +1713,7 @@ impl Reedline { &lines, self.prompt_edit_mode(), None, - self.use_ansi_coloring, + self.theme.use_ansi_coloring, &self.cursor_shapes, )?; } @@ -1723,13 +1732,13 @@ impl Reedline { .highlighter .highlight(buffer_to_paint, cursor_position_in_buffer); if let Some((from, to)) = self.editor.get_selection() { - styled_text.style_range(from, to, self.visual_selection_style); + styled_text.style_range(from, to, self.theme.visual_selection); } let (before_cursor, after_cursor) = styled_text.render_around_insertion_point( cursor_position_in_buffer, prompt, - self.use_ansi_coloring, + self.theme.use_ansi_coloring, ); let hint: String = if self.hints_active() { @@ -1738,7 +1747,7 @@ impl Reedline { buffer_to_paint, cursor_position_in_buffer, self.history.as_ref(), - self.use_ansi_coloring, + self.theme.use_ansi_coloring, ) }) } else { @@ -1781,7 +1790,7 @@ impl Reedline { &lines, self.prompt_edit_mode(), menu, - self.use_ansi_coloring, + self.theme.use_ansi_coloring, &self.cursor_shapes, ) } From 8a458d60fc86c802c5e3af608e6b71117d4a7b15 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sat, 22 Jun 2024 01:18:53 +0200 Subject: [PATCH 2/9] Add prompt colors to Theme --- src/engine.rs | 28 ++++++++++++++++------- src/painting/painter.rs | 44 ++++++++++++++++++------------------- src/painting/styled_text.rs | 8 +++---- src/prompt/base.rs | 22 ------------------- 4 files changed, 46 insertions(+), 56 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 256f8039..6d9b066a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use itertools::Itertools; -use nu_ansi_term::{Color, Style}; +use nu_ansi_term::Style; use crate::{enums::ReedlineRawEvent, CursorConfig}; #[cfg(feature = "bashisms")] @@ -39,6 +39,7 @@ use { cursor::{SetCursorStyle, Show}, event, event::{Event, KeyCode, KeyEvent, KeyModifiers}, + style::Color, terminal, QueueableCommand, }, std::{ @@ -179,16 +180,27 @@ impl Drop for Reedline { } } -struct Theme { - visual_selection: Style, - use_ansi_coloring: bool, + +pub struct Theme { + pub visual_selection: Style, + pub use_ansi_coloring: bool, + /// The color for the prompt, indicator, and right prompt + pub prompt: Color, + pub prompt_multiline: nu_ansi_term::Color, + pub indicator: Color, + pub prompt_right: Color, + } impl Default for Theme { fn default() -> Self { Self { - visual_selection: Style::new().on(Color::LightGray), + visual_selection: Style::new().on(nu_ansi_term::Color::LightGray), use_ansi_coloring: true, + prompt: Color::Green, + prompt_multiline: nu_ansi_term::Color::LightBlue, + indicator: Color::Cyan, + prompt_right: Color::AnsiValue(5), } } } @@ -1713,7 +1725,7 @@ impl Reedline { &lines, self.prompt_edit_mode(), None, - self.theme.use_ansi_coloring, + &self.theme, &self.cursor_shapes, )?; } @@ -1738,7 +1750,7 @@ impl Reedline { let (before_cursor, after_cursor) = styled_text.render_around_insertion_point( cursor_position_in_buffer, prompt, - self.theme.use_ansi_coloring, + &self.theme, ); let hint: String = if self.hints_active() { @@ -1790,7 +1802,7 @@ impl Reedline { &lines, self.prompt_edit_mode(), menu, - self.theme.use_ansi_coloring, + &self.theme, &self.cursor_shapes, ) } diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 233e98f8..3309e4cd 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -1,4 +1,4 @@ -use crate::{CursorConfig, PromptEditMode, PromptViMode}; +use crate::{CursorConfig, PromptEditMode, PromptViMode, engine::Theme}; use { super::utils::{coerce_crlf, line_width}, @@ -189,7 +189,7 @@ impl Painter { lines: &PromptLines, prompt_mode: PromptEditMode, menu: Option<&ReedlineMenu>, - use_ansi_coloring: bool, + theme: &Theme, cursor_config: &Option, ) -> Result<()> { self.stdout.queue(cursor::Hide)?; @@ -229,9 +229,9 @@ impl Painter { .queue(Clear(ClearType::FromCursorDown))?; if self.large_buffer { - self.print_large_buffer(prompt, lines, menu, use_ansi_coloring)?; + self.print_large_buffer(prompt, lines, menu, theme)?; } else { - self.print_small_buffer(prompt, lines, menu, use_ansi_coloring)?; + self.print_small_buffer(prompt, lines, menu, theme)?; } // The last_required_lines is used to calculate safe range of the current prompt. @@ -318,33 +318,33 @@ impl Painter { prompt: &dyn Prompt, lines: &PromptLines, menu: Option<&ReedlineMenu>, - use_ansi_coloring: bool, + theme: &Theme, ) -> Result<()> { // print our prompt with color - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_prompt_color()))?; + .queue(SetForegroundColor(theme.prompt))?; } self.stdout .queue(Print(&coerce_crlf(&lines.prompt_str_left)))?; - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_indicator_color()))?; + .queue(SetForegroundColor(theme.indicator))?; } self.stdout .queue(Print(&coerce_crlf(&lines.prompt_indicator)))?; - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_prompt_right_color()))?; + .queue(SetForegroundColor(theme.prompt_right))?; } self.print_right_prompt(lines)?; - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout .queue(SetAttribute(Attribute::Reset))? .queue(ResetColor)?; @@ -356,7 +356,7 @@ impl Painter { .queue(Print(&lines.after_cursor))?; if let Some(menu) = menu { - self.print_menu(menu, lines, use_ansi_coloring)?; + self.print_menu(menu, lines, theme.use_ansi_coloring)?; } else { self.stdout.queue(Print(&lines.hint))?; } @@ -369,7 +369,7 @@ impl Painter { prompt: &dyn Prompt, lines: &PromptLines, menu: Option<&ReedlineMenu>, - use_ansi_coloring: bool, + theme: &Theme, ) -> Result<()> { let screen_width = self.screen_width(); let screen_height = self.screen_height(); @@ -389,9 +389,9 @@ impl Painter { let extra_rows = (total_lines_before).saturating_sub(screen_height as usize); // print our prompt with color - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_prompt_color()))?; + .queue(SetForegroundColor(theme.prompt))?; } // In case the prompt is made out of multiple lines, the prompt is split by @@ -400,9 +400,9 @@ impl Painter { self.stdout.queue(Print(&coerce_crlf(prompt_skipped)))?; if extra_rows == 0 { - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_prompt_right_color()))?; + .queue(SetForegroundColor(theme.prompt_right))?; } self.print_right_prompt(lines)?; @@ -411,14 +411,14 @@ impl Painter { // Adjusting extra_rows base on the calculated prompt line size let extra_rows = extra_rows.saturating_sub(prompt_lines); - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout - .queue(SetForegroundColor(prompt.get_indicator_color()))?; + .queue(SetForegroundColor(theme.indicator))?; } let indicator_skipped = skip_buffer_lines(&lines.prompt_indicator, extra_rows, None); self.stdout.queue(Print(&coerce_crlf(indicator_skipped)))?; - if use_ansi_coloring { + if theme.use_ansi_coloring { self.stdout.queue(ResetColor)?; } @@ -453,7 +453,7 @@ impl Painter { } else { self.stdout.queue(Print(&lines.after_cursor))?; } - self.print_menu(menu, lines, use_ansi_coloring)?; + self.print_menu(menu, lines, theme.use_ansi_coloring)?; } else { // Selecting lines for the hint // The -1 subtraction is done because the remaining lines consider the line where the diff --git a/src/painting/styled_text.rs b/src/painting/styled_text.rs index 82560def..feb3fda5 100644 --- a/src/painting/styled_text.rs +++ b/src/painting/styled_text.rs @@ -1,6 +1,6 @@ use nu_ansi_term::Style; -use crate::Prompt; +use crate::{Prompt, engine::Theme}; use super::utils::strip_ansi; @@ -101,14 +101,14 @@ impl StyledText { insertion_point: usize, prompt: &dyn Prompt, // multiline_prompt: &str, - use_ansi_coloring: bool, + theme: &Theme, ) -> (String, String) { let mut current_idx = 0; let mut left_string = String::new(); let mut right_string = String::new(); let multiline_prompt = prompt.render_prompt_multiline_indicator(); - let prompt_style = Style::new().fg(prompt.get_prompt_multiline_color()); + let prompt_style = Style::new().fg(theme.prompt_multiline); for pair in &self.buffer { if current_idx >= insertion_point { @@ -135,7 +135,7 @@ impl StyledText { current_idx += pair.1.len(); } - if use_ansi_coloring { + if theme.use_ansi_coloring { (left_string, right_string) } else { (strip_ansi(&left_string), strip_ansi(&right_string)) diff --git a/src/prompt/base.rs b/src/prompt/base.rs index db69f2e0..412e8b0f 100644 --- a/src/prompt/base.rs +++ b/src/prompt/base.rs @@ -8,12 +8,6 @@ use { strum_macros::EnumIter, }; -/// The default color for the prompt, indicator, and right prompt -pub static DEFAULT_PROMPT_COLOR: Color = Color::Green; -pub static DEFAULT_PROMPT_MULTILINE_COLOR: nu_ansi_term::Color = nu_ansi_term::Color::LightBlue; -pub static DEFAULT_INDICATOR_COLOR: Color = Color::Cyan; -pub static DEFAULT_PROMPT_RIGHT_COLOR: Color = Color::AnsiValue(5); - /// The current success/failure of the history search pub enum PromptHistorySearchStatus { /// Success for the search @@ -97,22 +91,6 @@ pub trait Prompt: Send { &self, history_search: PromptHistorySearch, ) -> Cow; - /// Get the default prompt color - fn get_prompt_color(&self) -> Color { - DEFAULT_PROMPT_COLOR - } - /// Get the default multiline prompt color - fn get_prompt_multiline_color(&self) -> nu_ansi_term::Color { - DEFAULT_PROMPT_MULTILINE_COLOR - } - /// Get the default indicator color - fn get_indicator_color(&self) -> Color { - DEFAULT_INDICATOR_COLOR - } - /// Get the default right prompt color - fn get_prompt_right_color(&self) -> Color { - DEFAULT_PROMPT_RIGHT_COLOR - } /// Whether to render right prompt on the last line fn right_prompt_on_last_line(&self) -> bool { From 7843c9879c3ea3bc29ea1e139d36ef4daf09099c Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sat, 22 Jun 2024 01:25:31 +0200 Subject: [PATCH 3/9] Fixed warnings --- src/engine.rs | 2 -- src/painting/painter.rs | 8 ++------ src/prompt/base.rs | 1 - 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 6d9b066a..1d6d31c2 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1721,7 +1721,6 @@ impl Reedline { ); self.painter.repaint_buffer( - prompt, &lines, self.prompt_edit_mode(), None, @@ -1798,7 +1797,6 @@ impl Reedline { let menu = self.menus.iter().find(|menu| menu.is_active()); self.painter.repaint_buffer( - prompt, &lines, self.prompt_edit_mode(), menu, diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 3309e4cd..1fe2e44e 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -5,7 +5,6 @@ use { crate::{ menu::{Menu, ReedlineMenu}, painting::PromptLines, - Prompt, }, crossterm::{ cursor::{self, MoveTo, RestorePosition, SavePosition}, @@ -185,7 +184,6 @@ impl Painter { /// the screen. pub(crate) fn repaint_buffer( &mut self, - prompt: &dyn Prompt, lines: &PromptLines, prompt_mode: PromptEditMode, menu: Option<&ReedlineMenu>, @@ -229,9 +227,9 @@ impl Painter { .queue(Clear(ClearType::FromCursorDown))?; if self.large_buffer { - self.print_large_buffer(prompt, lines, menu, theme)?; + self.print_large_buffer(lines, menu, theme)?; } else { - self.print_small_buffer(prompt, lines, menu, theme)?; + self.print_small_buffer(lines, menu, theme)?; } // The last_required_lines is used to calculate safe range of the current prompt. @@ -315,7 +313,6 @@ impl Painter { fn print_small_buffer( &mut self, - prompt: &dyn Prompt, lines: &PromptLines, menu: Option<&ReedlineMenu>, theme: &Theme, @@ -366,7 +363,6 @@ impl Painter { fn print_large_buffer( &mut self, - prompt: &dyn Prompt, lines: &PromptLines, menu: Option<&ReedlineMenu>, theme: &Theme, diff --git a/src/prompt/base.rs b/src/prompt/base.rs index 412e8b0f..285e2ade 100644 --- a/src/prompt/base.rs +++ b/src/prompt/base.rs @@ -1,5 +1,4 @@ use { - crossterm::style::Color, serde::{Deserialize, Serialize}, std::{ borrow::Cow, From 681d056ee5cc2584c3501bcc008343e80f9369a8 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 23 Jun 2024 11:47:59 +0200 Subject: [PATCH 4/9] Make visual selection more readable --- src/engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 1d6d31c2..96a890b4 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -195,7 +195,7 @@ pub struct Theme { impl Default for Theme { fn default() -> Self { Self { - visual_selection: Style::new().on(nu_ansi_term::Color::LightGray), + visual_selection: Style::new().fg(nu_ansi_term::Color::Black).on(nu_ansi_term::Color::LightGray), use_ansi_coloring: true, prompt: Color::Green, prompt_multiline: nu_ansi_term::Color::LightBlue, From 47aa9f3dd81102460b400c7f40de0facc83adaf6 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 23 Jun 2024 11:53:32 +0200 Subject: [PATCH 5/9] Run `cargo fmt --all` --- src/engine.rs | 6 +++--- src/painting/painter.rs | 20 +++++++------------- src/painting/styled_text.rs | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 96a890b4..be986dda 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -180,7 +180,6 @@ impl Drop for Reedline { } } - pub struct Theme { pub visual_selection: Style, pub use_ansi_coloring: bool, @@ -189,13 +188,14 @@ pub struct Theme { pub prompt_multiline: nu_ansi_term::Color, pub indicator: Color, pub prompt_right: Color, - } impl Default for Theme { fn default() -> Self { Self { - visual_selection: Style::new().fg(nu_ansi_term::Color::Black).on(nu_ansi_term::Color::LightGray), + visual_selection: Style::new() + .fg(nu_ansi_term::Color::Black) + .on(nu_ansi_term::Color::LightGray), use_ansi_coloring: true, prompt: Color::Green, prompt_multiline: nu_ansi_term::Color::LightBlue, diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 1fe2e44e..8c89986b 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -1,4 +1,4 @@ -use crate::{CursorConfig, PromptEditMode, PromptViMode, engine::Theme}; +use crate::{engine::Theme, CursorConfig, PromptEditMode, PromptViMode}; use { super::utils::{coerce_crlf, line_width}, @@ -319,24 +319,21 @@ impl Painter { ) -> Result<()> { // print our prompt with color if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.prompt))?; + self.stdout.queue(SetForegroundColor(theme.prompt))?; } self.stdout .queue(Print(&coerce_crlf(&lines.prompt_str_left)))?; if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.indicator))?; + self.stdout.queue(SetForegroundColor(theme.indicator))?; } self.stdout .queue(Print(&coerce_crlf(&lines.prompt_indicator)))?; if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.prompt_right))?; + self.stdout.queue(SetForegroundColor(theme.prompt_right))?; } self.print_right_prompt(lines)?; @@ -386,8 +383,7 @@ impl Painter { // print our prompt with color if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.prompt))?; + self.stdout.queue(SetForegroundColor(theme.prompt))?; } // In case the prompt is made out of multiple lines, the prompt is split by @@ -397,8 +393,7 @@ impl Painter { if extra_rows == 0 { if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.prompt_right))?; + self.stdout.queue(SetForegroundColor(theme.prompt_right))?; } self.print_right_prompt(lines)?; @@ -408,8 +403,7 @@ impl Painter { let extra_rows = extra_rows.saturating_sub(prompt_lines); if theme.use_ansi_coloring { - self.stdout - .queue(SetForegroundColor(theme.indicator))?; + self.stdout.queue(SetForegroundColor(theme.indicator))?; } let indicator_skipped = skip_buffer_lines(&lines.prompt_indicator, extra_rows, None); self.stdout.queue(Print(&coerce_crlf(indicator_skipped)))?; diff --git a/src/painting/styled_text.rs b/src/painting/styled_text.rs index feb3fda5..95af4c06 100644 --- a/src/painting/styled_text.rs +++ b/src/painting/styled_text.rs @@ -1,6 +1,6 @@ use nu_ansi_term::Style; -use crate::{Prompt, engine::Theme}; +use crate::{engine::Theme, Prompt}; use super::utils::strip_ansi; From 89192ec23763b158942ad354d950882a0d691667 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 23 Jun 2024 16:01:33 +0200 Subject: [PATCH 6/9] Fixed CI missing use Prompt --- src/painting/painter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/painting/painter.rs b/src/painting/painter.rs index 8c89986b..fc046687 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -16,7 +16,7 @@ use { std::ops::RangeInclusive, }; #[cfg(feature = "external_printer")] -use {crate::LineBuffer, crossterm::cursor::MoveUp}; +use {crate::LineBuffer, crate::Prompt, crossterm::cursor::MoveUp}; // Returns a string that skips N number of lines with the next offset of lines // An offset of 0 would return only one line after skipping the required lines From 8127858c2a00919f832eb6afdcc5b8f0e0d047f9 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 23 Jun 2024 21:53:58 +0200 Subject: [PATCH 7/9] Rename Theme ReedlineTheme --- src/engine.rs | 8 ++++---- src/painting/painter.rs | 8 ++++---- src/painting/styled_text.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index be986dda..27d6c902 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -138,7 +138,7 @@ pub struct Reedline { hide_hints: bool, // Use ansi coloring or not - theme: Theme, + theme: ReedlineTheme, // Engine Menus menus: Vec, @@ -180,7 +180,7 @@ impl Drop for Reedline { } } -pub struct Theme { +pub struct ReedlineTheme { pub visual_selection: Style, pub use_ansi_coloring: bool, /// The color for the prompt, indicator, and right prompt @@ -190,7 +190,7 @@ pub struct Theme { pub prompt_right: Color, } -impl Default for Theme { +impl Default for ReedlineTheme { fn default() -> Self { Self { visual_selection: Style::new() @@ -244,7 +244,7 @@ impl Reedline { hinter, hide_hints: false, validator, - theme: Theme::default(), + theme: ReedlineTheme::default(), menus: Vec::new(), buffer_editor: None, cursor_shapes: None, diff --git a/src/painting/painter.rs b/src/painting/painter.rs index fc046687..f9c600a7 100644 --- a/src/painting/painter.rs +++ b/src/painting/painter.rs @@ -1,4 +1,4 @@ -use crate::{engine::Theme, CursorConfig, PromptEditMode, PromptViMode}; +use crate::{engine::ReedlineTheme, CursorConfig, PromptEditMode, PromptViMode}; use { super::utils::{coerce_crlf, line_width}, @@ -187,7 +187,7 @@ impl Painter { lines: &PromptLines, prompt_mode: PromptEditMode, menu: Option<&ReedlineMenu>, - theme: &Theme, + theme: &ReedlineTheme, cursor_config: &Option, ) -> Result<()> { self.stdout.queue(cursor::Hide)?; @@ -315,7 +315,7 @@ impl Painter { &mut self, lines: &PromptLines, menu: Option<&ReedlineMenu>, - theme: &Theme, + theme: &ReedlineTheme, ) -> Result<()> { // print our prompt with color if theme.use_ansi_coloring { @@ -362,7 +362,7 @@ impl Painter { &mut self, lines: &PromptLines, menu: Option<&ReedlineMenu>, - theme: &Theme, + theme: &ReedlineTheme, ) -> Result<()> { let screen_width = self.screen_width(); let screen_height = self.screen_height(); diff --git a/src/painting/styled_text.rs b/src/painting/styled_text.rs index 95af4c06..020db30f 100644 --- a/src/painting/styled_text.rs +++ b/src/painting/styled_text.rs @@ -1,6 +1,6 @@ use nu_ansi_term::Style; -use crate::{engine::Theme, Prompt}; +use crate::{engine::ReedlineTheme, Prompt}; use super::utils::strip_ansi; @@ -101,7 +101,7 @@ impl StyledText { insertion_point: usize, prompt: &dyn Prompt, // multiline_prompt: &str, - theme: &Theme, + theme: &ReedlineTheme, ) -> (String, String) { let mut current_idx = 0; let mut left_string = String::new(); From f1411cfddf8947c4a4b6f6d665dea2e27a89f447 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 7 Jul 2024 11:27:30 +0200 Subject: [PATCH 8/9] Add builder methods for the prompt colors --- src/engine.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/engine.rs b/src/engine.rs index 3c8c34d2..20bb8062 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -386,6 +386,34 @@ impl Reedline { self } + /// A builder which sets the color to use for the prompt. + #[must_use] + pub fn with_prompt_color(mut self, color: Color) -> Self { + self.theme.prompt = color; + self + } + + /// A builder which sets the color to use for the multiline prompt. + #[must_use] + pub fn with_prompt_multiline_color(mut self, color: nu_ansi_term::Color) -> Self { + self.theme.prompt_multiline = color; + self + } + + /// A builder which sets the indicator color to use for the prompt. + #[must_use] + pub fn with_indicator_color(mut self, color: Color) -> Self { + self.theme.indicator = color; + self + } + + + /// A builder which sets the color to use for the right side of the prompt. + #[must_use] + pub fn with_prompt_right_color(mut self, color: Color) -> Self { + self.theme.prompt_right = color; + self + } /// Update current working directory. #[must_use] pub fn with_cwd(mut self, cwd: Option) -> Self { From 5502fcd632bb2f280fd3b2b7ae8b272e17deef05 Mon Sep 17 00:00:00 2001 From: Adam Schmalhofer Date: Sun, 7 Jul 2024 11:35:15 +0200 Subject: [PATCH 9/9] `cargo fmt --all` fix --- src/engine.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine.rs b/src/engine.rs index 20bb8062..172b9e1f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -407,7 +407,6 @@ impl Reedline { self } - /// A builder which sets the color to use for the right side of the prompt. #[must_use] pub fn with_prompt_right_color(mut self, color: Color) -> Self {