mirror of
https://github.com/nushell/nushell
synced 2024-12-26 21:13:19 +00:00
Process prompts once rather than twice
This commit is contained in:
parent
406fb8d1d9
commit
dd36bf07f4
1 changed files with 7 additions and 27 deletions
34
src/cli.rs
34
src/cli.rs
|
@ -395,32 +395,6 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||||
// Redefine Ctrl-D to same command as Ctrl-C
|
// Redefine Ctrl-D to same command as Ctrl-C
|
||||||
rl.bind_sequence(rustyline::KeyPress::Ctrl('D'), rustyline::Cmd::Interrupt);
|
rl.bind_sequence(rustyline::KeyPress::Ctrl('D'), rustyline::Cmd::Interrupt);
|
||||||
|
|
||||||
let prompt = {
|
|
||||||
#[cfg(feature = "starship-prompt")]
|
|
||||||
{
|
|
||||||
let bytes = strip_ansi_escapes::strip(&starship::print::get_prompt(
|
|
||||||
starship::context::Context::new_with_dir(
|
|
||||||
clap::ArgMatches::default(),
|
|
||||||
cwd.clone(),
|
|
||||||
),
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
String::from_utf8_lossy(&bytes).to_string()
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "starship-prompt"))]
|
|
||||||
{
|
|
||||||
&format!(
|
|
||||||
"{}{}> ",
|
|
||||||
cwd,
|
|
||||||
match current_branch() {
|
|
||||||
Some(s) => format!("({})", s),
|
|
||||||
None => "".to_string(),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let colored_prompt = {
|
let colored_prompt = {
|
||||||
#[cfg(feature = "starship-prompt")]
|
#[cfg(feature = "starship-prompt")]
|
||||||
{
|
{
|
||||||
|
@ -432,7 +406,7 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||||
#[cfg(not(feature = "starship-prompt"))]
|
#[cfg(not(feature = "starship-prompt"))]
|
||||||
{
|
{
|
||||||
format!(
|
format!(
|
||||||
"{}{}\x1b[m]> ",
|
"\x1b[32m{}{}\x1b[m> ",
|
||||||
cwd,
|
cwd,
|
||||||
match current_branch() {
|
match current_branch() {
|
||||||
Some(s) => format!("({})", s),
|
Some(s) => format!("({})", s),
|
||||||
|
@ -442,6 +416,12 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let prompt = {
|
||||||
|
let bytes = strip_ansi_escapes::strip(&colored_prompt).unwrap();
|
||||||
|
|
||||||
|
String::from_utf8_lossy(&bytes).to_string()
|
||||||
|
};
|
||||||
|
|
||||||
rl.helper_mut().expect("No helper").colored_prompt = colored_prompt;
|
rl.helper_mut().expect("No helper").colored_prompt = colored_prompt;
|
||||||
let mut initial_command = Some(String::new());
|
let mut initial_command = Some(String::new());
|
||||||
let mut readline = Err(ReadlineError::Eof);
|
let mut readline = Err(ReadlineError::Eof);
|
||||||
|
|
Loading…
Reference in a new issue