Skip to content

Commit 0c2ab32

Browse files
committed
Formatting for emoji
1 parent f9c42e8 commit 0c2ab32

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lychee-bin/src/formatters/log.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,28 @@ pub(crate) fn init_logging(verbose: &Verbosity, mode: &OutputMode) {
3636
.filter_module("lychee_lib", level_filter);
3737
}
3838

39-
// Calculate the ongest log level text, including brackets.
40-
let levels = log::LevelFilter::iter();
41-
let max_level_text_width = levels.map(|level| level.as_str().len()).max().unwrap_or(0) + 2;
39+
// Calculate the longest log level text, including brackets.
40+
let max_level_text_width = log::LevelFilter::iter()
41+
.map(|level| level.as_str().len() + 2)
42+
.max()
43+
.unwrap_or(0);
4244

4345
// Customize the log message format if not plain.
4446
if mode.is_plain() {
4547
// Explicitly disable colors for plain output.
4648
builder.format(move |buf, record| writeln!(buf, "[{}] {}", record.level(), record.args()));
49+
} else if mode.is_emoji() {
50+
// Disable padding, keep colors
51+
builder.format(move |buf, record| {
52+
let level = record.level();
53+
let color = formatters::color::color_for_level(level);
54+
writeln!(
55+
buf,
56+
"{} {}",
57+
color.apply_to(format!("[{level}]")),
58+
record.args()
59+
)
60+
});
4761
} else {
4862
builder.format(move |buf, record| {
4963
let level = record.level();

lychee-bin/src/options.rs

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ impl OutputMode {
9797
pub(crate) const fn is_plain(&self) -> bool {
9898
matches!(self, OutputMode::Plain)
9999
}
100+
101+
/// Returns `true` if the response format is `Emoji`
102+
pub(crate) const fn is_emoji(&self) -> bool {
103+
matches!(self, OutputMode::Emoji)
104+
}
100105
}
101106

102107
// Macro for generating default functions to be used by serde

0 commit comments

Comments
 (0)