Style warnings more prominently

pull/614/head
Wilfred Hughes 2023-12-14 09:07:47 +07:00
parent 001279a2e1
commit 72348338aa
2 changed files with 31 additions and 6 deletions

@ -426,6 +426,24 @@ fn apply_header_color(
}
}
/// Style `s` as a warning and write to stderr.
pub(crate) fn print_warning(s: &str, display_options: &DisplayOptions) {
let prefix = if display_options.use_color {
if display_options.background_color.is_dark() {
"warning: ".bright_yellow().to_string()
} else {
"warning: ".yellow().to_string()
}
.bold()
.to_string()
} else {
"warning: ".to_string()
};
eprint!("{}", prefix);
eprint!("{}\n\n", s);
}
pub(crate) fn apply_line_number_color(
s: &str,
is_novel: bool,

@ -44,6 +44,7 @@ mod words;
#[macro_use]
extern crate log;
use display::style::print_warning;
use log::info;
use mimalloc::MiMalloc;
@ -228,9 +229,12 @@ fn main() {
_ => false,
};
eprintln!(
"warning: You've specified the same {} twice.\n",
if is_dir { "directory" } else { "file" }
print_warning(
&format!(
"You've specified the same {} twice.",
if is_dir { "directory" } else { "file" }
),
&display_options,
);
}
@ -402,9 +406,12 @@ fn diff_conflicts_file(
};
if conflict_files.num_conflicts == 0 {
eprintln!(
"warning: Expected a file with conflict markers {}, but none were found. See --help for usage instructions.\n",
START_LHS_MARKER,
print_warning(
&format!(
"Expected a file with conflict markers {}, but none were found. See --help for usage instructions.",
START_LHS_MARKER,
),
display_options,
);
}