mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 19:59:16 +02:00
Give rustyline non-ansi to begin with. Fixes Windows
This commit is contained in:
35
src/cli.rs
35
src/cli.rs
@@ -398,15 +398,17 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
let prompt = {
|
||||
#[cfg(feature = "starship-prompt")]
|
||||
{
|
||||
&starship::print::get_prompt(starship::context::Context::new_with_dir(
|
||||
let bytes = strip_ansi_escapes::strip(&starship::print::get_prompt(starship::context::Context::new_with_dir(
|
||||
clap::ArgMatches::default(),
|
||||
cwd,
|
||||
))
|
||||
cwd.clone(),
|
||||
))).unwrap();
|
||||
|
||||
String::from_utf8_lossy(&bytes).to_string()
|
||||
}
|
||||
#[cfg(not(feature = "starship-prompt"))]
|
||||
{
|
||||
&format!(
|
||||
"{}{}\x1b[m> ",
|
||||
"{}{}> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
@@ -415,10 +417,33 @@ pub async fn cli() -> Result<(), Box<dyn Error>> {
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
let colored_prompt = {
|
||||
#[cfg(feature = "starship-prompt")]
|
||||
{
|
||||
starship::print::get_prompt(starship::context::Context::new_with_dir(
|
||||
clap::ArgMatches::default(),
|
||||
cwd,
|
||||
))
|
||||
}
|
||||
#[cfg(not(feature = "starship-prompt"))]
|
||||
{
|
||||
format!(
|
||||
"{}{}\x1b[m]> ",
|
||||
cwd,
|
||||
match current_branch() {
|
||||
Some(s) => format!("({})", s),
|
||||
None => "".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
rl.helper_mut().expect("No helper").colored_prompt = colored_prompt;
|
||||
let mut initial_command = Some(String::new());
|
||||
let mut readline = Err(ReadlineError::Eof);
|
||||
while let Some(ref cmd) = initial_command {
|
||||
readline = rl.readline_with_initial(prompt, (&cmd, ""));
|
||||
readline = rl.readline_with_initial(&prompt, (&cmd, ""));
|
||||
if let Err(ReadlineError::Eof) = &readline {
|
||||
// Fuzzy search in history
|
||||
let lines = rl.history().iter().rev().map(|s| s.as_str()).collect();
|
||||
|
@@ -14,11 +14,12 @@ use std::borrow::Cow::{self, Owned};
|
||||
|
||||
pub(crate) struct Helper {
|
||||
context: Context,
|
||||
pub colored_prompt: String,
|
||||
}
|
||||
|
||||
impl Helper {
|
||||
pub(crate) fn new(context: Context) -> Helper {
|
||||
Helper { context }
|
||||
Helper { context, colored_prompt: String::new() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +42,14 @@ impl Hinter for Helper {
|
||||
}
|
||||
|
||||
impl Highlighter for Helper {
|
||||
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(&'s self, prompt: &'p str, _: bool) -> Cow<'b, str> {
|
||||
Owned("\x1b[32m".to_owned() + &prompt + "\x1b[m")
|
||||
fn highlight_prompt<'b, 's: 'b, 'p: 'b>(&'s self, prompt: &'p str, default: bool) -> Cow<'b, str> {
|
||||
use std::borrow::Cow::Borrowed;
|
||||
|
||||
if default {
|
||||
Borrowed(&self.colored_prompt)
|
||||
} else {
|
||||
Borrowed(prompt)
|
||||
}
|
||||
}
|
||||
|
||||
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
|
||||
|
Reference in New Issue
Block a user