@@ -38,6 +38,34 @@ pub use anstyle::*;
38
38
/// See [`Renderer::term_width`]
39
39
pub const DEFAULT_TERM_WIDTH : usize = 140 ;
40
40
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
+ const DEFAULT_ERROR_STYLE : Style = AnsiColor :: BrightRed . on_default ( ) . effects ( Effects :: BOLD ) ;
48
+ const DEFAULT_WARNING_STYLE : Style = if USE_WINDOWS_COLORS {
49
+ AnsiColor :: BrightYellow . on_default ( )
50
+ } else {
51
+ AnsiColor :: Yellow . on_default ( )
52
+ }
53
+ . effects ( Effects :: BOLD ) ;
54
+ const DEFAULT_INFO_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
55
+ const DEFAULT_NOTE_STYLE : Style = AnsiColor :: BrightGreen . on_default ( ) . effects ( Effects :: BOLD ) ;
56
+ const DEFAULT_HELP_STYLE : Style = AnsiColor :: BrightCyan . on_default ( ) . effects ( Effects :: BOLD ) ;
57
+ const DEFAULT_LINE_NUM_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
58
+ const DEFAULT_EMPHASIS_STYLE : Style = if USE_WINDOWS_COLORS {
59
+ AnsiColor :: BrightWhite . on_default ( )
60
+ } else {
61
+ Style :: new ( )
62
+ }
63
+ . effects ( Effects :: BOLD ) ;
64
+ const DEFAULT_NONE_STYLE : Style = Style :: new ( ) ;
65
+ const DEFAULT_CONTEXT_STYLE : Style = BRIGHT_BLUE . effects ( Effects :: BOLD ) ;
66
+ const DEFAULT_ADDITION_STYLE : Style = AnsiColor :: BrightGreen . on_default ( ) ;
67
+ const DEFAULT_REMOVAL_STYLE : Style = AnsiColor :: BrightRed . on_default ( ) ;
68
+
41
69
/// The [Renderer] for a [`Report`]
42
70
///
43
71
/// The caller is expected to detect any relevant terminal features and configure the renderer,
@@ -94,35 +122,19 @@ impl Renderer {
94
122
///
95
123
/// When testing styled terminal output, see the [`testing-colors` feature](crate#features)
96
124
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
- } ;
103
125
Self {
104
126
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 ( ) ,
127
+ error : DEFAULT_ERROR_STYLE ,
128
+ warning : DEFAULT_WARNING_STYLE ,
129
+ info : DEFAULT_INFO_STYLE ,
130
+ note : DEFAULT_NOTE_STYLE ,
131
+ help : DEFAULT_HELP_STYLE ,
132
+ line_num : DEFAULT_LINE_NUM_STYLE ,
133
+ emphasis : DEFAULT_EMPHASIS_STYLE ,
134
+ none : DEFAULT_NONE_STYLE ,
135
+ context : DEFAULT_CONTEXT_STYLE ,
136
+ addition : DEFAULT_ADDITION_STYLE ,
137
+ removal : DEFAULT_REMOVAL_STYLE ,
126
138
} ,
127
139
..Self :: plain ( )
128
140
}
0 commit comments