File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,4 @@ harness = false
40
40
41
41
[features ]
42
42
default = []
43
+ testing-colors = []
Original file line number Diff line number Diff line change 40
40
//! options, such as color, or margins.
41
41
//!
42
42
//! Finally, `impl Display` into a final `String` output.
43
+ //!
44
+ //! # features
45
+ //! - `testing-colors` - Makes [Renderer::styled] colors OS independent, which
46
+ //! allows for easier testing when testing colored output. It should be added as
47
+ //! a feature in `[dev-dependencies]`, which can be done with the following command:
48
+ //! ```text
49
+ //! cargo add annotate-snippets --dev --feature testing-colors
50
+ //! ```
51
+ //!
43
52
44
53
pub mod renderer;
45
54
mod snippet;
Original file line number Diff line number Diff line change @@ -61,16 +61,20 @@ impl Renderer {
61
61
}
62
62
63
63
/// Default terminal styling
64
+ ///
65
+ /// # Note
66
+ /// When testing styled terminal output, see the [`testing-colors` feature](crate#features)
64
67
pub const fn styled ( ) -> Self {
65
- const BRIGHT_BLUE : Style = if cfg ! ( windows) {
68
+ const USE_WINDOWS_COLORS : bool = cfg ! ( windows) && !cfg ! ( feature = "testing-colors" ) ;
69
+ const BRIGHT_BLUE : Style = if USE_WINDOWS_COLORS {
66
70
AnsiColor :: BrightCyan . on_default ( )
67
71
} else {
68
72
AnsiColor :: BrightBlue . on_default ( )
69
73
} ;
70
74
Self {
71
75
stylesheet : Stylesheet {
72
76
error : AnsiColor :: BrightRed . on_default ( ) . effects ( Effects :: BOLD ) ,
73
- warning : if cfg ! ( windows ) {
77
+ warning : if USE_WINDOWS_COLORS {
74
78
AnsiColor :: BrightYellow . on_default ( )
75
79
} else {
76
80
AnsiColor :: Yellow . on_default ( )
@@ -80,7 +84,7 @@ impl Renderer {
80
84
note : AnsiColor :: BrightGreen . on_default ( ) . effects ( Effects :: BOLD ) ,
81
85
help : AnsiColor :: BrightCyan . on_default ( ) . effects ( Effects :: BOLD ) ,
82
86
line_no : BRIGHT_BLUE . effects ( Effects :: BOLD ) ,
83
- emphasis : if cfg ! ( windows ) {
87
+ emphasis : if USE_WINDOWS_COLORS {
84
88
AnsiColor :: BrightWhite . on_default ( )
85
89
} else {
86
90
Style :: new ( )
You can’t perform that action at this time.
0 commit comments