From bbe16cbe4b0a5f241b7c86ce05cd067416c2545a Mon Sep 17 00:00:00 2001 From: Kurt Lawrence Date: Wed, 17 Jan 2024 21:09:14 +1000 Subject: [PATCH 1/3] only run semver check when merging to mater --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50b98ce..1e1da8f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,7 @@ jobs: run: cargo test check-semver: name: Check semver compatibility + if: github.base_ref == 'master' runs-on: ubuntu-latest steps: - name: Checkout repository From b4c4df86711789c55ead24b9787b11df37913b24 Mon Sep 17 00:00:00 2001 From: Asthowen Date: Mon, 26 Feb 2024 12:51:55 +0100 Subject: [PATCH 2/3] Add support for arbitrary ANSI color --- src/color.rs | 4 ++++ src/lib.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/color.rs b/src/color.rs index b6d796e..95a37d4 100644 --- a/src/color.rs +++ b/src/color.rs @@ -21,6 +21,7 @@ pub enum Color { BrightCyan, BrightWhite, TrueColor { r: u8, g: u8, b: u8 }, + AnsiColor(u8), } fn truecolor_support() -> bool { @@ -56,6 +57,7 @@ impl Color { self.closest_color_euclidean().to_fg_str() } Color::TrueColor { r, g, b } => format!("38;2;{};{};{}", r, g, b).into(), + Color::AnsiColor(code) => format!("38;5;{}", code).into(), } } @@ -81,6 +83,7 @@ impl Color { self.closest_color_euclidean().to_bg_str() } Color::TrueColor { r, g, b } => format!("48;2;{};{};{}", r, g, b).into(), + Color::AnsiColor(code) => format!("48;5;{}", code).into(), } } @@ -195,6 +198,7 @@ impl Color { b: 255, }, TrueColor { r, g, b } => TrueColor { r, g, b }, + AnsiColor(color) => AnsiColor(color), } } } diff --git a/src/lib.rs b/src/lib.rs index 6942868..06dd9bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,6 +271,14 @@ pub trait Colorize { b: color.b, }) } + + fn ansi_color(self, color: T) -> ColoredString + where + Self: Sized, + T: Into, + { + self.color(Color::AnsiColor(color.into())) + } fn color>(self, color: S) -> ColoredString; // Background Colors fn on_black(self) -> ColoredString @@ -400,6 +408,13 @@ pub trait Colorize { b: color.b, }) } + fn on_ansi_color(self, color: T) -> ColoredString + where + Self: Sized, + T: Into, + { + self.on_color(Color::AnsiColor(color.into())) + } fn on_color>(self, color: S) -> ColoredString; // Styles fn clear(self) -> ColoredString; From 946cb90f6b7c1e0082ac1951583201c3581e8a2b Mon Sep 17 00:00:00 2001 From: Asthowen Date: Tue, 27 Feb 2024 08:33:02 +0100 Subject: [PATCH 3/3] Edit changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf9cda1..2b7f4ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - Changes to `Styles`: - Implemented bitwise operators `BitAnd`, `BitOr`, `BitXor`, and `Not` which all combine `Styles`\'s and output `Style`\'s. These can also take a `Style` as an operand. - Added additional testing for all of the above changes. -- Added methods `with_style` and `with_color_and_style` to `Colorize`. +- Added methods `with_style`, `with_color_and_style`, `ansi_color` and `on_ansi_color` to `Colorize`. # 2.1.0 * Impl From for ColoredString by @mahor1221 in https://github.com/colored-rs/colored/pull/126