mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Use default prompt as fallback (#663)
This commit is contained in:
parent
857ecda050
commit
4d1ce6c27b
@ -1,3 +1,5 @@
|
||||
use reedline::DefaultPrompt;
|
||||
|
||||
use {
|
||||
reedline::{
|
||||
Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus, PromptViMode,
|
||||
@ -8,7 +10,7 @@ use {
|
||||
/// Nushell prompt definition
|
||||
#[derive(Clone)]
|
||||
pub struct NushellPrompt {
|
||||
prompt_string: String,
|
||||
prompt_string: Option<String>,
|
||||
default_prompt_indicator: String,
|
||||
default_vi_insert_prompt_indicator: String,
|
||||
default_vi_visual_prompt_indicator: String,
|
||||
@ -24,7 +26,7 @@ impl Default for NushellPrompt {
|
||||
impl NushellPrompt {
|
||||
pub fn new() -> NushellPrompt {
|
||||
NushellPrompt {
|
||||
prompt_string: "".to_string(),
|
||||
prompt_string: None,
|
||||
default_prompt_indicator: "〉".to_string(),
|
||||
default_vi_insert_prompt_indicator: ": ".to_string(),
|
||||
default_vi_visual_prompt_indicator: "v ".to_string(),
|
||||
@ -32,7 +34,7 @@ impl NushellPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_prompt(&mut self, prompt_string: String) {
|
||||
pub fn update_prompt(&mut self, prompt_string: Option<String>) {
|
||||
self.prompt_string = prompt_string;
|
||||
}
|
||||
|
||||
@ -54,7 +56,7 @@ impl NushellPrompt {
|
||||
|
||||
pub fn update_all_prompt_strings(
|
||||
&mut self,
|
||||
prompt_string: String,
|
||||
prompt_string: Option<String>,
|
||||
prompt_indicator_string: String,
|
||||
prompt_vi_insert_string: String,
|
||||
prompt_vi_visual_string: String,
|
||||
@ -73,8 +75,13 @@ impl NushellPrompt {
|
||||
}
|
||||
|
||||
impl Prompt for NushellPrompt {
|
||||
fn render_prompt(&self, _: usize) -> Cow<str> {
|
||||
self.prompt_string.as_str().into()
|
||||
fn render_prompt(&self, width: usize) -> Cow<str> {
|
||||
if let Some(prompt_string) = &self.prompt_string {
|
||||
prompt_string.into()
|
||||
} else {
|
||||
let default = DefaultPrompt::new(1);
|
||||
default.render_prompt(width).to_string().into()
|
||||
}
|
||||
}
|
||||
|
||||
fn render_prompt_indicator(&self, edit_mode: PromptEditMode) -> Cow<str> {
|
||||
|
10
src/main.rs
10
src/main.rs
@ -763,7 +763,7 @@ fn update_prompt<'prompt>(
|
||||
Err(_) => {
|
||||
// apply the other indicators
|
||||
nu_prompt.update_all_prompt_strings(
|
||||
String::new(),
|
||||
None,
|
||||
prompt_indicator_string,
|
||||
prompt_vi_insert_string,
|
||||
prompt_vi_visual_string,
|
||||
@ -775,7 +775,7 @@ fn update_prompt<'prompt>(
|
||||
None => {
|
||||
// apply the other indicators
|
||||
nu_prompt.update_all_prompt_strings(
|
||||
String::new(),
|
||||
None,
|
||||
prompt_indicator_string,
|
||||
prompt_vi_insert_string,
|
||||
prompt_vi_visual_string,
|
||||
@ -803,7 +803,7 @@ fn update_prompt<'prompt>(
|
||||
// If we can't run the custom prompt, give them the default
|
||||
// apply the other indicators
|
||||
nu_prompt.update_all_prompt_strings(
|
||||
String::new(),
|
||||
None,
|
||||
prompt_indicator_string,
|
||||
prompt_vi_insert_string,
|
||||
prompt_vi_visual_string,
|
||||
@ -816,7 +816,7 @@ fn update_prompt<'prompt>(
|
||||
match evaluated_prompt {
|
||||
Ok(evaluated_prompt) => {
|
||||
nu_prompt.update_all_prompt_strings(
|
||||
evaluated_prompt,
|
||||
Some(evaluated_prompt),
|
||||
prompt_indicator_string,
|
||||
prompt_vi_insert_string,
|
||||
prompt_vi_visual_string,
|
||||
@ -824,7 +824,7 @@ fn update_prompt<'prompt>(
|
||||
);
|
||||
}
|
||||
_ => nu_prompt.update_all_prompt_strings(
|
||||
String::new(),
|
||||
None,
|
||||
prompt_indicator_string,
|
||||
prompt_vi_insert_string,
|
||||
prompt_vi_visual_string,
|
||||
|
Loading…
Reference in New Issue
Block a user