diff --git a/Cargo.toml b/Cargo.toml index 05c5b9a..d71bd84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "ansi_term" +name = "ansiterm" description = "Library for ANSI terminal colours and styles (bold, underline)" edition = "2021" authors = [ "ogham@bsago.me", "Ryan Scheel (Havvy) ", "Josh Triplett " ] -documentation = "https://docs.rs/ansi_term" +documentation = "https://docs.rs/ansiterm" homepage = "https://github.com/ogham/rust-ansi-term" license = "MIT" readme = "README.md" @@ -11,7 +11,7 @@ version = "0.12.1" repository = "https://github.com/ogham/rust-ansi-term" [lib] -name = "ansi_term" +name = "ansiterm" [features] derive_serde_style = ["serde"] diff --git a/README.md b/README.md index cc1184d..52e495f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ -# Rustadopt community fork of rust-ansi-term by github.com/ogham +# ansiterm-rs -This is a library for controlling colours and formatting, such as red bold text or blue underlined text, on ANSI terminals. +Continuation of the unmaintained [ansi-term](https://github.com/ogham/rust-ansi-term), +a library for controlling colours and formatting, such as red bold text or blue +underlined text, on ANSI terminals. +Big shout-out to its creator [Benjamin Sago](https://github.com/ogham). # Installation @@ -24,7 +27,7 @@ To format a string, call the `paint` method on a `Style` or a `Colour`, passing For example, here’s how to get some red text: ```rust -use ansi_term::Colour::Red; +use ansiterm::Colour::Red; println!("This is in red: {}", Red.paint("a red string")); ``` @@ -36,7 +39,7 @@ This allows strings to be printed with a minimum of `String` allocations being p If you *do* want to get at the escape codes, then you can convert the `ANSIString` to a string as you would any other `Display` value: ```rust -use ansi_term::Colour::Red; +use ansiterm::Colour::Red; let red_string = Red.paint("a red string").to_string(); ``` @@ -44,7 +47,7 @@ let red_string = Red.paint("a red string").to_string(); **Note for Windows 10 users:** On Windows 10, the application must enable ANSI support first: ```rust,ignore -let enabled = ansi_term::enable_ansi_support(); +let enabled = ansiterm::enable_ansi_support(); ``` ## Bold, underline, background, and other styles @@ -55,7 +58,7 @@ Each method creates a new style that has that specific property set. For example: ```rust -use ansi_term::Style; +use ansiterm::Style; println!("How about some {} and {}?", Style::new().bold().paint("bold"), @@ -65,7 +68,7 @@ println!("How about some {} and {}?", For brevity, these methods have also been implemented for `Colour` values, so you can give your styles a foreground colour without having to begin with an empty `Style` value: ```rust -use ansi_term::Colour::{Blue, Yellow}; +use ansiterm::Colour::{Blue, Yellow}; println!("Demonstrating {} and {}!", Blue.bold().paint("blue bold"), @@ -81,8 +84,8 @@ In some cases, you may find it easier to change the foreground on an existing `S You can do this using the `fg` method: ```rust -use ansi_term::Style; -use ansi_term::Colour::{Blue, Cyan, Yellow}; +use ansiterm::Style; +use ansiterm::Colour::{Blue, Cyan, Yellow}; println!("Yellow on blue: {}", Style::new().on(Blue).fg(Yellow).paint("yow!")); println!("Also yellow on blue: {}", Cyan.on(Blue).fg(Yellow).paint("zow!")); @@ -92,8 +95,8 @@ You can turn a `Colour` into a `Style` with the `normal` method. This will produce the exact same `ANSIString` as if you just used the `paint` method on the `Colour` directly, but it’s useful in certain cases: for example, you may have a method that returns `Styles`, and need to represent both the “red bold” and “red, but not bold” styles with values of the same type. The `Style` struct also has a `Default` implementation if you want to have a style with *nothing* set. ```rust -use ansi_term::Style; -use ansi_term::Colour::Red; +use ansiterm::Style; +use ansiterm::Colour::Red; Red.normal().paint("yet another red string"); Style::default().paint("a completely regular string"); @@ -106,7 +109,7 @@ You can access the extended range of 256 colours by using the `Colour::Fixed` va This can be included wherever you would use a `Colour`: ```rust -use ansi_term::Colour::Fixed; +use ansiterm::Colour::Fixed; Fixed(134).paint("A sort of light purple"); Fixed(221).on(Fixed(124)).paint("Mustard in the ketchup"); @@ -118,7 +121,7 @@ There’s nothing stopping you from using these as `Fixed` colours instead, but You can also access full 24-bit colour by using the `Colour::RGB` variant, which takes separate `u8` arguments for red, green, and blue: ```rust -use ansi_term::Colour::RGB; +use ansiterm::Colour::RGB; RGB(70, 130, 180).paint("Steel blue"); ``` @@ -134,8 +137,8 @@ The `ANSIStrings` struct takes a slice of several `ANSIString` values, and will The following code snippet uses this to enclose a binary number displayed in red bold text inside some red, but not bold, brackets: ```rust -use ansi_term::Colour::Red; -use ansi_term::{ANSIString, ANSIStrings}; +use ansiterm::Colour::Red; +use ansiterm::{ANSIString, ANSIStrings}; let some_value = format!("{:b}", 42); let strings: &[ANSIString<'static>] = &[ @@ -160,7 +163,7 @@ This library also supports formatting `[u8]` byte strings; this supports applica This type does not implement `Display`, as it may not contain UTF-8, but it does provide a method `write_to` to write the result to any value that implements `Write`: ```rust -use ansi_term::Colour::Green; +use ansiterm::Colour::Green; Green.paint("user data".as_bytes()).write_to(&mut std::io::stdout()).unwrap(); ``` @@ -168,8 +171,8 @@ Green.paint("user data".as_bytes()).write_to(&mut std::io::stdout()).unwrap(); Similarly, the type `ANSIByteStrings` supports writing a list of `ANSIByteString` values with minimal escape sequences: ```rust -use ansi_term::Colour::Green; -use ansi_term::ANSIByteStrings; +use ansiterm::Colour::Green; +use ansiterm::ANSIByteStrings; ANSIByteStrings(&[ Green.paint("user data 1\n".as_bytes()), diff --git a/examples/256_colours.rs b/examples/256_colours.rs index 92fe2f1..093fc3e 100644 --- a/examples/256_colours.rs +++ b/examples/256_colours.rs @@ -1,5 +1,5 @@ -extern crate ansi_term; -use ansi_term::Colour; +extern crate ansiterm; +use ansiterm::Colour; // This example prints out the 256 colours. // They're arranged like this: diff --git a/examples/basic_colours.rs b/examples/basic_colours.rs index ba88156..2cb7463 100644 --- a/examples/basic_colours.rs +++ b/examples/basic_colours.rs @@ -1,5 +1,5 @@ -extern crate ansi_term; -use ansi_term::{Style, Colour::*}; +extern crate ansiterm; +use ansiterm::{Style, Colour::*}; // This example prints out the 16 basic colours. diff --git a/examples/rgb_colours.rs b/examples/rgb_colours.rs index fd2cc7a..2d3f1ec 100644 --- a/examples/rgb_colours.rs +++ b/examples/rgb_colours.rs @@ -1,5 +1,5 @@ -extern crate ansi_term; -use ansi_term::{Style, Colour}; +extern crate ansiterm; +use ansiterm::{Style, Colour}; // This example prints out a colour gradient in a grid by calculating each // character’s red, green, and blue components, and using 24-bit colour codes diff --git a/src/ansi.rs b/src/ansi.rs index f80f789..1e6b67a 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -173,7 +173,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::{Style, Colour::Blue}; + /// use ansiterm::{Style, Colour::Blue}; /// /// let style = Style::default().bold(); /// assert_eq!("\x1b[1m", @@ -198,7 +198,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::{Style, Colour::Green}; + /// use ansiterm::{Style, Colour::Green}; /// /// let style = Style::default().bold(); /// assert_eq!("\x1b[32m", @@ -222,7 +222,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::{Style, Colour::Green}; + /// use ansiterm::{Style, Colour::Green}; /// /// let style = Style::default().bold(); /// assert_eq!("\x1b[0m", @@ -252,7 +252,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour::Green; + /// use ansiterm::Colour::Green; /// /// assert_eq!("\x1b[0m", /// Green.suffix().to_string()); @@ -270,7 +270,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour::{Red, Yellow}; + /// use ansiterm::Colour::{Red, Yellow}; /// /// assert_eq!("\x1b[33m", /// Red.infix(Yellow).to_string()); @@ -287,7 +287,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour::Purple; + /// use ansiterm::Colour::Purple; /// /// assert_eq!("\x1b[0m", /// Purple.suffix().to_string()); @@ -344,7 +344,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// assert_eq!(Colour::Fixed( 16), Colour::approx_rgb( 0, 0, 0)); /// assert_eq!(Colour::Fixed( 16), Colour::approx_rgb( 0, 1, 2)); @@ -364,7 +364,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// assert_eq!(Colour::Red, Colour::Red.into_256()); /// assert_eq!(Colour::Fixed( 11), Colour::Fixed(11).into_256()); @@ -398,7 +398,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// assert_eq!(( 0, 0, 0), Colour::Fixed( 16).into_rgb()); /// assert_eq!(( 95, 135, 175), Colour::Fixed( 67).into_rgb()); diff --git a/src/debug.rs b/src/debug.rs index d94e208..101196d 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -9,7 +9,7 @@ use crate::style::Style; /// `format!("{:#?}")`. /// /// ``` -/// use ansi_term::Colour::{Red, Blue}; +/// use ansiterm::Colour::{Red, Blue}; /// /// assert_eq!( /// "Style { fg(Red), on(Blue), bold, italic }", diff --git a/src/display.rs b/src/display.rs index 4f58fa6..ea2860a 100644 --- a/src/display.rs +++ b/src/display.rs @@ -25,7 +25,7 @@ where ::Owned: fmt::Debug { /// # Examples /// /// ``` -/// use ansi_term::ANSIString; +/// use ansiterm::ANSIString; /// /// let plain_string = ANSIString::from("a plain string"); /// let clone_string = plain_string.clone(); @@ -73,15 +73,15 @@ where ::Owned: fmt::Debug { /// # Examples /// /// ``` -/// use ansi_term::ANSIString; -/// use ansi_term::Colour::Red; +/// use ansiterm::ANSIString; +/// use ansiterm::Colour::Red; /// /// let red_string = Red.paint("a red string"); /// println!("{}", red_string); /// ``` /// /// ``` -/// use ansi_term::ANSIString; +/// use ansiterm::ANSIString; /// /// let plain_string = ANSIString::from("a plain string"); /// assert_eq!(&*plain_string, "a plain string"); @@ -183,7 +183,7 @@ impl Colour { /// to get blue text. /// /// ``` - /// use ansi_term::Colour::Blue; + /// use ansiterm::Colour::Blue; /// println!("{}", Blue.paint("da ba dee")); /// ``` #[must_use] diff --git a/src/lib.rs b/src/lib.rs index 5b9fccf..948ae45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ //! here’s how to get some red text: //! //! ``` -//! use ansi_term::Colour::Red; +//! use ansiterm::Colour::Red; //! //! println!("This is in red: {}", Red.paint("a red string")); //! ``` @@ -34,7 +34,7 @@ //! [`ANSIString`] to a string as you would any other `Display` value: //! //! ``` -//! use ansi_term::Colour::Red; +//! use ansiterm::Colour::Red; //! //! let red_string = Red.paint("a red string").to_string(); //! ``` @@ -49,7 +49,7 @@ //! property set. For example: //! //! ``` -//! use ansi_term::Style; +//! use ansiterm::Style; //! //! println!("How about some {} and {}?", //! Style::new().bold().paint("bold"), @@ -61,7 +61,7 @@ //! an empty `Style` value: //! //! ``` -//! use ansi_term::Colour::{Blue, Yellow}; +//! use ansiterm::Colour::{Blue, Yellow}; //! //! println!("Demonstrating {} and {}!", //! Blue.bold().paint("blue bold"), @@ -79,8 +79,8 @@ //! You can do this using the [`fg`] method: //! //! ``` -//! use ansi_term::Style; -//! use ansi_term::Colour::{Blue, Cyan, Yellow}; +//! use ansiterm::Style; +//! use ansiterm::Colour::{Blue, Cyan, Yellow}; //! //! println!("Yellow on blue: {}", Style::new().on(Blue).fg(Yellow).paint("yow!")); //! println!("Also yellow on blue: {}", Cyan.on(Blue).fg(Yellow).paint("zow!")); @@ -95,8 +95,8 @@ //! want to have a style with *nothing* set. //! //! ``` -//! use ansi_term::Style; -//! use ansi_term::Colour::Red; +//! use ansiterm::Style; +//! use ansiterm::Colour::Red; //! //! Red.normal().paint("yet another red string"); //! Style::default().paint("a completely regular string"); @@ -110,7 +110,7 @@ //! included wherever you would use a `Colour`: //! //! ``` -//! use ansi_term::Colour::Fixed; +//! use ansiterm::Colour::Fixed; //! //! Fixed(134).paint("A sort of light purple"); //! Fixed(221).on(Fixed(124)).paint("Mustard in the ketchup"); @@ -125,7 +125,7 @@ //! which takes separate `u8` arguments for red, green, and blue: //! //! ``` -//! use ansi_term::Colour::RGB; +//! use ansiterm::Colour::RGB; //! //! RGB(70, 130, 180).paint("Steel blue"); //! ``` @@ -150,8 +150,8 @@ //! red bold text inside some red, but not bold, brackets: //! //! ``` -//! use ansi_term::Colour::Red; -//! use ansi_term::{ANSIString, ANSIStrings}; +//! use ansiterm::Colour::Red; +//! use ansiterm::{ANSIString, ANSIStrings}; //! //! let some_value = format!("{:b}", 42); //! let strings: &[ANSIString<'static>] = &[ @@ -182,7 +182,7 @@ //! implements [`Write`]: //! //! ``` -//! use ansi_term::Colour::Green; +//! use ansiterm::Colour::Green; //! //! Green.paint("user data".as_bytes()).write_to(&mut std::io::stdout()).unwrap(); //! ``` @@ -191,8 +191,8 @@ //! [`ANSIByteString`] values with minimal escape sequences: //! //! ``` -//! use ansi_term::Colour::Green; -//! use ansi_term::ANSIByteStrings; +//! use ansiterm::Colour::Green; +//! use ansiterm::ANSIByteStrings; //! //! ANSIByteStrings(&[ //! Green.paint("user data 1\n".as_bytes()), @@ -229,7 +229,7 @@ //! [`fg`]: struct.Style.html#method.fg //! [`on`]: struct.Style.html#method.on -#![crate_name = "ansi_term"] +#![crate_name = "ansiterm"] #![crate_type = "rlib"] #![crate_type = "dylib"] diff --git a/src/style.rs b/src/style.rs index c49637f..f79e0ce 100644 --- a/src/style.rs +++ b/src/style.rs @@ -4,7 +4,7 @@ /// # Examples /// /// ``` -/// use ansi_term::{Style, Colour}; +/// use ansiterm::{Style, Colour}; /// /// let style = Style::new().bold().on(Colour::Black); /// println!("{}", style.paint("Bold on black")); @@ -51,7 +51,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new(); /// println!("{}", style.paint("hi")); @@ -65,7 +65,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().bold(); /// println!("{}", style.paint("hey")); @@ -79,7 +79,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().dimmed(); /// println!("{}", style.paint("sup")); @@ -93,7 +93,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().italic(); /// println!("{}", style.paint("greetings")); @@ -107,7 +107,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().underline(); /// println!("{}", style.paint("salutations")); @@ -120,7 +120,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().blink(); /// println!("{}", style.paint("wazzup")); @@ -134,7 +134,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().reverse(); /// println!("{}", style.paint("aloha")); @@ -148,7 +148,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().hidden(); /// println!("{}", style.paint("ahoy")); @@ -162,7 +162,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// let style = Style::new().strikethrough(); /// println!("{}", style.paint("yo")); @@ -176,7 +176,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::{Style, Colour}; + /// use ansiterm::{Style, Colour}; /// /// let style = Style::new().fg(Colour::Yellow); /// println!("{}", style.paint("hi")); @@ -190,7 +190,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::{Style, Colour}; + /// use ansiterm::{Style, Colour}; /// /// let style = Style::new().on(Colour::Blue); /// println!("{}", style.paint("eyyyy")); @@ -205,7 +205,7 @@ impl Style { /// # Examples /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// /// assert_eq!(true, Style::default().is_plain()); /// assert_eq!(false, Style::default().bold().is_plain()); @@ -221,7 +221,7 @@ impl Default for Style { /// style returns the exact same text. /// /// ``` - /// use ansi_term::Style; + /// use ansiterm::Style; /// assert_eq!(None, Style::default().foreground); /// assert_eq!(None, Style::default().background); /// assert_eq!(false, Style::default().is_bold); @@ -349,7 +349,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Red.normal(); /// println!("{}", style.paint("hi")); @@ -364,7 +364,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Green.bold(); /// println!("{}", style.paint("hey")); @@ -379,7 +379,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Yellow.dimmed(); /// println!("{}", style.paint("sup")); @@ -394,7 +394,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Blue.italic(); /// println!("{}", style.paint("greetings")); @@ -409,7 +409,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Purple.underline(); /// println!("{}", style.paint("salutations")); @@ -424,7 +424,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Cyan.blink(); /// println!("{}", style.paint("wazzup")); @@ -439,7 +439,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Black.reverse(); /// println!("{}", style.paint("aloha")); @@ -454,7 +454,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::White.hidden(); /// println!("{}", style.paint("ahoy")); @@ -469,7 +469,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::Fixed(244).strikethrough(); /// println!("{}", style.paint("yo")); @@ -484,7 +484,7 @@ impl Colour { /// # Examples /// /// ``` - /// use ansi_term::Colour; + /// use ansiterm::Colour; /// /// let style = Colour::RGB(31, 31, 31).on(Colour::White); /// println!("{}", style.paint("eyyyy")); @@ -530,7 +530,7 @@ impl From for Style { /// with the `From` trait. /// /// ``` - /// use ansi_term::{Style, Colour}; + /// use ansiterm::{Style, Colour}; /// let green_foreground = Style::default().fg(Colour::Green); /// assert_eq!(green_foreground, Colour::Green.normal()); /// assert_eq!(green_foreground, Colour::Green.into());