Skip to content

Commit

Permalink
refactor: rename to ansiterm
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro-Alessio Gierens <sandro@gierens.de>
  • Loading branch information
gierens committed Sep 6, 2023
1 parent 61a1faa commit 7506d78
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 83 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[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) <ryan.havvy@gmail.com>", "Josh Triplett <josh@joshtriplett.org>" ]
documentation = "https://docs.rs/ansi_term"
documentation = "https://docs.rs/ansiterm"
homepage = "https://github.com/ogham/rust-ansi-term"
license = "MIT"
readme = "README.md"
version = "0.12.1"
repository = "https://github.com/ogham/rust-ansi-term"

[lib]
name = "ansi_term"
name = "ansiterm"

[features]
derive_serde_style = ["serde"]
Expand Down
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"));
```
Expand All @@ -36,15 +39,15 @@ 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();
```

**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
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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!"));
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
```
Expand All @@ -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>] = &[
Expand All @@ -160,16 +163,16 @@ 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();
```

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()),
Expand Down
4 changes: 2 additions & 2 deletions examples/256_colours.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions examples/basic_colours.rs
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
4 changes: 2 additions & 2 deletions examples/rgb_colours.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -252,7 +252,7 @@ impl Colour {
/// # Examples
///
/// ```
/// use ansi_term::Colour::Green;
/// use ansiterm::Colour::Green;
///
/// assert_eq!("\x1b[0m",
/// Green.suffix().to_string());
Expand All @@ -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());
Expand All @@ -287,7 +287,7 @@ impl Colour {
/// # Examples
///
/// ```
/// use ansi_term::Colour::Purple;
/// use ansiterm::Colour::Purple;
///
/// assert_eq!("\x1b[0m",
/// Purple.suffix().to_string());
Expand Down Expand Up @@ -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));
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }",
Expand Down
10 changes: 5 additions & 5 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where <S as ToOwned>::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();
Expand Down Expand Up @@ -73,15 +73,15 @@ where <S as ToOwned>::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");
Expand Down Expand Up @@ -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]
Expand Down
Loading

0 comments on commit 7506d78

Please sign in to comment.