22//! and error reporting hooks
33use crate :: {
44 section:: PanicMessage ,
5+ style_if_possible,
56 writers:: { EnvSection , WriterExt } ,
67} ;
78use fmt:: Display ;
89use indenter:: { indented, Format } ;
9- use owo_colors:: { style, OwoColorize , Style } ;
10+ use owo_colors:: { style, Style } ;
1011use std:: env;
1112use std:: fmt:: Write as _;
1213use std:: { fmt, path:: PathBuf , sync:: Arc } ;
@@ -192,12 +193,12 @@ impl fmt::Display for StyledFrame<'_> {
192193 } ;
193194
194195 if is_dependency_code {
195- write ! ( f, "{}" , ( name) . style ( theme. dependency_code) ) ?;
196+ write ! ( f, "{}" , style_if_possible ( name, theme. dependency_code) ) ?;
196197 } else {
197- write ! ( f, "{}" , ( name) . style ( theme. crate_code) ) ?;
198+ write ! ( f, "{}" , style_if_possible ( name, theme. crate_code) ) ?;
198199 }
199200
200- write ! ( f, "{}" , ( hash_suffix) . style ( theme. code_hash) ) ?;
201+ write ! ( f, "{}" , style_if_possible ( hash_suffix, theme. code_hash) ) ?;
201202
202203 let mut separated = f. header ( "\n " ) ;
203204
@@ -214,8 +215,8 @@ impl fmt::Display for StyledFrame<'_> {
214215 write ! (
215216 & mut separated. ready( ) ,
216217 " at {}:{}" ,
217- file . style ( theme. file) ,
218- lineno . style ( theme. line_number) ,
218+ style_if_possible ( file , theme. file) ,
219+ style_if_possible ( lineno , theme. line_number) ,
219220 ) ?;
220221
221222 let v = if std:: thread:: panicking ( ) {
@@ -266,9 +267,9 @@ impl fmt::Display for SourceSection<'_> {
266267 write ! (
267268 & mut f,
268269 "{:>8} {} {}" ,
269- cur_line_no . style ( theme. active_line) ,
270- ">" . style ( theme. active_line) ,
271- line . style ( theme. active_line) ,
270+ style_if_possible ( cur_line_no , theme. active_line) ,
271+ style_if_possible ( ">" , theme. active_line) ,
272+ style_if_possible ( line , theme. active_line) ,
272273 ) ?;
273274 } else {
274275 write ! ( & mut f, "{:>8} │ {}" , cur_line_no, line) ?;
@@ -797,7 +798,7 @@ impl PanicMessage for DefaultPanicMessage {
797798 writeln ! (
798799 f,
799800 "{}" ,
800- "The application panicked (crashed)." . style ( theme. panic_header)
801+ style_if_possible ( "The application panicked (crashed)." , theme. panic_header)
801802 ) ?;
802803
803804 // Print panic message.
@@ -809,7 +810,7 @@ impl PanicMessage for DefaultPanicMessage {
809810 . unwrap_or ( "<non string panic payload>" ) ;
810811
811812 write ! ( f, "Message: " ) ?;
812- writeln ! ( f, "{}" , payload . style ( theme. panic_message) ) ?;
813+ writeln ! ( f, "{}" , style_if_possible ( payload , theme. panic_message) ) ?;
813814
814815 // If known, print panic location.
815816 write ! ( f, "Location: " ) ?;
@@ -1131,7 +1132,7 @@ impl fmt::Display for BacktraceFormatter<'_> {
11311132 write!(
11321133 & mut separated. ready( ) ,
11331134 "{:^80}" ,
1134- buf . style ( self . theme. hidden_frames)
1135+ style_if_possible ( & buf , self . theme. hidden_frames)
11351136 ) ?;
11361137 } ;
11371138 }
0 commit comments