Merge pull request #975 from jonathandturner/process_prompt_once

Process prompts once rather than twice
This commit is contained in:
Jonathan Turner 2019-11-17 10:22:49 +13:00 committed by GitHub
commit 57d425d929
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);