diff options
81 files changed, 149 insertions, 142 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f21f94220..5942b5387 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -180,7 +180,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { mod tests { use super::*; use crate::test::ModuleRenderer; - use ansi_term::Color; + use nu_ansi_term::Color; use std::fs::File; use std::io; diff --git a/Cargo.lock b/Cargo.lock index 230ea10d0..2c8bb7dfd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,15 +38,6 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] name = "anyhow" version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1758,6 +1749,16 @@ dependencies = [ ] [[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] name = "num-derive" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1904,6 +1905,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] name = "parking" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2661,7 +2668,6 @@ dependencies = [ name = "starship" version = "1.10.2" dependencies = [ - "ansi_term", "chrono", "clap", "clap_complete", @@ -2679,6 +2685,7 @@ dependencies = [ "mockall", "nix 0.25.0", "notify-rust", + "nu-ansi-term", "once_cell", "open", "os_info", diff --git a/Cargo.toml b/Cargo.toml index 1c85bd6b3..68565f1dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ config-schema = ["schemars"] notify = ["notify-rust"] [dependencies] -ansi_term = "0.12.1" chrono = { version = "0.4.22", features = ["clock", "std"] } clap = { version = "=3.2.20", features = ["derive", "cargo", "unicode", "unstable-v4"] } clap_complete = "3.2.4" @@ -51,6 +50,7 @@ log = { version = "0.4.16", features = ["std"] } # nofity-rust is optional (on by default) because the crate doesn't currently build for darwin with nix # see: https://github.com/NixOS/nixpkgs/issues/160876 notify-rust = { version = "4.5.8", optional = true } +nu-ansi-term = "0.46.0" once_cell = "1.13.1" open = "3.0.2" os_info = "3.5.0" diff --git a/src/config.rs b/src/config.rs index faeba829c..af882deaf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,6 @@ use crate::serde_utils::ValueDeserializer; use crate::utils; -use ansi_term::Color; +use nu_ansi_term::Color; use serde::{ de::value::Error as ValueError, de::Error as SerdeError, Deserialize, Deserializer, Serialize, }; @@ -251,7 +251,7 @@ impl StarshipConfig { } /// Deserialize a style string in the starship format with serde -pub fn deserialize_style<'de, D>(de: D) -> Result<ansi_term::Style, D::Error> +pub fn deserialize_style<'de, D>(de: D) -> Result<nu_ansi_term::Style, D::Error> where D: Deserializer<'de>, { @@ -271,10 +271,10 @@ where - 'blink' - '<color>' (see the `parse_color_string` doc for valid color strings) */ -pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> { +pub fn parse_style_string(style_string: &str) -> Option<nu_ansi_term::Style> { style_string .split_whitespace() - .fold(Some(ansi_term::Style::new()), |maybe_style, token| { + .fold(Some(nu_ansi_term::Style::new()), |maybe_style, token| { maybe_style.and_then(|style| { let token = token.to_lowercase(); @@ -333,7 +333,7 @@ pub fn parse_style_string(style_string: &str) -> Option<ansi_term::Style> { - u8 (a number from 0-255, representing an ANSI color) - colstring (one of the 16 predefined color strings) */ -fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> { +fn parse_color_string(color_string: &str) -> Option<nu_ansi_term::Color> { // Parse RGB hex values log::trace!("Parsing color_string: {}", color_string); if color_string.starts_with('#') { @@ -349,7 +349,7 @@ fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> { let g: u8 = u8::from_str_radix(&color_string[3..5], 16).ok()?; let b: u8 = u8::from_str_radix(&color_string[5..7], 16).ok()?; log::trace!("Read RGB color string: {},{},{}", r, g, b); - return Some(Color::RGB(r, g, b)); + return Some(Color::Rgb(r, g, b)); } // Parse a u8 (ansi color) @@ -369,14 +369,14 @@ fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> { "purple" => Some(Color::Purple), "cyan" => Some(Color::Cyan), "white" => Some(Color::White), - "bright-black" => Some(Color::Fixed(8)), // "bright-black" is dark grey - "bright-red" => Some(Color::Fixed(9)), - "bright-green" => Some(Color::Fixed(10)), - "bright-yellow" => Some(Color::Fixed(11)), - "bright-blue" => Some(Color::Fixed(12)), - "bright-purple" => Some(Color::Fixed(13)), - "bright-cyan" => Some(Color::Fixed(14)), - "bright-white" => Some(Color::Fixed(15)), + "bright-black" => Some(Color::DarkGray), // "bright-black" is dark grey + "bright-red" => Some(Color::LightRed), + "bright-green" => Some(Color::LightGreen), + "bright-yellow" => Some(Color::LightYellow), + "bright-blue" => Some(Color::LightBlue), + "bright-purple" => Some(Color::LightPurple), + "bright-cyan" => Some(Color::LightCyan), + "bright-white" => Some(Color::LightGray), _ => None, }; @@ -391,7 +391,7 @@ fn parse_color_string(color_string: &str) -> Option<ansi_term::Color> { #[cfg(test)] mod tests { use super::*; - use ansi_term::Style; + use nu_ansi_term::Style; // Small wrapper to allow deserializing Style without a struct with #[serde(deserialize_with=)] #[derive(Default, Clone, Debug, PartialEq)] @@ -574,7 +574,7 @@ mod tests { let config = Value::from("#a12BcD"); assert_eq!( <StyleWrapper>::from_config(&config).unwrap().0, - Color::RGB(0xA1, 0x2B, 0xCD).into() + Color::Rgb(0xA1, 0x2B, 0xCD).into() ); } @@ -600,7 +600,7 @@ mod tests { assert!(mystyle.is_dimmed); assert_eq!( mystyle, - ansi_term::Style::new() + nu_ansi_term::Style::new() .bold() .italic() .underline() @@ -620,7 +620,7 @@ mod tests { assert!(mystyle.is_reverse); assert_eq!( mystyle, - ansi_term::Style::new() + nu_ansi_term::Style::new() .bold() .italic() .underline() @@ -641,7 +641,7 @@ mod tests { assert!(mystyle.is_blink); assert_eq!( mystyle, - ansi_term::Style::new() + nu_ansi_term::Style::new() .bold() .italic() .underline() @@ -662,7 +662,7 @@ mod tests { assert!(mystyle.is_hidden); assert_eq!( mystyle, - ansi_term::Style::new() + nu_ansi_term::Style::new() .bold() .italic() .underline() @@ -683,7 +683,7 @@ mod tests { assert!(mystyle.is_strikethrough); assert_eq!( mystyle, - ansi_term::Style::new() + nu_ansi_term::Style::new() .bold() .italic() .underline() @@ -698,7 +698,7 @@ mod tests { // Test a "plain" style with no formatting let config = Value::from(""); let plain_style = <StyleWrapper>::from_config(&config).unwrap().0; - assert_eq!(plain_style, ansi_term::Style::new()); + assert_eq!(plain_style, nu_ansi_term::Style::new()); // Test a string that's clearly broken let config = Value::from("djklgfhjkldhlhk;j"); @@ -763,7 +763,7 @@ mod tests { Style::new() .underline() .fg(Color::Fixed(120)) - .on(Color::RGB(5, 5, 5)) + .on(Color::Rgb(5, 5, 5)) ); // Test that the last color style is always the one used diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs index 3755edc7d..8cce8f4e2 100644 --- a/src/formatter/string_formatter.rs +++ b/src/formatter/string_formatter.rs @@ -1,4 +1,4 @@ -use ansi_term::Style; +use nu_ansi_term::Style; use pest::error::Error as PestError; use rayon::prelude::*; use std::borrow::Cow; @@ -465,7 +465,7 @@ where #[cfg(test)] mod tests { use super::*; - use ansi_term::Color; + use nu_ansi_term::Color; // match_next(result: IterMut<Segment>, value, style) macro_rules! match_next { diff --git a/src/logger.rs b/src/logger.rs index 82d8e97fb..d7ff11f8d 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -1,6 +1,6 @@ use crate::utils; -use ansi_term::Color; use log::{Level, LevelFilter, Metadata, Record}; +use nu_ansi_term::Color; use once_cell::sync::OnceCell; use std::{ collections::HashSet, diff --git a/src/main.rs b/src/main.rs index 0e4ba6538..7ffb15887 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ enum Commands { fn main() { // Configure the current terminal on windows to support ANSI escape sequences. #[cfg(windows)] - let _ = ansi_term::enable_ansi_support(); + let _ = nu_ansi_term::enable_ansi_support(); logger::init(); init_global_threadpool(); diff --git a/src/module.rs b/src/module.rs index e5b896256..c83947e24 100644 --- a/src/module.rs +++ b/src/module.rs @@ -2,7 +2,7 @@ use crate::context::Shell; use crate::segment; use crate::segment::{FillSegment, Segment}; use crate::utils::wrap_colorseq_for_shell; -use ansi_term::{ANSIString, ANSIStrings}; +use nu_ansi_term::{AnsiString, AnsiStrings}; use std::fmt; use std::time::Duration; @@ -146,15 +146,15 @@ impl<'a> Module<'a> { self.segments.iter().map(segment::Segment::value).collect() } - /// Returns a vector of colored `ANSIString` elements to be later used with - /// `ANSIStrings()` to optimize ANSI codes - pub fn ansi_strings(&self) -> Vec<ANSIString> { + /// Returns a vector of colored `AnsiString` elements to be later used with + /// `AnsiStrings()` to optimize ANSI codes + pub fn ansi_strings(&self) -> Vec<AnsiString> { self.ansi_strings_for_shell(Shell::Unknown, None) } - pub fn ansi_strings_for_shell(&self, shell: Shell, width: Option<usize>) -> Vec<ANSIString> { + pub fn ansi_strings_for_shell(&self, shell: Shell, width: Option<usize>) -> Vec<AnsiString> { let mut iter = self.segments.iter().peekable(); - let mut ansi_strings: Vec<ANSIString> = Vec::new(); + let mut ansi_strings: Vec<AnsiString> = Vec::new(); while iter.peek().is_some() { ansi_strings.extend(ansi_line(&mut iter, width)); } @@ -171,27 +171,27 @@ impl<'a> Module<'a> { impl<'a> fmt::Display for Module<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let ansi_strings = self.ansi_strings(); - write!(f, "{}", ANSIStrings(&ansi_strings)) + write!(f, "{}", AnsiStrings(&ansi_strings)) } } -fn ansi_strings_modified(ansi_strings: Vec<ANSIString>, shell: Shell) -> Vec<ANSIString> { +fn ansi_strings_modified(ansi_strings: Vec<AnsiString>, shell: Shell) -> Vec<AnsiString> { ansi_strings .into_iter() .map(|ansi| { let wrapped = wrap_colorseq_for_shell(ansi.to_string(), shell); - ANSIString::from(wrapped) + AnsiString::from(wrapped) }) - .collect::<Vec<ANSIString>>() + .collect::<Vec<AnsiString>>() } -fn ansi_line<'a, I>(segments: &mut I, term_width: Option<usize>) -> Vec<ANSIString<'a>> +fn ansi_line<'a, I>(segments: &mut I, term_width: Option<usize>) -> Vec<AnsiString<'a>> where I: Iterator<Item = &'a Segment>, { let mut used = 0usize; - let mut current: Vec<ANSIString> = Vec::new(); - let mut chunks: Vec<(Vec<ANSIString>, &FillSegment)> = Vec::new(); + let mut current: Vec<AnsiString> = Vec::new(); + let mut chunks: Vec<(Vec<AnsiString>, &FillSegment)> = Vec::new(); for segment in segments { match segment { @@ -223,7 +223,7 @@ where .chain(std::iter::once(fill.ansi_string(fill_size))) }) .chain(current.into_iter()) - .collect::<Vec<ANSIString>>() + .collect::<Vec<AnsiString>>() } } diff --git a/src/modules/aws.rs b/src/modules/aws.rs index fa83c6111..0768a0f40 100644 --- a/src/modules/aws.rs +++ b/src/modules/aws.rs @@ -248,7 +248,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { #[cfg(test)] mod tests { use crate::test::ModuleRenderer; - use ansi_term::Color; + use nu_ansi_term::Color; use std::fs::{create_dir, File}; use std::io::{self, Write}; diff --git a/src/modules/azure.rs b/src/modules/azure.rs index 87bb351db..5cb2b52e4 100644 --- a/src/modules/azure.rs +++ b/src/modules/azure.rs @@ -108,8 +108,8 @@ fn parse_json(json_file_path: &Path) -> Option<JValue> { mod tests { use crate::modules::azure::parse_json; use crate::test::ModuleRenderer; - use ansi_term::Color; use ini::Ini; + use nu_ansi_term::Color; use std::fs::File; use std::io::{self, Write}; use std::path::PathBuf; diff --git a/src/modules/battery.rs b/src/modules/battery.rs index 1e4cc05a5..0800b2d45 100644 --- a/src/modules/battery.rs +++ b/src/modules/battery.rs @@ -172,7 +172,7 @@ impl BatteryInfoProvider for BatteryInfoProviderImpl { mod tests { use super::*; use crate::test::ModuleRenderer; - use ansi_term::Color; |