@@ -38,6 +38,45 @@ pub use anstyle::*;
3838/// See [`Renderer::term_width`]
3939pub const DEFAULT_TERM_WIDTH : usize = 140 ;
4040
41+ const USE_WINDOWS_COLORS : bool = cfg ! ( windows) && !cfg ! ( feature = "testing-colors" ) ;
42+ const BRIGHT_BLUE : Style = if USE_WINDOWS_COLORS {
43+ AnsiColor :: BrightCyan . on_default ( )
44+ } else {
45+ AnsiColor :: BrightBlue . on_default ( )
46+ } ;
47+ /// [`Renderer::error`] applied by [`Renderer::styled`]
48+ pub const DEFAULT_ERROR_STYLE : Style = AnsiColor :: BrightRed . on_default ( ) . effects ( Effects :: BOLD ) ;
49+ /// [`Renderer::warning`] applied by [`Renderer::styled`]
50+ pub const DEFAULT_WARNING_STYLE : Style = if USE_WINDOWS_COLORS {
51+ AnsiColor :: BrightYellow . on_default ( )
52+ } else {
53+ AnsiColor :: Yellow . on_default ( )
54+ }
55+ . effects ( Effects :: BOLD ) ;
56+ /// [`Renderer::info`] applied by [`Renderer::styled`]
57+ pub const DEFAULT_INFO_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
58+ /// [`Renderer::note`] applied by [`Renderer::styled`]
59+ pub const DEFAULT_NOTE_STYLE : Style = AnsiColor :: BrightGreen . on_default ( ) . effects ( Effects :: BOLD ) ;
60+ /// [`Renderer::help`] applied by [`Renderer::styled`]
61+ pub const DEFAULT_HELP_STYLE : Style = AnsiColor :: BrightCyan . on_default ( ) . effects ( Effects :: BOLD ) ;
62+ /// [`Renderer::line_num`] applied by [`Renderer::styled`]
63+ pub const DEFAULT_LINE_NUM_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
64+ /// [`Renderer::emphasis`] applied by [`Renderer::styled`]
65+ pub const DEFAULT_EMPHASIS_STYLE : Style = if USE_WINDOWS_COLORS {
66+ AnsiColor :: BrightWhite . on_default ( )
67+ } else {
68+ Style :: new ( )
69+ }
70+ . effects ( Effects :: BOLD ) ;
71+ /// [`Renderer::none`] applied by [`Renderer::styled`]
72+ pub const DEFAULT_NONE_STYLE : Style = Style :: new ( ) ;
73+ /// [`Renderer::context`] applied by [`Renderer::styled`]
74+ pub const DEFAULT_CONTEXT_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
75+ /// [`Renderer::addition`] applied by [`Renderer::styled`]
76+ pub const DEFAULT_ADDITION_STYLE : Style = AnsiColor :: BrightGreen . on_default ( ) ;
77+ /// [`Renderer::removal`] applied by [`Renderer::styled`]
78+ pub const DEFAULT_REMOVAL_STYLE : Style = AnsiColor :: BrightRed . on_default ( ) ;
79+
4180/// The [Renderer] for a [`Report`]
4281///
4382/// The caller is expected to detect any relevant terminal features and configure the renderer,
@@ -94,35 +133,19 @@ impl Renderer {
94133 ///
95134 /// When testing styled terminal output, see the [`testing-colors` feature](crate#features)
96135 pub const fn styled ( ) -> Self {
97- const USE_WINDOWS_COLORS : bool = cfg ! ( windows) && !cfg ! ( feature = "testing-colors" ) ;
98- const BRIGHT_BLUE : Style = if USE_WINDOWS_COLORS {
99- AnsiColor :: BrightCyan . on_default ( )
100- } else {
101- AnsiColor :: BrightBlue . on_default ( )
102- } ;
103136 Self {
104137 stylesheet : Stylesheet {
105- error : AnsiColor :: BrightRed . on_default ( ) . effects ( Effects :: BOLD ) ,
106- warning : if USE_WINDOWS_COLORS {
107- AnsiColor :: BrightYellow . on_default ( )
108- } else {
109- AnsiColor :: Yellow . on_default ( )
110- }
111- . effects ( Effects :: BOLD ) ,
112- info : BRIGHT_BLUE . effects ( Effects :: BOLD ) ,
113- note : AnsiColor :: BrightGreen . on_default ( ) . effects ( Effects :: BOLD ) ,
114- help : AnsiColor :: BrightCyan . on_default ( ) . effects ( Effects :: BOLD ) ,
115- line_num : BRIGHT_BLUE . effects ( Effects :: BOLD ) ,
116- emphasis : if USE_WINDOWS_COLORS {
117- AnsiColor :: BrightWhite . on_default ( )
118- } else {
119- Style :: new ( )
120- }
121- . effects ( Effects :: BOLD ) ,
122- none : Style :: new ( ) ,
123- context : BRIGHT_BLUE . effects ( Effects :: BOLD ) ,
124- addition : AnsiColor :: BrightGreen . on_default ( ) ,
125- removal : AnsiColor :: BrightRed . on_default ( ) ,
138+ error : DEFAULT_ERROR_STYLE ,
139+ warning : DEFAULT_WARNING_STYLE ,
140+ info : DEFAULT_INFO_STYLE ,
141+ note : DEFAULT_NOTE_STYLE ,
142+ help : DEFAULT_HELP_STYLE ,
143+ line_num : DEFAULT_LINE_NUM_STYLE ,
144+ emphasis : DEFAULT_EMPHASIS_STYLE ,
145+ none : DEFAULT_NONE_STYLE ,
146+ context : DEFAULT_CONTEXT_STYLE ,
147+ addition : DEFAULT_ADDITION_STYLE ,
148+ removal : DEFAULT_REMOVAL_STYLE ,
126149 } ,
127150 ..Self :: plain ( )
128151 }
0 commit comments