diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
commit | 4f9fe856a25ab29345b90e7725509e9ee38a37be (patch) | |
tree | e4ffd8a9374cae7b21f7cbfb352927e0e074aff6 /vendor/nu-ansi-term/src/lib.rs | |
parent | Adding upstream version 1.68.2+dfsg1. (diff) | |
download | rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.tar.xz rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.zip |
Adding upstream version 1.69.0+dfsg1.upstream/1.69.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/nu-ansi-term/src/lib.rs (renamed from vendor/ansi_term/src/lib.rs) | 145 |
1 files changed, 73 insertions, 72 deletions
diff --git a/vendor/ansi_term/src/lib.rs b/vendor/nu-ansi-term/src/lib.rs index 2d2f83ae6..c04fd3276 100644 --- a/vendor/ansi_term/src/lib.rs +++ b/vendor/nu-ansi-term/src/lib.rs @@ -1,40 +1,40 @@ -//! This is a library for controlling colours and formatting, such as +//! This is a library for controlling colors and formatting, such as //! red bold text or blue underlined text, on ANSI terminals. //! //! //! ## Basic usage //! //! There are three main types in this crate that you need to be -//! concerned with: [`ANSIString`], [`Style`], and [`Colour`]. +//! concerned with: [`AnsiString`], [`Style`], and [`Color`]. //! -//! A `Style` holds stylistic information: foreground and background colours, +//! A `Style` holds stylistic information: foreground and background colors, //! whether the text should be bold, or blinking, or other properties. The -//! [`Colour`] enum represents the available colours. And an [`ANSIString`] is a +//! [`Color`] enum represents the available colors. And an [`AnsiString`] is a //! string paired with a [`Style`]. //! -//! [`Color`] is also available as an alias to `Colour`. +//! [`Color`] is also available as an alias to `Color`. //! -//! To format a string, call the `paint` method on a `Style` or a `Colour`, +//! To format a string, call the `paint` method on a `Style` or a `Color`, //! passing in the string you want to format as the argument. For example, //! here’s how to get some red text: //! //! ``` -//! use ansi_term::Colour::Red; +//! use nu_ansi_term::Color::Red; //! //! println!("This is in red: {}", Red.paint("a red string")); //! ``` //! //! It’s important to note that the `paint` method does *not* actually return a //! string with the ANSI control characters surrounding it. Instead, it returns -//! an [`ANSIString`] value that has a [`Display`] implementation that, when +//! an [`AnsiString`] value that has a [`Display`] implementation that, when //! formatted, returns the characters. This allows strings to be printed with a //! minimum of [`String`] allocations being performed behind the scenes. //! //! 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: +//! [`AnsiString`] to a string as you would any other `Display` value: //! //! ``` -//! use ansi_term::Colour::Red; +//! use nu_ansi_term::Color::Red; //! //! let red_string = Red.paint("a red string").to_string(); //! ``` @@ -42,26 +42,26 @@ //! //! ## Bold, underline, background, and other styles //! -//! For anything more complex than plain foreground colour changes, you need to -//! construct `Style` values themselves, rather than beginning with a `Colour`. +//! For anything more complex than plain foreground color changes, you need to +//! construct `Style` values themselves, rather than beginning with a `Color`. //! You can do this by chaining methods based on a new `Style`, created with //! [`Style::new()`]. Each method creates a new style that has that specific //! property set. For example: //! //! ``` -//! use ansi_term::Style; +//! use nu_ansi_term::Style; //! //! println!("How about some {} and {}?", //! Style::new().bold().paint("bold"), //! Style::new().underline().paint("underline")); //! ``` //! -//! 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 +//! For brevity, these methods have also been implemented for `Color` values, +//! so you can give your styles a foreground color without having to begin with //! an empty `Style` value: //! //! ``` -//! use ansi_term::Colour::{Blue, Yellow}; +//! use nu_ansi_term::Color::{Blue, Yellow}; //! //! println!("Demonstrating {} and {}!", //! Blue.bold().paint("blue bold"), @@ -72,68 +72,68 @@ //! //! The complete list of styles you can use are: [`bold`], [`dimmed`], [`italic`], //! [`underline`], [`blink`], [`reverse`], [`hidden`], [`strikethrough`], and [`on`] for -//! background colours. +//! background colors. //! //! In some cases, you may find it easier to change the foreground on an -//! existing `Style` rather than starting from the appropriate `Colour`. +//! existing `Style` rather than starting from the appropriate `Color`. //! You can do this using the [`fg`] method: //! //! ``` -//! use ansi_term::Style; -//! use ansi_term::Colour::{Blue, Cyan, Yellow}; +//! use nu_ansi_term::Style; +//! use nu_ansi_term::Color::{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!")); //! ``` //! -//! 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: +//! You can turn a `Color` into a `Style` with the [`normal`] method. +//! This will produce the exact same `AnsiString` as if you just used the +//! `paint` method on the `Color` 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. //! //! ``` -//! use ansi_term::Style; -//! use ansi_term::Colour::Red; +//! use nu_ansi_term::Style; +//! use nu_ansi_term::Color::Red; //! //! Red.normal().paint("yet another red string"); //! Style::default().paint("a completely regular string"); //! ``` //! //! -//! ## Extended colours +//! ## Extended colors //! -//! You can access the extended range of 256 colours by using the `Colour::Fixed` -//! variant, which takes an argument of the colour number to use. This can be -//! included wherever you would use a `Colour`: +//! You can access the extended range of 256 colors by using the `Color::Fixed` +//! variant, which takes an argument of the color number to use. This can be +//! included wherever you would use a `Color`: //! //! ``` -//! use ansi_term::Colour::Fixed; +//! use nu_ansi_term::Color::Fixed; //! //! Fixed(134).paint("A sort of light purple"); //! Fixed(221).on(Fixed(124)).paint("Mustard in the ketchup"); //! ``` //! //! The first sixteen of these values are the same as the normal and bold -//! standard colour variants. There’s nothing stopping you from using these as -//! `Fixed` colours instead, but there’s nothing to be gained by doing so +//! standard color variants. There’s nothing stopping you from using these as +//! `Fixed` colors instead, but there’s nothing to be gained by doing so //! either. //! -//! You can also access full 24-bit colour by using the `Colour::RGB` variant, +//! You can also access full 24-bit color by using the `Color::Rgb` variant, //! which takes separate `u8` arguments for red, green, and blue: //! //! ``` -//! use ansi_term::Colour::RGB; +//! use nu_ansi_term::Color::Rgb; //! -//! RGB(70, 130, 180).paint("Steel blue"); +//! Rgb(70, 130, 180).paint("Steel blue"); //! ``` //! -//! ## Combining successive coloured strings +//! ## Combining successive colored strings //! //! The benefit of writing ANSI escape codes to the terminal is that they -//! *stack*: you do not need to end every coloured string with a reset code if +//! *stack*: you do not need to end every colored string with a reset code if //! the text that follows it is of a similar style. For example, if you want to //! have some blue text followed by some blue bold text, it’s possible to send //! the ANSI code for blue, followed by the ANSI code for bold, and finishing @@ -141,8 +141,8 @@ //! strings. //! //! This crate can optimise the ANSI codes that get printed in situations like -//! this, making life easier for your terminal renderer. The [`ANSIStrings`] -//! type takes a slice of several [`ANSIString`] values, and will iterate over +//! this, making life easier for your terminal renderer. The [`AnsiStrings`] +//! type takes a slice of several [`AnsiString`] values, and will iterate over //! each of them, printing only the codes for the styles that need to be updated //! as part of its formatting routine. //! @@ -150,25 +150,25 @@ //! red bold text inside some red, but not bold, brackets: //! //! ``` -//! use ansi_term::Colour::Red; -//! use ansi_term::{ANSIString, ANSIStrings}; +//! use nu_ansi_term::Color::Red; +//! use nu_ansi_term::{AnsiString, AnsiStrings}; //! //! let some_value = format!("{:b}", 42); -//! let strings: &[ANSIString<'static>] = &[ +//! let strings: &[AnsiString<'static>] = &[ //! Red.paint("["), //! Red.bold().paint(some_value), //! Red.paint("]"), //! ]; //! -//! println!("Value: {}", ANSIStrings(strings)); +//! println!("Value: {}", AnsiStrings(strings)); //! ``` //! //! There are several things to note here. Firstly, the [`paint`] method can take -//! *either* an owned [`String`] or a borrowed [`&str`]. Internally, an [`ANSIString`] +//! *either* an owned [`String`] or a borrowed [`&str`]. Internally, an [`AnsiString`] //! holds a copy-on-write ([`Cow`]) string value to deal with both owned and //! borrowed strings at the same time. This is used here to display a `String`, //! the result of the `format!` call, using the same mechanism as some -//! statically-available `&str` slices. Secondly, that the [`ANSIStrings`] value +//! statically-available `&str` slices. Secondly, that the [`AnsiStrings`] value //! works in the same way as its singular counterpart, with a [`Display`] //! implementation that only performs the formatting when required. //! @@ -176,25 +176,25 @@ //! //! This library also supports formatting `\[u8]` byte strings; this supports //! applications working with text in an unknown encoding. [`Style`] and -//! [`Colour`] support painting `\[u8]` values, resulting in an [`ANSIByteString`]. +//! [`Color`] support painting `\[u8]` values, resulting in an [`AnsiByteString`]. //! 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`]: //! //! ``` -//! use ansi_term::Colour::Green; +//! use nu_ansi_term::Color::Green; //! //! 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: +//! Similarly, the type [`AnsiByteStrings`] supports writing a list of +//! [`AnsiByteString`] values with minimal escape sequences: //! //! ``` -//! use ansi_term::Colour::Green; -//! use ansi_term::ANSIByteStrings; +//! use nu_ansi_term::Color::Green; +//! use nu_ansi_term::AnsiByteStrings; //! -//! ANSIByteStrings(&[ +//! AnsiByteStrings(&[ //! Green.paint("user data 1\n".as_bytes()), //! Green.bold().paint("user data 2\n".as_bytes()), //! ]).write_to(&mut std::io::stdout()).unwrap(); @@ -209,14 +209,14 @@ //! [`Style`]: struct.Style.html //! [`Style::new()`]: struct.Style.html#method.new //! [`Color`]: enum.Color.html -//! [`Colour`]: enum.Colour.html -//! [`ANSIString`]: type.ANSIString.html -//! [`ANSIStrings`]: type.ANSIStrings.html -//! [`ANSIByteString`]: type.ANSIByteString.html -//! [`ANSIByteStrings`]: type.ANSIByteStrings.html -//! [`write_to`]: type.ANSIByteString.html#method.write_to -//! [`paint`]: type.ANSIByteString.html#method.write_to -//! [`normal`]: enum.Colour.html#method.normal +//! [`Color`]: enum.Color.html +//! [`AnsiString`]: type.AnsiString.html +//! [`AnsiStrings`]: type.AnsiStrings.html +//! [`AnsiByteString`]: type.AnsiByteString.html +//! [`AnsiByteStrings`]: type.AnsiByteStrings.html +//! [`write_to`]: type.AnsiByteString.html#method.write_to +//! [`paint`]: type.AnsiByteString.html#method.write_to +//! [`normal`]: enum.Color.html#method.normal //! //! [`bold`]: struct.Style.html#method.bold //! [`dimmed`]: struct.Style.html#method.dimmed @@ -229,16 +229,14 @@ //! [`fg`]: struct.Style.html#method.fg //! [`on`]: struct.Style.html#method.on -#![crate_name = "ansi_term"] +#![crate_name = "nu_ansi_term"] #![crate_type = "rlib"] -#![crate_type = "dylib"] - #![warn(missing_copy_implementations)] -#![warn(missing_docs)] +// #![warn(missing_docs)] #![warn(trivial_casts, trivial_numeric_casts)] -#![warn(unused_extern_crates, unused_qualifications)] +// #![warn(unused_extern_crates, unused_qualifications)] -#[cfg(target_os="windows")] +#[cfg(target_os = "windows")] extern crate winapi; #[cfg(test)] #[macro_use] @@ -247,14 +245,11 @@ extern crate doc_comment; #[cfg(test)] doctest!("../README.md"); -mod ansi; -pub use ansi::{Prefix, Infix, Suffix}; +pub mod ansi; +pub use ansi::{Infix, Prefix, Suffix}; mod style; -pub use style::{Colour, Style}; - -/// Color is a type alias for `Colour`. -pub use Colour as Color; +pub use style::{Color, Style}; mod difference; mod display; @@ -269,3 +264,9 @@ mod util; pub use util::*; mod debug; + +pub mod gradient; +pub use gradient::*; + +mod rgb; +pub use rgb::*; |