-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from epage/anstream
feat!: Always print color when color is enabled
- Loading branch information
Showing
18 changed files
with
169 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
msrv = "1.60.0" # MSRV | ||
msrv = "1.64.0" # MSRV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
[workspace] | ||
members = ["crates/*"] | ||
resolver = "2" | ||
|
||
[workspace.package] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
rust-version = "1.64.0" # MSRV | ||
include = [ | ||
"build.rs", | ||
"src/**/*", | ||
"Cargo.toml", | ||
"LICENSE*", | ||
"README.md", | ||
"benches/**/*", | ||
"examples/**/*" | ||
] | ||
|
||
[package] | ||
name = "predicates" | ||
version = "2.1.5" | ||
description = "An implementation of boolean-valued predicate functions." | ||
authors = ["Nick Stevens <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/assert-rs/predicates-rs" | ||
homepage = "https://github.com/assert-rs/predicates-rs" | ||
documentation = "https://docs.rs/predicates" | ||
readme = "README.md" | ||
categories = ["data-structures", "rust-patterns"] | ||
keywords = ["predicate", "boolean", "combinatorial", "match", "logic"] | ||
edition = "2021" | ||
rust-version = "1.60.0" # MSRV | ||
include = [ | ||
"src/**/*", | ||
"Cargo.toml", | ||
"LICENSE*", | ||
"README.md", | ||
"examples/**/*" | ||
] | ||
license.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
include.workspace = true | ||
|
||
[package.metadata.release] | ||
pre-release-replacements = [ | ||
|
@@ -41,15 +50,13 @@ normalize-line-endings = { version = "0.3.0", optional = true } | |
regex = { version="1.0", optional = true } | ||
float-cmp = { version="0.9", optional = true } | ||
itertools = "0.10" | ||
yansi = { version = "0.5.1", optional = true } | ||
concolor = { version = "0.0.12", optional = true } | ||
anstyle = "0.3.0" | ||
|
||
[dev-dependencies] | ||
predicates-tree = { version = "1.0", path = "crates/tree" } | ||
|
||
[features] | ||
default = ["diff", "regex", "float-cmp", "normalize-line-endings"] | ||
default = ["diff", "regex", "float-cmp", "normalize-line-endings", "color"] | ||
diff = ["dep:difflib"] | ||
unstable = [] | ||
color = ["dep:yansi", "dep:concolor", "concolor?/std"] | ||
color-auto = ["color", "concolor?/auto"] | ||
color = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,13 @@ name = "predicates-core" | |
version = "1.0.5" | ||
description = "An API for boolean-valued predicate functions." | ||
authors = ["Nick Stevens <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
repository = "https://github.com/assert-rs/predicates-rs/tree/master/crates/core" | ||
homepage = "https://github.com/assert-rs/predicates-rs/tree/master/crates/core" | ||
documentation = "https://docs.rs/predicates-core" | ||
categories = ["data-structures", "rust-patterns"] | ||
keywords = ["predicate", "boolean", "combinatorial", "match", "logic"] | ||
edition = "2021" | ||
rust-version = "1.60.0" # MSRV | ||
include = [ | ||
"src/**/*", | ||
"Cargo.toml", | ||
"LICENSE*", | ||
"README.md", | ||
"examples/**/*" | ||
] | ||
license.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
include.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,26 +3,20 @@ name = "predicates-tree" | |
version = "1.0.7" | ||
authors = ["Nick Stevens <[email protected]>"] | ||
description = "Render boolean-valued predicate functions results as a tree." | ||
license = "MIT OR Apache-2.0" | ||
readme = "README.md" | ||
repository = "https://github.com/assert-rs/predicates-rs/tree/master/crates/tree" | ||
homepage = "https://github.com/assert-rs/predicates-rs/tree/master/crates/tree" | ||
documentation = "https://docs.rs/predicates-tree" | ||
categories = ["data-structures", "rust-patterns"] | ||
keywords = ["predicate", "boolean", "combinatorial", "match", "logic"] | ||
edition = "2021" | ||
rust-version = "1.60.0" # MSRV | ||
include = [ | ||
"src/**/*", | ||
"Cargo.toml", | ||
"LICENSE*", | ||
"README.md", | ||
"examples/**/*" | ||
] | ||
license.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
include.workspace = true | ||
|
||
[dependencies] | ||
predicates-core = { version = "1.0", path = "../core" } | ||
termtree = "0.4" | ||
termtree = "0.4.1" | ||
|
||
[dev-dependencies] | ||
predicates = { version = "2.1", path = "../..", features = ["color-auto"] } | ||
predicates = { version = "2.1", path = "../..", features = ["color"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,69 @@ | ||
#[derive(Copy, Clone, Debug, Default)] | ||
pub(crate) struct Palette { | ||
pub(crate) description: styled::Style, | ||
pub(crate) var: styled::Style, | ||
pub(crate) expected: styled::Style, | ||
description: anstyle::Style, | ||
var: anstyle::Style, | ||
expected: anstyle::Style, | ||
} | ||
|
||
impl Palette { | ||
#[cfg(feature = "color")] | ||
pub(crate) fn current() -> Self { | ||
if concolor::get(concolor::Stream::Either).ansi_color() { | ||
pub(crate) fn new(alternate: bool) -> Self { | ||
if alternate && cfg!(feature = "color") { | ||
Self { | ||
description: styled::Style(yansi::Style::new(yansi::Color::Blue).bold()), | ||
var: styled::Style(yansi::Style::new(yansi::Color::Red).bold()), | ||
expected: styled::Style(yansi::Style::new(yansi::Color::Green).bold()), | ||
description: anstyle::AnsiColor::Blue | anstyle::Effects::BOLD, | ||
var: anstyle::AnsiColor::Red | anstyle::Effects::BOLD, | ||
expected: anstyle::AnsiColor::Green | anstyle::Effects::BOLD, | ||
} | ||
} else { | ||
Self::default() | ||
Self::plain() | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "color"))] | ||
pub(crate) fn current() -> Self { | ||
Self::default() | ||
pub(crate) fn plain() -> Self { | ||
Self { | ||
description: Default::default(), | ||
var: Default::default(), | ||
expected: Default::default(), | ||
} | ||
} | ||
|
||
pub(crate) fn description<D: std::fmt::Display>(self, display: D) -> Styled<D> { | ||
Styled::new(display, self.description) | ||
} | ||
} | ||
|
||
#[cfg(feature = "color")] | ||
mod styled { | ||
#[derive(Copy, Clone, Debug, Default)] | ||
pub(crate) struct Style(pub(crate) yansi::Style); | ||
pub(crate) fn var<D: std::fmt::Display>(self, display: D) -> Styled<D> { | ||
Styled::new(display, self.var) | ||
} | ||
|
||
impl Style { | ||
pub(crate) fn paint<T: std::fmt::Display>(self, item: T) -> impl std::fmt::Display { | ||
self.0.paint(item) | ||
} | ||
pub(crate) fn expected<D: std::fmt::Display>(self, display: D) -> Styled<D> { | ||
Styled::new(display, self.expected) | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "color"))] | ||
mod styled { | ||
#[derive(Copy, Clone, Debug, Default)] | ||
pub(crate) struct Style; | ||
#[derive(Debug)] | ||
pub(crate) struct Styled<D> { | ||
display: D, | ||
style: anstyle::Style, | ||
} | ||
|
||
impl Style { | ||
pub(crate) fn paint<T: std::fmt::Display>(self, item: T) -> impl std::fmt::Display { | ||
item | ||
impl<D: std::fmt::Display> Styled<D> { | ||
pub(crate) fn new(display: D, style: anstyle::Style) -> Self { | ||
Self { display, style } | ||
} | ||
} | ||
|
||
impl<D: std::fmt::Display> std::fmt::Display for Styled<D> { | ||
#[inline] | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
if f.alternate() { | ||
write!( | ||
f, | ||
"{}{}{}", | ||
self.style.render(), | ||
self.display, | ||
self.style.render_reset() | ||
) | ||
} else { | ||
self.display.fmt(f) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.