Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nushell/nu-ansi-term
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.46.0
Choose a base ref
...
head repository: nushell/nu-ansi-term
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.47.0
Choose a head ref

Commits on Sep 12, 2022

  1. Add @fdncred 's changelog (#9)

    * reconstruct and create a changelog
    
    * add a changelog (#8)
    
    * add a changelog
    
    * really clippy?
    
    * oops, forgot this change
    
    * Update CHANGELOG.md
    
    Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
    sholderbach and fdncred authored Sep 12, 2022
    Copy the full SHA
    736e913 View commit details

Commits on Sep 20, 2022

  1. Update README.md (#10)

    Colour was changed to Color (not Color -> Color). Fixed two other uses of British spelling
    j16r authored Sep 20, 2022
    Copy the full SHA
    f394403 View commit details

Commits on Sep 29, 2022

  1. Update README.md (#11)

    update cargo.toml to reflect registered crate name is `nu-ansi-term` and not 'nu_ansi_term'
    bwinchester authored Sep 29, 2022
    Copy the full SHA
    cd686ec View commit details

Commits on Oct 6, 2022

  1. Allow dereferencing AnsiString as underlying string (#12)

    Adds `AnsiGenericString::as_str()`
    richardhozak authored Oct 6, 2022
    Copy the full SHA
    67eb4e4 View commit details

Commits on Oct 12, 2022

  1. Implement the provided operators for Rgb manually (#13)

    * Implement the provided operators for `Rgb` manually
    
    This removes the overload dependency by implementing the operators for the Rgb struct manually.
    nickelc authored Oct 12, 2022
    Copy the full SHA
    7fdaa4a View commit details

Commits on Jan 22, 2023

  1. Copy the full SHA
    a146687 View commit details

Commits on Mar 6, 2023

  1. Replace winapi crate with windows crate (#16)

    * Replace winapi crate with windows crate
    
    * Fix clippy lifetime warning
    
    * Format utils.rs
    kgrech authored Mar 6, 2023
    Copy the full SHA
    cad5cf5 View commit details
  2. Replace unmaintained/outdated GitHub Actions (#17)

    The `actions-rs/*` actions are replaced with `dtolnay/rust-toolchain`
    and plain cargo commands.
    nickelc authored Mar 6, 2023
    Copy the full SHA
    ebc2bdd View commit details
  3. Update windows to 0.44

    nickelc authored and sholderbach committed Mar 6, 2023
    Copy the full SHA
    2f30ef5 View commit details
  4. Copy the full SHA
    223d6aa View commit details
  5. Copy the full SHA
    d29cc7e View commit details
  6. Use the windows-sys crate (#19)

    The `windows-sys` crate is only 2.5MB, compared to 11.5MB for the `windows` crate.
    nickelc authored Mar 6, 2023
    Copy the full SHA
    2a7ffde View commit details
  7. Enable ansi support for examples under windows (#20)

    * Enable ansi support for examples under windows
    
    * Run the `256_colors` example in the build jobs
    nickelc authored Mar 6, 2023
    Copy the full SHA
    555d4e1 View commit details
  8. Rust Edition 2021 (#21)

    jaudiger authored Mar 6, 2023
    Copy the full SHA
    6b88253 View commit details
  9. Copy the full SHA
    f3be6e3 View commit details

Commits on Mar 7, 2023

  1. Copy the full SHA
    085dc58 View commit details

Commits on Mar 8, 2023

  1. Improve changelog (#25)

    List all versions on crates.io with release dates and newest changes first.
    nickelc authored Mar 8, 2023
    Copy the full SHA
    e316a12 View commit details
  2. Copy the full SHA
    9e85aa5 View commit details

Commits on Mar 11, 2023

  1. Copy the full SHA
    2e06cc0 View commit details
  2. Set MSRV to 1.62.1 in package metadata (#30)

    clippy respects the rust version set in the package metadata and
    wouldn't break the build job for newer rust features.
    nickelc authored Mar 11, 2023
    Copy the full SHA
    9fdb618 View commit details
  3. Add const on some functions (#22)

    Requires MSRV 1.61
    jaudiger authored Mar 11, 2023
    Copy the full SHA
    dcb7273 View commit details

Commits on Mar 13, 2023

  1. Copy the full SHA
    7a842de View commit details
  2. Bump version for 0.47 release. (#32)

    Will be used starting with `reedline` 0.17 and `nu` 0.77.
    sholderbach authored Mar 13, 2023
    Copy the full SHA
    4fdb684 View commit details
Showing with 350 additions and 145 deletions.
  1. +9 −22 .github/workflows/ci.yml
  2. +17 −1 .gitignore
  3. +82 −0 CHANGELOG.md
  4. +16 −10 Cargo.toml
  5. +4 −6 README.md
  6. +3 −1 examples/256_colors.rs
  7. +3 −1 examples/basic_colors.rs
  8. +3 −0 examples/gradient_colors.rs
  9. +3 −1 examples/rgb_colors.rs
  10. +3 −3 src/ansi.rs
  11. +0 −1 src/debug.rs
  12. +1 −1 src/difference.rs
  13. +10 −5 src/display.rs
  14. +1 −0 src/gradient.rs
  15. +2 −8 src/lib.rs
  16. +162 −40 src/rgb.rs
  17. +13 −18 src/style.rs
  18. +1 −5 src/util.rs
  19. +17 −22 src/windows.rs
31 changes: 9 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -4,36 +4,23 @@ name: Continuous integration

jobs:
ci:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- stable
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy

- uses: actions-rs/cargo@v1
with:
command: build

- uses: actions-rs/cargo@v1
with:
command: test

- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
- run: cargo build --all-features
- run: cargo test --all-features
- run: cargo fmt --check --all
- run: cargo clippy -- -D warnings
- run: cargo run --example 256_colors
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
target
Cargo.lock
Cargo.lock

# JetBrains' IDE items
.idea/*

# VSCode's IDE items
.vscode/*

# Helix configuration folder
.helix/*
.helix

# Visual Studio
.vs/*
*.rsproj
*.rsproj.user
*.sln
82 changes: 82 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Changelog

## v0.47.0 (Unreleased)

### Breaking changes

- Bumped minimum supported Rust version (MSRV) to 1.62.1
- Change of `Color::default()` value to the ANSI default color `Color::Default` (code `39` and `49` for foreground and background respectively). This replaces `Color::White` as the default value.

### Other changes

- `const`ification of several functions and methods.
- Improved CI workflow.
- Updated to Rust edition 2021.
- Replaced `winapi` dependency with `windows-sys`.
- Removed `overload` dependency.
- Added `AnsiGenericString::as_str()` to allow access to the underlying string.
- Fixed typos in README.
- Added `CHANGELOG.md` for changes since forking `ansi_term`.

## v0.46.0 (2022-06-03)

- Removed `impl Deref` for `AnsiGenericString`.
- Improved README headings.

## v0.45.1 (2022-03-27)

- Added `Color::Default` enum variant with ansi codes `39` and `49` for foreground & background.

## v0.45.0 (2022-03-16)

- Fixed examples in README.
- Fixed typos in documentation.
- Renamed `ANSIByteStrings` to `AnsiByteStrings`.
- Added GitHub Actions workflow.
- Changed authors metadata.
- Updated license

## v0.43.0 (2022-01-18)

- Fixed clippy warning.

## v0.40.0 (2021-11-16)

- Fixed clippy warning.

## v0.38.0 (2021-10-05)

- Removed `itertools` dependency.

## v0.37.0 (2021-09-14)

- Fixed clippy warnings.

## v0.31.0 (2021-05-11)

- Implemented `Default` trait for `Color` returning `Color::White`.
- Added helpers for gradients.
- Fixed clippy warning.

## v0.30.0 (2021-04-21)

- Export `ansi` module to expose `ansi::RESET`.

## v0.29.0 (2021-03-30)

- Renamed `Color::RGB` enum variant to `Color::Rgb`.
- Renamed `ANSIByteString` to `AnsiByteString`.
- Renamed `ANSIGenericString` to `AnsiGenericString`.
- Renamed `ANSIGenericStrings` to `AnsiGenericStrings`.
- Renamed `ANSIString` to `AnsiString`.
- Renamed `ANSIStrings` to `AnsiStrings`.

## v0.28.0 (2021-03-09)

- Forked `ansi_term` as `nu-ansi-term`.
- Added Nushell project contributors to the authors.
- Updated README.md.
- Renamed `Colour` to `Color`.
- Renamed some files ending in `colour` to `color`.
- Added "bright" colors ansi 90-97 (foreground) and 100-107 (background).
- Ran cargo fmt
26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -6,10 +6,11 @@ authors = [
"The Nushell Project Developers",
]
description = "Library for ANSI terminal colors and styles (bold, underline)"
edition = "2018"
edition = "2021"
rust-version = "1.62.1"
license = "MIT"
name = "nu-ansi-term"
version = "0.46.0"
version = "0.47.0"
repository = "https://github.com/nushell/nu-ansi-term"

[lib]
@@ -19,16 +20,21 @@ doctest = true
derive_serde_style = ["serde"]

[dependencies]
overload = "0.1.1"
serde = { version="1.0.90", features=["derive"], optional=true }
serde = { version="1.0.152", features=["derive"], optional=true }

[target.'cfg(target_os="windows")'.dependencies.winapi]
version = "0.3.4"
features = ["consoleapi", "errhandlingapi", "fileapi", "handleapi", "processenv"]
[target.'cfg(windows)'.dependencies.windows]
version = "0.45.0"
package = "windows-sys"
features = [
"Win32_Foundation",
"Win32_System_Console",
"Win32_Storage_FileSystem",
"Win32_Security"
]

[dev-dependencies]
doc-comment = "0.3"
regex = "1.1.9"
doc-comment = "0.3.3"
regex = "1.7.1"

[dev-dependencies.serde_json]
version = "1.0.39"
version = "1.0.94"
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nu-ansi-term

> This is a copy of rust-ansi-term but with Color change to Color and light foreground colors added (90-97) as well as light background colors added (100-107).
> This is a copy of rust-ansi-term but with Colour change to Color and light foreground colors added (90-97) as well as light background colors added (100-107).
This is a library for controlling colors and formatting, such as red bold text or blue underlined text, on ANSI terminals.

@@ -12,7 +12,7 @@ This crate works with [Cargo](http://crates.io). Add the following to your `Carg

```toml
[dependencies]
nu_ansi_term = "0.46"
nu-ansi-term = "0.47"
```

## Basic usage
@@ -23,8 +23,6 @@ A `Style` holds stylistic information: foreground and background colors, whether
The `Color` enum represents the available colors.
And an `AnsiString` is a string paired with a `Style`.

`Color` is also available as an alias to `Color`.

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:

@@ -127,9 +125,9 @@ use nu_ansi_term::Color::RGB;
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 the text that follows it is of a similar style.
The benefit of writing ANSI escape codes to the terminal is that they _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 with a reset code without having to have an extra one between the two strings.

This crate can optimise the ANSI codes that get printed in situations like this, making life easier for your terminal renderer.
4 changes: 3 additions & 1 deletion examples/256_colors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate nu_ansi_term;
use nu_ansi_term::Color;

// This example prints out the 256 colors.
@@ -10,6 +9,9 @@ use nu_ansi_term::Color;
// - 232 to 255 are shades of grey.

fn main() {
#[cfg(windows)]
nu_ansi_term::enable_ansi_support().unwrap();

// First two lines
for c in 0..8 {
glow(c, c != 0);
4 changes: 3 additions & 1 deletion examples/basic_colors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
extern crate nu_ansi_term;
use nu_ansi_term::{Color::*, Style};

// This example prints out the 16 basic colors.

fn main() {
#[cfg(windows)]
nu_ansi_term::enable_ansi_support().unwrap();

let normal = Style::default();

println!("{} {}", normal.paint("Normal"), normal.bold().paint("bold"));
3 changes: 3 additions & 0 deletions examples/gradient_colors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use nu_ansi_term::{build_all_gradient_text, Color, Gradient, Rgb, TargetGround};

fn main() {
#[cfg(windows)]
nu_ansi_term::enable_ansi_support().unwrap();

let text = "lorem ipsum quia dolor sit amet, consectetur, adipisci velit";

// a gradient from hex colors
4 changes: 3 additions & 1 deletion examples/rgb_colors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate nu_ansi_term;
use nu_ansi_term::{Color, Style};

// This example prints out a color gradient in a grid by calculating each
@@ -9,6 +8,9 @@ const WIDTH: i32 = 80;
const HEIGHT: i32 = 24;

fn main() {
#[cfg(windows)]
nu_ansi_term::enable_ansi_support().unwrap();

for row in 0..HEIGHT {
for col in 0..WIDTH {
let r = (row * 255 / HEIGHT) as u8;
6 changes: 3 additions & 3 deletions src/ansi.rs
Original file line number Diff line number Diff line change
@@ -194,7 +194,7 @@ impl Style {
/// assert_eq!("",
/// style.prefix().to_string());
/// ```
pub fn prefix(self) -> Prefix {
pub const fn prefix(self) -> Prefix {
Prefix(self)
}

@@ -219,7 +219,7 @@ impl Style {
/// assert_eq!("",
/// style.infix(style).to_string());
/// ```
pub fn infix(self, next: Style) -> Infix {
pub const fn infix(self, next: Style) -> Infix {
Infix(self, next)
}

@@ -243,7 +243,7 @@ impl Style {
/// assert_eq!("",
/// style.suffix().to_string());
/// ```
pub fn suffix(self) -> Suffix {
pub const fn suffix(self) -> Suffix {
Suffix(self)
}
}
1 change: 0 additions & 1 deletion src/debug.rs
Original file line number Diff line number Diff line change
@@ -120,7 +120,6 @@ mod test {

#[test]
fn long_and_detailed() {
extern crate regex;
let expected_debug = "Style { fg(Blue), bold }";
let expected_pretty_repat = r##"(?x)
Style\s+\{\s+
2 changes: 1 addition & 1 deletion src/difference.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use super::Style;

/// When printing out one colored string followed by another, use one of
/// these rules to figure out which *extra* control codes need to be sent.
#[derive(PartialEq, Clone, Copy, Debug)]
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum Difference {
/// Print out the control codes specified by this style to end up looking
/// like the second string's styles.
15 changes: 10 additions & 5 deletions src/display.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use std::io;
/// An `AnsiGenericString` includes a generic string type and a `Style` to
/// display that string. `AnsiString` and `AnsiByteString` are aliases for
/// this type on `str` and `\[u8]`, respectively.
#[derive(PartialEq, Debug)]
#[derive(Eq, PartialEq, Debug)]
pub struct AnsiGenericString<'a, S: 'a + ToOwned + ?Sized>
where
<S as ToOwned>::Owned: fmt::Debug,
@@ -107,19 +107,24 @@ where
<S as ToOwned>::Owned: fmt::Debug,
{
/// Directly access the style
pub fn style_ref(&self) -> &Style {
pub const fn style_ref(&self) -> &Style {
&self.style
}

/// Directly access the style mutably
pub fn style_ref_mut(&mut self) -> &mut Style {
&mut self.style
}

// Directly access the underlying string
pub fn as_str(&self) -> &S {
self.string.as_ref()
}
}

/// A set of `AnsiGenericStrings`s collected together, in order to be
/// written with a minimum of control characters.
#[derive(Debug, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub struct AnsiGenericStrings<'a, S: 'a + ToOwned + ?Sized>(pub &'a [AnsiGenericString<'a, S>])
where
<S as ToOwned>::Owned: fmt::Debug,
@@ -131,7 +136,7 @@ pub type AnsiStrings<'a> = AnsiGenericStrings<'a, str>;

/// A function to construct an `AnsiStrings` instance.
#[allow(non_snake_case)]
pub fn AnsiStrings<'a>(arg: &'a [AnsiString<'a>]) -> AnsiStrings<'a> {
pub const fn AnsiStrings<'a>(arg: &'a [AnsiString<'a>]) -> AnsiStrings<'a> {
AnsiGenericStrings(arg)
}

@@ -141,7 +146,7 @@ pub type AnsiByteStrings<'a> = AnsiGenericStrings<'a, [u8]>;

/// A function to construct an `AnsiByteStrings` instance.
#[allow(non_snake_case)]
pub fn AnsiByteStrings<'a>(arg: &'a [AnsiByteString<'a>]) -> AnsiByteStrings<'a> {
pub const fn AnsiByteStrings<'a>(arg: &'a [AnsiByteString<'a>]) -> AnsiByteStrings<'a> {
AnsiGenericStrings(arg)
}

1 change: 1 addition & 0 deletions src/gradient.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ impl Gradient {
pub const fn new(start: Rgb, end: Rgb) -> Self {
Self { start, end }
}

pub const fn from_color_rgb(start: Color, end: Color) -> Self {
let start_grad = match start {
Color::Rgb(r, g, b) => Rgb { r, g, b },
Loading