From 0b5e131410a2af3c9efc6bdb9591863c3e6e8bfb Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 9 Apr 2021 11:38:56 -0500 Subject: [PATCH] Remove x1b, update prompt (#3291) * add term size command * remove \x1b and use nu_ansi_term, make prompt with no config prettier --- crates/nu-ansi-term/src/ansi.rs | 1 + crates/nu-ansi-term/src/lib.rs | 2 +- crates/nu-cli/src/cli.rs | 21 +++++++++++++++++++-- crates/nu-cli/src/shell/helper.rs | 3 ++- crates/nu-table/src/wrap.rs | 8 ++++++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/crates/nu-ansi-term/src/ansi.rs b/crates/nu-ansi-term/src/ansi.rs index 02c339f967..1b9a78eda2 100644 --- a/crates/nu-ansi-term/src/ansi.rs +++ b/crates/nu-ansi-term/src/ansi.rs @@ -1,3 +1,4 @@ +#![allow(missing_docs)] use crate::style::{Color, Style}; use crate::write::AnyWrite; use std::fmt; diff --git a/crates/nu-ansi-term/src/lib.rs b/crates/nu-ansi-term/src/lib.rs index e903ce2355..e19d6b1e97 100644 --- a/crates/nu-ansi-term/src/lib.rs +++ b/crates/nu-ansi-term/src/lib.rs @@ -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; diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index ed69824bc7..0952d421a9 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -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 ", 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 ", 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 + ) } }; diff --git a/crates/nu-cli/src/shell/helper.rs b/crates/nu-cli/src/shell/helper.rs index 2c56915530..ef1963c9ae 100644 --- a/crates/nu-cli/src/shell/helper.rs +++ b/crates/nu-cli/src/shell/helper.rs @@ -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> { diff --git a/crates/nu-table/src/wrap.rs b/crates/nu-table/src/wrap.rs index a86702dc14..9aa01a29b6 100644 --- a/crates/nu-table/src/wrap.rs +++ b/crates/nu-table/src/wrap.rs @@ -252,13 +252,17 @@ pub fn wrap<'a>( }; if let Some(leading_match) = re_leading.find(¤t_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(¤t_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 {