Remove x1b, update prompt (#3291)

* add term size command

* remove \x1b and use nu_ansi_term, make prompt with no config prettier
This commit is contained in:
Darren Schroeder
2021-04-09 11:38:56 -05:00
committed by GitHub
parent 556596bce8
commit 0b5e131410
5 changed files with 29 additions and 6 deletions

View File

@ -1,4 +1,5 @@
use crate::line_editor::configure_ctrl_c;
use nu_ansi_term::Color;
use nu_command::commands::default_context::create_default_context;
use nu_engine::{maybe_print_errors, run_block, script::run_script_standalone, EvaluationContext};
@ -242,7 +243,15 @@ pub fn cli(context: EvaluationContext, options: Options) -> Result<(), Box<dyn E
if err.is_some() {
context.scope.exit_scope();
format!("\x1b[32m{}{}\x1b[m> ", cwd, current_branch())
format!(
"{}{}{}{}{}{}> ",
Color::Green.bold().prefix().to_string(),
cwd,
nu_ansi_term::ansi::RESET,
Color::Cyan.bold().prefix().to_string(),
current_branch(),
nu_ansi_term::ansi::RESET
)
} else {
let run_result = run_block(&prompt_block, &context, InputStream::empty());
context.scope.exit_scope();
@ -276,7 +285,15 @@ pub fn cli(context: EvaluationContext, options: Options) -> Result<(), Box<dyn E
}
}
} else {
format!("\x1b[32m{}{}\x1b[m> ", cwd, current_branch())
format!(
"{}{}{}{}{}{}> ",
Color::Green.bold().prefix().to_string(),
cwd,
nu_ansi_term::ansi::RESET,
Color::Cyan.bold().prefix().to_string(),
current_branch(),
nu_ansi_term::ansi::RESET
)
}
};

View File

@ -1,5 +1,6 @@
use crate::completion;
use crate::shell::completer::NuCompleter;
use nu_ansi_term::Color;
use nu_engine::{DefaultPalette, EvaluationContext, Painter};
use nu_source::{Tag, Tagged};
use std::borrow::Cow::{self, Owned};
@ -79,7 +80,7 @@ impl rustyline::highlight::Highlighter for Helper {
}
fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> {
Owned("\x1b[1m".to_owned() + hint + "\x1b[m")
Owned(Color::DarkGray.prefix().to_string() + hint + nu_ansi_term::ansi::RESET)
}
fn highlight<'l>(&self, line: &'l str, _pos: usize) -> Cow<'l, str> {