Skip to content

Commit a562f91

Browse files
committed
Rename crate::style_if_possible into crate::style
1 parent 6f22b4a commit a562f91

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

color-eyre/src/config.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(deprecated)] // for PanicHook until we bump MSRV
44
use crate::{
55
section::PanicMessage,
6-
style_if_possible,
6+
style,
77
writers::{EnvSection, WriterExt},
88
};
99
use fmt::Display;
@@ -194,12 +194,12 @@ impl fmt::Display for StyledFrame<'_> {
194194
};
195195

196196
if is_dependency_code {
197-
write!(f, "{}", style_if_possible(name, theme.dependency_code))?;
197+
write!(f, "{}", style(name, theme.dependency_code))?;
198198
} else {
199-
write!(f, "{}", style_if_possible(name, theme.crate_code))?;
199+
write!(f, "{}", style(name, theme.crate_code))?;
200200
}
201201

202-
write!(f, "{}", style_if_possible(hash_suffix, theme.code_hash))?;
202+
write!(f, "{}", style(hash_suffix, theme.code_hash))?;
203203

204204
let mut separated = f.header("\n");
205205

@@ -216,8 +216,8 @@ impl fmt::Display for StyledFrame<'_> {
216216
write!(
217217
&mut separated.ready(),
218218
" at {}:{}",
219-
style_if_possible(file, theme.file),
220-
style_if_possible(lineno, theme.line_number),
219+
style(file, theme.file),
220+
style(lineno, theme.line_number),
221221
)?;
222222

