File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,4 @@ harness = false
4040
4141[features ]
4242default = []
43+ testing-colors = []
Original file line number Diff line number Diff line change 4040//! options, such as color, or margins.
4141//!
4242//! 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+ //!
4352
4453pub mod renderer;
4554mod snippet;
Original file line number Diff line number Diff line change @@ -61,16 +61,20 @@ impl Renderer {
6161 }
6262
6363 /// Default terminal styling
64+ ///
65+ /// # Note
66+ /// When testing styled terminal output, see the [`testing-colors` feature](crate#features)
6467 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 {
6670 AnsiColor :: BrightCyan . on_default ( )
6771 } else {
6872 AnsiColor :: BrightBlue . on_default ( )
6973 } ;
7074 Self {
7175 stylesheet : Stylesheet {
7276 error : AnsiColor :: BrightRed . on_default ( ) . effects ( Effects :: BOLD ) ,
73- warning : if cfg ! ( windows ) {
77+ warning : if USE_WINDOWS_COLORS {
7478 AnsiColor :: BrightYellow . on_default ( )
7579 } else {
7680 AnsiColor :: Yellow . on_default ( )
@@ -80,7 +84,7 @@ impl Renderer {
8084 note : AnsiColor :: BrightGreen . on_default ( ) . effects ( Effects :: BOLD ) ,
8185 help : AnsiColor :: BrightCyan . on_default ( ) . effects ( Effects :: BOLD ) ,
8286 line_no : BRIGHT_BLUE . effects ( Effects :: BOLD ) ,
83- emphasis : if cfg ! ( windows ) {
87+ emphasis : if USE_WINDOWS_COLORS {
8488 AnsiColor :: BrightWhite . on_default ( )
8589 } else {
8690 Style :: new ( )
You can’t perform that action at this time.
0 commit comments