mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
using menu trait (#861)
This commit is contained in:
@ -14,10 +14,8 @@ pub struct NushellPrompt {
|
||||
right_prompt_string: Option<String>,
|
||||
default_prompt_indicator: String,
|
||||
default_vi_insert_prompt_indicator: String,
|
||||
default_vi_visual_prompt_indicator: String,
|
||||
default_menu_prompt_indicator: String,
|
||||
default_vi_normal_prompt_indicator: String,
|
||||
default_multiline_indicator: String,
|
||||
default_history_prompt_indicator: String,
|
||||
}
|
||||
|
||||
impl Default for NushellPrompt {
|
||||
@ -33,10 +31,8 @@ impl NushellPrompt {
|
||||
right_prompt_string: None,
|
||||
default_prompt_indicator: "〉".to_string(),
|
||||
default_vi_insert_prompt_indicator: ": ".to_string(),
|
||||
default_vi_visual_prompt_indicator: "v ".to_string(),
|
||||
default_menu_prompt_indicator: "| ".to_string(),
|
||||
default_vi_normal_prompt_indicator: "〉".to_string(),
|
||||
default_multiline_indicator: "::: ".to_string(),
|
||||
default_history_prompt_indicator: "? ".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,8 +52,8 @@ impl NushellPrompt {
|
||||
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
|
||||
}
|
||||
|
||||
pub fn update_prompt_vi_visual(&mut self, prompt_vi_visual_string: String) {
|
||||
self.default_vi_visual_prompt_indicator = prompt_vi_visual_string;
|
||||
pub fn update_prompt_vi_normal(&mut self, prompt_vi_normal_string: String) {
|
||||
self.default_vi_normal_prompt_indicator = prompt_vi_normal_string;
|
||||
}
|
||||
|
||||
pub fn update_prompt_multiline(&mut self, prompt_multiline_indicator_string: String) {
|
||||
@ -71,20 +67,15 @@ impl NushellPrompt {
|
||||
prompt_indicator_string: String,
|
||||
prompt_multiline_indicator_string: String,
|
||||
prompt_vi: (String, String),
|
||||
prompt_menus: (String, String),
|
||||
) {
|
||||
let (prompt_vi_insert_string, prompt_vi_visual_string) = prompt_vi;
|
||||
let (prompt_indicator_menu, prompt_history_indicator_menu) = prompt_menus;
|
||||
let (prompt_vi_insert_string, prompt_vi_normal_string) = prompt_vi;
|
||||
|
||||
self.left_prompt_string = left_prompt_string;
|
||||
self.right_prompt_string = right_prompt_string;
|
||||
self.default_prompt_indicator = prompt_indicator_string;
|
||||
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
|
||||
self.default_vi_visual_prompt_indicator = prompt_vi_visual_string;
|
||||
self.default_vi_normal_prompt_indicator = prompt_vi_normal_string;
|
||||
self.default_multiline_indicator = prompt_multiline_indicator_string;
|
||||
|
||||
self.default_menu_prompt_indicator = prompt_indicator_menu;
|
||||
self.default_history_prompt_indicator = prompt_history_indicator_menu;
|
||||
}
|
||||
|
||||
fn default_wrapped_custom_string(&self, str: String) -> String {
|
||||
@ -95,19 +86,27 @@ impl NushellPrompt {
|
||||
impl Prompt for NushellPrompt {
|
||||
fn render_prompt_left(&self) -> Cow<str> {
|
||||
if let Some(prompt_string) = &self.left_prompt_string {
|
||||
prompt_string.into()
|
||||
prompt_string.replace("\n", "\r\n").into()
|
||||
} else {
|
||||
let default = DefaultPrompt::new();
|
||||
default.render_prompt_left().to_string().into()
|
||||
default
|
||||
.render_prompt_left()
|
||||
.to_string()
|
||||
.replace("\n", "\r\n")
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn render_prompt_right(&self) -> Cow<str> {
|
||||
if let Some(prompt_string) = &self.right_prompt_string {
|
||||
prompt_string.into()
|
||||
prompt_string.replace("\n", "\r\n").into()
|
||||
} else {
|
||||
let default = DefaultPrompt::new();
|
||||
default.render_prompt_right().to_string().into()
|
||||
default
|
||||
.render_prompt_right()
|
||||
.to_string()
|
||||
.replace("\n", "\r\n")
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,13 +115,10 @@ impl Prompt for NushellPrompt {
|
||||
PromptEditMode::Default => self.default_prompt_indicator.as_str().into(),
|
||||
PromptEditMode::Emacs => self.default_prompt_indicator.as_str().into(),
|
||||
PromptEditMode::Vi(vi_mode) => match vi_mode {
|
||||
PromptViMode::Normal => self.default_prompt_indicator.as_str().into(),
|
||||
PromptViMode::Normal => self.default_vi_normal_prompt_indicator.as_str().into(),
|
||||
PromptViMode::Insert => self.default_vi_insert_prompt_indicator.as_str().into(),
|
||||
PromptViMode::Visual => self.default_vi_visual_prompt_indicator.as_str().into(),
|
||||
},
|
||||
PromptEditMode::Custom(str) => self.default_wrapped_custom_string(str).into(),
|
||||
PromptEditMode::Menu => self.default_menu_prompt_indicator.as_str().into(),
|
||||
PromptEditMode::HistoryMenu => self.default_history_prompt_indicator.as_str().into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user