223223
let v = if std::thread::panicking() {
@@ -268,9 +268,9 @@ impl fmt::Display for SourceSection<'_> {
268268
write!(
269269
&mut f,
270270
"{:>8} {} {}",
271-
style_if_possible(cur_line_no, theme.active_line),
272-
style_if_possible(">", theme.active_line),
273-
style_if_possible(line, theme.active_line),
271+
style(cur_line_no, theme.active_line),
272+
style(">", theme.active_line),
273+
style(line, theme.active_line),
274274
)?;
275275
} else {
276276
write!(&mut f, "{cur_line_no:>8} │ {line}")?;
@@ -799,7 +799,7 @@ impl PanicMessage for DefaultPanicMessage {
799799
writeln!(
800800
f,
801801
"{}",
802-
style_if_possible("The application panicked (crashed).", theme.panic_header)
802+
style("The application panicked (crashed).", theme.panic_header)
803803
)?;
804804

805805
// Print panic message.
@@ -811,7 +811,7 @@ impl PanicMessage for DefaultPanicMessage {
811811
.unwrap_or("<non string panic payload>");
812812

813813
write!(f, "Message: ")?;
814-
writeln!(f, "{}", style_if_possible(payload, theme.panic_message))?;
814+
writeln!(f, "{}", style(payload, theme.panic_message))?;
815815

816816
// If known, print panic location.
817817
write!(f, "Location: ")?;
@@ -1132,7 +1132,7 @@ impl fmt::Display for BacktraceFormatter<'_> {
11321132
write!(
11331133
&mut separated.ready(),
11341134
"{:^80}",
1135-
style_if_possible(&buf, self.theme.hidden_frames)
1135+
style(&buf, self.theme.hidden_frames)
11361136
)?;
11371137
};
11381138
}

color-eyre/src/fmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Module for new types that isolate complext formatting
22
use std::fmt;
3-
use crate::style_if_possible;
3+
use crate::style;
44

55
pub(crate) struct LocationSection<'a>(
66
pub(crate) Option<&'a std::panic::Location<'a>>,
@@ -12,9 +12,9 @@ impl fmt::Display for LocationSection<'_> {
1212
let theme = self.1;
1313
// If known, print panic location.
1414
if let Some(loc) = self.0 {
15-
write!(f, "{}", style_if_possible(loc.file(), theme.panic_file))?;
15+
write!(f, "{}", style(loc.file(), theme.panic_file))?;
1616
write!(f, ":")?;
17-
write!(f, "{}", style_if_possible(&loc.line(), theme.panic_line_number))?;
17+
write!(f, "{}", style(&loc.line(), theme.panic_line_number))?;
1818
} else {
1919
write!(f, "<unknown>")?;
2020
}

color-eyre/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
config::BacktraceFormatter,
33
section::help::HelpInfo,
4-
style_if_possible,
4+
style,
55
writers::{EnvSection, WriterExt},
66
Handler,
77
};
@@ -64,7 +64,7 @@ impl eyre::EyreHandler for Handler {
6464

6565
for (n, error) in errors() {
6666
writeln!(f)?;
67-
write!(indented(f).ind(n), "{}", style_if_possible(error, self.theme.error))?;
67+
write!(indented(f).ind(n), "{}", style(error, self.theme.error))?;
6868
}
6969

7070
let mut separated = f.header("\n\n");

color-eyre/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub fn install() -> Result<(), crate::eyre::Report> {
464464

465465
/// Apply owo_colors style if possible. Returns a string with/without ANSI
466466
/// escape symbols.
467-
fn style_if_possible<S>(str: S, style: Style) -> String
467+
fn style<S>(str: S, style: Style) -> String
468468
where
469469
S: ToString + std::fmt::Display,
470470
{

color-eyre/src/section/help.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::{
33
config::Theme,
44
eyre::{Report, Result},
5-
style_if_possible,
5+
style,
66
Section,
77
};
88
use indenter::indented;
@@ -261,18 +261,18 @@ impl Display for HelpInfo {
261261
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
262262
match self {
263263
HelpInfo::Note(note, theme) => {
264-
write!(f, "{}: {}", style_if_possible("Note", theme.help_info_note), note)
264+
write!(f, "{}: {}", style("Note", theme.help_info_note), note)
265265
}
266266
HelpInfo::Warning(warning, theme) => write!(
267267
f,
268268
"{}: {}",
269-
style_if_possible("Warning", theme.help_info_warning),
269+
style("Warning", theme.help_info_warning),
270270
warning
271271
),
272272
HelpInfo::Suggestion(suggestion, theme) => write!(
273273
f,
274274
"{}: {}",
275-
style_if_possible("Suggestion", theme.help_info_suggestion),
275+
style("Suggestion", theme.help_info_suggestion),
276276
suggestion
277277
),
278278
HelpInfo::Custom(section) => write!(f, "{section}"),
@@ -286,7 +286,7 @@ impl Display for HelpInfo {
286286
write!(f, "Error:")?;
287287
for (n, error) in errors.enumerate() {
288288
writeln!(f)?;
289-
write!(indented(f).ind(n), "{}", style_if_possible(error, theme.help_info_error))?;
289+
write!(indented(f).ind(n), "{}", style(error, theme.help_info_error))?;
290290
}
291291

292292
Ok(())

color-spantrace/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ impl Frame<'_> {
276276
f,
277277
"{:>2}: {}{}{}",
278278
i,
279-
style_if_possible(self.metadata.target(), self.theme.target),
280-
style_if_possible("::", self.theme.target),
281-
style_if_possible(self.metadata.name(), self.theme.target),
279+
style(self.metadata.target(), self.theme.target),
280+
style("::", self.theme.target),
281+
style(self.metadata.name(), self.theme.target),
282282
)
283283
}
284284

@@ -287,7 +287,7 @@ impl Frame<'_> {
287287
write!(
288288
f,
289289
" with {}",
290-
style_if_possible(self.fields, self.theme.fields)
290+
style(self.fields, self.theme.fields)
291291
)?;
292292
}
293293

@@ -303,8 +303,8 @@ impl Frame<'_> {
303303
write!(
304304
f,
305305
"\n at {}:{}",
306-
style_if_possible(file, self.theme.file),
307-
style_if_possible(lineno, self.theme.line_number),
306+
style(file, self.theme.file),
307+
style(lineno, self.theme.line_number),
308308
)?;
309309
} else {
310310
write!(f, "\n at <unknown source file>")?;
@@ -341,7 +341,7 @@ impl Frame<'_> {
341341
cur_line_no.to_string(),
342342
line.unwrap()
343343
)?;
344-
write!(f, "\n{}", style_if_possible(&buf, self.theme.active_line))?;
344+
write!(f, "\n{}", style(&buf, self.theme.active_line))?;
345345
buf.clear();
346346
} else {
347347
write!(f, "\n{:>8} │ {}", cur_line_no, line.unwrap())?;
@@ -385,7 +385,7 @@ impl fmt::Display for ColorSpanTrace<'_> {
385385

386386
/// Apply owo_colors style if possible. Returns a string with/without ANSI
387387
/// escape symbols.
388-
fn style_if_possible<S>(str: S, style: Style) -> String
388+
fn style<S>(str: S, style: Style) -> String
389389
where
390390
S: ToString + std::fmt::Display,
391391
{

0 commit comments

Comments
 (0)