Skip to content

Commit 0a5b4ab

Browse files
committed
fix(cli): Make the correction stand out more
This does deviate from rustc for `long` format but it seems worth it. I did move backticks to be out of the coloring so the `error:` was more distinct from the typo in `long` format.
1 parent 1ca3216 commit 0a5b4ab

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

crates/typos-cli/src/bin/typos-cli/report.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use typos_cli::report::{Context, Message, Report, Typo};
1010

1111
const ERROR: anstyle::Style = anstyle::AnsiColor::BrightRed.on_default();
1212
const INFO: anstyle::Style = anstyle::AnsiColor::BrightBlue.on_default();
13-
const STRONG: anstyle::Style = anstyle::Style::new().effects(anstyle::Effects::BOLD);
13+
const GOOD: anstyle::Style = anstyle::AnsiColor::BrightGreen.on_default();
1414

1515
pub struct MessageStatus<'r> {
1616
typos_found: atomic::AtomicBool,
@@ -126,8 +126,9 @@ impl Report for PrintLong {
126126
}
127127

128128
fn print_brief_correction(msg: &Typo) -> Result<(), std::io::Error> {
129+
let error = ERROR.render();
130+
let good = GOOD.render();
129131
let info = INFO.render();
130-
let strong = STRONG.render();
131132
let reset = anstyle::Reset.render();
132133

133134
let start = String::from_utf8_lossy(&msg.buffer[0..msg.byte_offset]);
@@ -139,7 +140,7 @@ fn print_brief_correction(msg: &Typo) -> Result<(), std::io::Error> {
139140
let divider = ":";
140141
writeln!(
141142
stdout().lock(),
142-
"{info}{}{divider}{column_number}{reset}: {strong}`{}` is disallowed{reset}",
143+
"{info}{}{divider}{column_number}{reset}: `{error}{}{reset}` is disallowed",
143144
context_display(&msg.context),
144145
msg.typo,
145146
)?;
@@ -148,10 +149,13 @@ fn print_brief_correction(msg: &Typo) -> Result<(), std::io::Error> {
148149
let divider = ":";
149150
writeln!(
150151
stdout().lock(),
151-
"{info}{}{divider}{column_number}{reset}: {strong}`{}` -> {}{reset}",
152+
"{info}{}{divider}{column_number}{reset}: `{error}{}{reset}` -> {}",
152153
context_display(&msg.context),
153154
msg.typo,
154-
itertools::join(corrections.iter().map(|s| format!("`{}`", s)), ", ")
155+
itertools::join(
156+
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
157+
", "
158+
)
155159
)?;
156160
}
157161
}
@@ -161,8 +165,8 @@ fn print_brief_correction(msg: &Typo) -> Result<(), std::io::Error> {
161165

162166
fn print_long_correction(msg: &Typo) -> Result<(), std::io::Error> {
163167
let error = ERROR.render();
168+
let good = GOOD.render();
164169
let info = INFO.render();
165-
let strong = STRONG.render();
166170
let reset = anstyle::Reset.render();
167171

168172
let stdout = stdout();
@@ -178,16 +182,19 @@ fn print_long_correction(msg: &Typo) -> Result<(), std::io::Error> {
178182
typos::Status::Invalid => {
179183
writeln!(
180184
handle,
181-
"{error}error{reset}: {strong}`{}` is disallowed{reset}",
185+
"{error}error{reset}: `{error}{}{reset}` is disallowed",
182186
msg.typo,
183187
)?;
184188
}
185189
typos::Status::Corrections(corrections) => {
186190
writeln!(
187191
handle,
188-
"{error}error{reset}: {strong}`{}` should be {}{reset}",
192+
"{error}error{reset}: `{error}{}{reset}` should be {}",
189193
msg.typo,
190-
itertools::join(corrections.iter().map(|s| format!("`{}`", s)), ", ")
194+
itertools::join(
195+
corrections.iter().map(|s| format!("`{good}{}{reset}`", s)),
196+
", "
197+
)
191198
)?;
192199
}
193200
}

0 commit comments

Comments
 (0)