diff --git a/CHANGELOG.md b/CHANGELOG.md index b6605193..0f460225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate + +## [0.10.2] - 2024-02-29 + +### Added + +- Added `testing-colors` feature to remove platform-specific colors when testing + [#82](https://github.com/rust-lang/annotate-snippets-rs/pull/82) + ## [0.10.1] - 2024-01-04 ### Fixed @@ -85,7 +93,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Update the syntax to Rust 2018 idioms. (#4) -[Unreleased]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.10.1...HEAD +[Unreleased]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.10.2...HEAD +[0.10.2]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.10.1...0.10.2 [0.10.1]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.10.0...0.10.1 [0.10.0]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.9.2...0.10.0 [0.9.2]: https://github.com/rust-lang/annotate-snippets-rs/compare/0.9.1...0.9.2 diff --git a/Cargo.lock b/Cargo.lock index 221841ad..86766fc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "annotate-snippets" -version = "0.10.1" +version = "0.10.2" dependencies = [ "anstyle", "criterion", @@ -346,18 +346,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -447,18 +447,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.192" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", @@ -478,9 +478,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a39fd9da..05a34828 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "annotate-snippets" -version = "0.10.1" +version = "0.10.2" edition = "2021" rust-version = "1.73" # MSRV authors = ["Zibi Braniecki "] @@ -31,7 +31,7 @@ unicode-width = "0.1.11" criterion = "0.5.1" difference = "2.0.0" glob = "0.3.1" -serde = { version = "1.0.192", features = ["derive"] } +serde = { version = "1.0.196", features = ["derive"] } toml = "0.5.11" [[bench]] @@ -40,3 +40,4 @@ harness = false [features] default = [] +testing-colors = [] diff --git a/src/lib.rs b/src/lib.rs index 80eac530..03ffbb64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,15 @@ //! options, such as color, or margins. //! //! Finally, `impl Display` into a final `String` output. +//! +//! # features +//! - `testing-colors` - Makes [Renderer::styled] colors OS independent, which +//! allows for easier testing when testing colored output. It should be added as +//! a feature in `[dev-dependencies]`, which can be done with the following command: +//! ```text +//! cargo add annotate-snippets --dev --feature testing-colors +//! ``` +//! pub mod renderer; mod snippet; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index be81ebcc..b6108ce7 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -61,8 +61,12 @@ impl Renderer { } /// Default terminal styling + /// + /// # Note + /// When testing styled terminal output, see the [`testing-colors` feature](crate#features) pub const fn styled() -> Self { - const BRIGHT_BLUE: Style = if cfg!(windows) { + const USE_WINDOWS_COLORS: bool = cfg!(windows) && !cfg!(feature = "testing-colors"); + const BRIGHT_BLUE: Style = if USE_WINDOWS_COLORS { AnsiColor::BrightCyan.on_default() } else { AnsiColor::BrightBlue.on_default() @@ -70,7 +74,7 @@ impl Renderer { Self { stylesheet: Stylesheet { error: AnsiColor::BrightRed.on_default().effects(Effects::BOLD), - warning: if cfg!(windows) { + warning: if USE_WINDOWS_COLORS { AnsiColor::BrightYellow.on_default() } else { AnsiColor::Yellow.on_default() @@ -80,7 +84,7 @@ impl Renderer { note: AnsiColor::BrightGreen.on_default().effects(Effects::BOLD), help: AnsiColor::BrightCyan.on_default().effects(Effects::BOLD), line_no: BRIGHT_BLUE.effects(Effects::BOLD), - emphasis: if cfg!(windows) { + emphasis: if USE_WINDOWS_COLORS { AnsiColor::BrightWhite.on_default() } else { Style::new()