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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 6 deletions

View File

@ -1,3 +1,4 @@
#![allow(missing_docs)]
use crate::style::{Color, Style};
use crate::write::AnyWrite;
use std::fmt;

View File

@ -246,7 +246,7 @@ extern crate doc_comment;
#[cfg(test)]
doctest!("../README.md");
mod ansi;
pub mod ansi;
pub use ansi::{Infix, Prefix, Suffix};
mod style;

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> {

View File

@ -252,13 +252,17 @@ pub fn wrap<'a>(
};
if let Some(leading_match) = re_leading.find(&current_line.clone()) {
String::insert_str(&mut current_line, leading_match.end(), "\x1b[0m");
String::insert_str(
&mut current_line,
leading_match.end(),
nu_ansi_term::ansi::RESET,
);
String::insert_str(&mut current_line, leading_match.start(), &bg_color_string);
}
if let Some(trailing_match) = re_trailing.find(&current_line.clone()) {
String::insert_str(&mut current_line, trailing_match.start(), &bg_color_string);
current_line += "\x1b[0m";
current_line += nu_ansi_term::ansi::RESET;
}
output.push(WrappedLine {