2022-07-11 23:01:49 +02:00
|
|
|
#[cfg(windows)]
|
|
|
|
use nu_utils::enable_vt_processing;
|
2022-01-04 20:49:04 +01:00
|
|
|
use reedline::DefaultPrompt;
|
2021-10-02 15:10:28 +02:00
|
|
|
use {
|
|
|
|
reedline::{
|
|
|
|
Prompt, PromptEditMode, PromptHistorySearch, PromptHistorySearchStatus, PromptViMode,
|
|
|
|
},
|
|
|
|
std::borrow::Cow,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Nushell prompt definition
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct NushellPrompt {
|
2022-01-06 13:57:55 +01:00
|
|
|
left_prompt_string: Option<String>,
|
|
|
|
right_prompt_string: Option<String>,
|
2022-03-31 07:22:55 +02:00
|
|
|
default_prompt_indicator: Option<String>,
|
|
|
|
default_vi_insert_prompt_indicator: Option<String>,
|
|
|
|
default_vi_normal_prompt_indicator: Option<String>,
|
|
|
|
default_multiline_indicator: Option<String>,
|
2022-10-23 16:18:26 +02:00
|
|
|
render_right_prompt_on_last_line: bool,
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for NushellPrompt {
|
|
|
|
fn default() -> Self {
|
|
|
|
NushellPrompt::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NushellPrompt {
|
|
|
|
pub fn new() -> NushellPrompt {
|
|
|
|
NushellPrompt {
|
2022-01-06 13:57:55 +01:00
|
|
|
left_prompt_string: None,
|
|
|
|
right_prompt_string: None,
|
2022-03-31 07:22:55 +02:00
|
|
|
default_prompt_indicator: None,
|
|
|
|
default_vi_insert_prompt_indicator: None,
|
|
|
|
default_vi_normal_prompt_indicator: None,
|
|
|
|
default_multiline_indicator: None,
|
2022-10-23 16:18:26 +02:00
|
|
|
render_right_prompt_on_last_line: false,
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 13:57:55 +01:00
|
|
|
pub fn update_prompt_left(&mut self, prompt_string: Option<String>) {
|
|
|
|
self.left_prompt_string = prompt_string;
|
|
|
|
}
|
|
|
|
|
2022-10-23 16:18:26 +02:00
|
|
|
pub fn update_prompt_right(
|
|
|
|
&mut self,
|
|
|
|
prompt_string: Option<String>,
|
|
|
|
render_right_prompt_on_last_line: bool,
|
|
|
|
) {
|
2022-01-06 13:57:55 +01:00
|
|
|
self.right_prompt_string = prompt_string;
|
2022-10-23 16:18:26 +02:00
|
|
|
self.render_right_prompt_on_last_line = render_right_prompt_on_last_line;
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:55 +02:00
|
|
|
pub fn update_prompt_indicator(&mut self, prompt_indicator_string: Option<String>) {
|
2022-01-01 23:53:16 +01:00
|
|
|
self.default_prompt_indicator = prompt_indicator_string;
|
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:55 +02:00
|
|
|
pub fn update_prompt_vi_insert(&mut self, prompt_vi_insert_string: Option<String>) {
|
2022-01-01 23:53:16 +01:00
|
|
|
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
|
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:55 +02:00
|
|
|
pub fn update_prompt_vi_normal(&mut self, prompt_vi_normal_string: Option<String>) {
|
2022-01-27 08:53:23 +01:00
|
|
|
self.default_vi_normal_prompt_indicator = prompt_vi_normal_string;
|
2022-01-01 23:53:16 +01:00
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:55 +02:00
|
|
|
pub fn update_prompt_multiline(&mut self, prompt_multiline_indicator_string: Option<String>) {
|
2022-01-01 23:53:16 +01:00
|
|
|
self.default_multiline_indicator = prompt_multiline_indicator_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_all_prompt_strings(
|
|
|
|
&mut self,
|
2022-01-06 13:57:55 +01:00
|
|
|
left_prompt_string: Option<String>,
|
|
|
|
right_prompt_string: Option<String>,
|
2022-03-31 07:22:55 +02:00
|
|
|
prompt_indicator_string: Option<String>,
|
|
|
|
prompt_multiline_indicator_string: Option<String>,
|
|
|
|
prompt_vi: (Option<String>, Option<String>),
|
2022-10-23 16:18:26 +02:00
|
|
|
render_right_prompt_on_last_line: bool,
|
2022-01-01 23:53:16 +01:00
|
|
|
) {
|
2022-01-27 08:53:23 +01:00
|
|
|
let (prompt_vi_insert_string, prompt_vi_normal_string) = prompt_vi;
|
2022-01-21 09:59:29 +01:00
|
|
|
|
2022-01-06 13:57:55 +01:00
|
|
|
self.left_prompt_string = left_prompt_string;
|
|
|
|
self.right_prompt_string = right_prompt_string;
|
2022-01-01 23:53:16 +01:00
|
|
|
self.default_prompt_indicator = prompt_indicator_string;
|
2022-03-31 07:22:55 +02:00
|
|
|
self.default_multiline_indicator = prompt_multiline_indicator_string;
|
|
|
|
|
2022-01-01 23:53:16 +01:00
|
|
|
self.default_vi_insert_prompt_indicator = prompt_vi_insert_string;
|
2022-01-27 08:53:23 +01:00
|
|
|
self.default_vi_normal_prompt_indicator = prompt_vi_normal_string;
|
2022-10-23 16:18:26 +02:00
|
|
|
|
|
|
|
self.render_right_prompt_on_last_line = render_right_prompt_on_last_line;
|
2022-01-01 23:53:16 +01:00
|
|
|
}
|
|
|
|
|
2021-10-02 15:10:28 +02:00
|
|
|
fn default_wrapped_custom_string(&self, str: String) -> String {
|
2023-01-30 02:37:54 +01:00
|
|
|
format!("({str})")
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Prompt for NushellPrompt {
|
2022-01-06 13:57:55 +01:00
|
|
|
fn render_prompt_left(&self) -> Cow<str> {
|
2022-07-11 23:01:49 +02:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
let _ = enable_vt_processing();
|
|
|
|
}
|
|
|
|
|
2022-05-10 23:33:18 +02:00
|
|
|
if let Some(prompt_string) = &self.left_prompt_string {
|
|
|
|
prompt_string.replace('\n', "\r\n").into()
|
2022-01-06 13:57:55 +01:00
|
|
|
} else {
|
2023-01-13 21:37:39 +01:00
|
|
|
let default = DefaultPrompt::default();
|
2023-05-08 20:00:44 +02:00
|
|
|
let prompt = default
|
2022-05-10 23:33:18 +02:00
|
|
|
.render_prompt_left()
|
|
|
|
.to_string()
|
|
|
|
.replace('\n', "\r\n")
|
2023-05-08 20:00:44 +02:00
|
|
|
+ " ";
|
|
|
|
|
|
|
|
prompt.into()
|
2022-05-10 23:33:18 +02:00
|
|
|
}
|
2022-01-06 13:57:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn render_prompt_right(&self) -> Cow<str> {
|
|
|
|
if let Some(prompt_string) = &self.right_prompt_string {
|
2022-02-24 20:02:28 +01:00
|
|
|
prompt_string.replace('\n', "\r\n").into()
|
2022-01-04 20:49:04 +01:00
|
|
|
} else {
|
2023-01-13 21:37:39 +01:00
|
|
|
let default = DefaultPrompt::default();
|
2022-01-27 08:53:23 +01:00
|
|
|
default
|
|
|
|
.render_prompt_right()
|
|
|
|
.to_string()
|
2022-02-24 20:02:28 +01:00
|
|
|
.replace('\n', "\r\n")
|
2022-01-27 08:53:23 +01:00
|
|
|
.into()
|
2022-01-04 20:49:04 +01:00
|
|
|
}
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn render_prompt_indicator(&self, edit_mode: PromptEditMode) -> Cow<str> {
|
|
|
|
match edit_mode {
|
2022-03-31 07:22:55 +02:00
|
|
|
PromptEditMode::Default => match &self.default_prompt_indicator {
|
2023-01-21 14:47:00 +01:00
|
|
|
Some(indicator) => indicator,
|
Make the default prompt play nice with basic fonts (#8080)
# Description
This commit changes the `PROMPT_INDICATOR` and
`PROMPT_INDICATOR_VI_NORMAL` in the default_env and sample_login files.
It also changes its missing fallback in the prompt.rs file.
This has the intention of making the default prompt friendlier when
dealing with basic terminals that may not support displaying a huge
range of the Unicode standard, or users who don't want to get out of
their way to install custom fonts for their terminals. It's also
nicer/more balanced on the eyes, to me, and brings it in line with the
logo of nushell `nu>`.
# User-Facing Changes
New installations of nushell will have > as the default prompt
indicator, and running `config reset` will also change it. This might be
confusing for a few seconds, it could be minor enough that it just feels
slightly off. Anyone who has, for some reason, unset the
PROMPT_INDICATOR variable, or set it to $nothing, will also receive the
`>` treatment.
Users running on basic terminals (like cmd.exe on Windows 10) should no
longer face font issues with the default basic prompt.
# Drawbacks
The Unicode arrow is pretty cool. And it predates many of us. Maybe it's
worth keeping. One argument I could see, and mildly disagree with, is
that it might make users lean towards installing a modern font for their
terminal which will would have good consequences in the future.
2023-03-02 01:59:32 +01:00
|
|
|
None => "> ",
|
2023-01-21 14:47:00 +01:00
|
|
|
}
|
|
|
|
.into(),
|
2022-03-31 07:22:55 +02:00
|
|
|
PromptEditMode::Emacs => match &self.default_prompt_indicator {
|
2023-01-21 14:47:00 +01:00
|
|
|
Some(indicator) => indicator,
|
Make the default prompt play nice with basic fonts (#8080)
# Description
This commit changes the `PROMPT_INDICATOR` and
`PROMPT_INDICATOR_VI_NORMAL` in the default_env and sample_login files.
It also changes its missing fallback in the prompt.rs file.
This has the intention of making the default prompt friendlier when
dealing with basic terminals that may not support displaying a huge
range of the Unicode standard, or users who don't want to get out of
their way to install custom fonts for their terminals. It's also
nicer/more balanced on the eyes, to me, and brings it in line with the
logo of nushell `nu>`.
# User-Facing Changes
New installations of nushell will have > as the default prompt
indicator, and running `config reset` will also change it. This might be
confusing for a few seconds, it could be minor enough that it just feels
slightly off. Anyone who has, for some reason, unset the
PROMPT_INDICATOR variable, or set it to $nothing, will also receive the
`>` treatment.
Users running on basic terminals (like cmd.exe on Windows 10) should no
longer face font issues with the default basic prompt.
# Drawbacks
The Unicode arrow is pretty cool. And it predates many of us. Maybe it's
worth keeping. One argument I could see, and mildly disagree with, is
that it might make users lean towards installing a modern font for their
terminal which will would have good consequences in the future.
2023-03-02 01:59:32 +01:00
|
|
|
None => "> ",
|
2023-01-21 14:47:00 +01:00
|
|
|
}
|
|
|
|
.into(),
|
2021-10-02 15:10:28 +02:00
|
|
|
PromptEditMode::Vi(vi_mode) => match vi_mode {
|
2022-03-31 07:22:55 +02:00
|
|
|
PromptViMode::Normal => match &self.default_vi_normal_prompt_indicator {
|
2023-01-21 14:47:00 +01:00
|
|
|
Some(indicator) => indicator,
|
|
|
|
None => ": ",
|
2022-03-31 07:22:55 +02:00
|
|
|
},
|
|
|
|
PromptViMode::Insert => match &self.default_vi_insert_prompt_indicator {
|
2023-01-21 14:47:00 +01:00
|
|
|
Some(indicator) => indicator,
|
Make the default prompt play nice with basic fonts (#8080)
# Description
This commit changes the `PROMPT_INDICATOR` and
`PROMPT_INDICATOR_VI_NORMAL` in the default_env and sample_login files.
It also changes its missing fallback in the prompt.rs file.
This has the intention of making the default prompt friendlier when
dealing with basic terminals that may not support displaying a huge
range of the Unicode standard, or users who don't want to get out of
their way to install custom fonts for their terminals. It's also
nicer/more balanced on the eyes, to me, and brings it in line with the
logo of nushell `nu>`.
# User-Facing Changes
New installations of nushell will have > as the default prompt
indicator, and running `config reset` will also change it. This might be
confusing for a few seconds, it could be minor enough that it just feels
slightly off. Anyone who has, for some reason, unset the
PROMPT_INDICATOR variable, or set it to $nothing, will also receive the
`>` treatment.
Users running on basic terminals (like cmd.exe on Windows 10) should no
longer face font issues with the default basic prompt.
# Drawbacks
The Unicode arrow is pretty cool. And it predates many of us. Maybe it's
worth keeping. One argument I could see, and mildly disagree with, is
that it might make users lean towards installing a modern font for their
terminal which will would have good consequences in the future.
2023-03-02 01:59:32 +01:00
|
|
|
None => "> ",
|
2022-03-31 07:22:55 +02:00
|
|
|
},
|
2023-01-21 14:47:00 +01:00
|
|
|
}
|
|
|
|
.into(),
|
2021-10-02 15:10:28 +02:00
|
|
|
PromptEditMode::Custom(str) => self.default_wrapped_custom_string(str).into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render_prompt_multiline_indicator(&self) -> Cow<str> {
|
2022-05-10 23:33:18 +02:00
|
|
|
match &self.default_multiline_indicator {
|
2023-01-21 14:47:00 +01:00
|
|
|
Some(indicator) => indicator,
|
|
|
|
None => "::: ",
|
2022-05-10 23:33:18 +02:00
|
|
|
}
|
2023-01-21 14:47:00 +01:00
|
|
|
.into()
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn render_prompt_history_search_indicator(
|
|
|
|
&self,
|
|
|
|
history_search: PromptHistorySearch,
|
|
|
|
) -> Cow<str> {
|
|
|
|
let prefix = match history_search.status {
|
|
|
|
PromptHistorySearchStatus::Passing => "",
|
|
|
|
PromptHistorySearchStatus::Failing => "failing ",
|
|
|
|
};
|
|
|
|
|
|
|
|
Cow::Owned(format!(
|
|
|
|
"({}reverse-search: {})",
|
|
|
|
prefix, history_search.term
|
|
|
|
))
|
|
|
|
}
|
2022-10-23 16:18:26 +02:00
|
|
|
|
|
|
|
fn right_prompt_on_last_line(&self) -> bool {
|
|
|
|
self.render_right_prompt_on_last_line
|
|
|
|
}
|
2021-10-02 15:10:28 +02:00
|
|
|
}
|