Merge pull request #750 from epage/lock

fix: Ensure stdout is locked
This commit is contained in:
Ed Page 2023-06-20 09:24:16 -05:00 committed by GitHub
commit 78fa8783f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,17 +122,17 @@ impl Report for PrintBrief {
Message::Typo(msg) => print_brief_correction(msg, self.stdout_palette)?, Message::Typo(msg) => print_brief_correction(msg, self.stdout_palette)?,
Message::FileType(msg) => { Message::FileType(msg) => {
writeln!( writeln!(
stdout(), stdout().lock(),
"{}:{}", "{}:{}",
msg.path.display(), msg.path.display(),
msg.file_type.unwrap_or("-") msg.file_type.unwrap_or("-")
)?; )?;
} }
Message::File(msg) => { Message::File(msg) => {
writeln!(stdout(), "{}", msg.path.display())?; writeln!(stdout().lock(), "{}", msg.path.display())?;
} }
Message::Parse(msg) => { Message::Parse(msg) => {
writeln!(stdout(), "{}", msg.data)?; writeln!(stdout().lock(), "{}", msg.data)?;
} }
Message::Error(msg) => { Message::Error(msg) => {
log::error!("{}: {}", context_display(&msg.context), msg.msg); log::error!("{}: {}", context_display(&msg.context), msg.msg);
@ -157,17 +157,17 @@ impl Report for PrintLong {
Message::Typo(msg) => print_long_correction(msg, self.stdout_palette)?, Message::Typo(msg) => print_long_correction(msg, self.stdout_palette)?,
Message::FileType(msg) => { Message::FileType(msg) => {
writeln!( writeln!(
stdout(), stdout().lock(),
"{}:{}", "{}:{}",
msg.path.display(), msg.path.display(),
msg.file_type.unwrap_or("-") msg.file_type.unwrap_or("-")
)?; )?;
} }
Message::File(msg) => { Message::File(msg) => {
writeln!(stdout(), "{}", msg.path.display())?; writeln!(stdout().lock(), "{}", msg.path.display())?;
} }
Message::Parse(msg) => { Message::Parse(msg) => {
writeln!(stdout(), "{}", msg.data)?; writeln!(stdout().lock(), "{}", msg.data)?;
} }
Message::Error(msg) => { Message::Error(msg) => {
log::error!("{}: {}", context_display(&msg.context), msg.msg); log::error!("{}: {}", context_display(&msg.context), msg.msg);
@ -187,7 +187,7 @@ fn print_brief_correction(msg: &Typo, palette: Palette) -> Result<(), std::io::E
typos::Status::Invalid => { typos::Status::Invalid => {
let divider = ":"; let divider = ":";
writeln!( writeln!(
stdout(), stdout().lock(),
"{:#}{:#}{:#}: {:#}", "{:#}{:#}{:#}: {:#}",
palette.info(context_display(&msg.context)), palette.info(context_display(&msg.context)),
palette.info(divider), palette.info(divider),
@ -198,7 +198,7 @@ fn print_brief_correction(msg: &Typo, palette: Palette) -> Result<(), std::io::E
typos::Status::Corrections(corrections) => { typos::Status::Corrections(corrections) => {
let divider = ":"; let divider = ":";
writeln!( writeln!(
stdout(), stdout().lock(),
"{:#}{:#}{:#}: {:#}", "{:#}{:#}{:#}: {:#}",
palette.info(context_display(&msg.context)), palette.info(context_display(&msg.context)),
palette.info(divider), palette.info(divider),
@ -328,7 +328,7 @@ pub struct PrintJson;
impl Report for PrintJson { impl Report for PrintJson {
fn report(&self, msg: Message) -> Result<(), std::io::Error> { fn report(&self, msg: Message) -> Result<(), std::io::Error> {
writeln!(stdout(), "{}", serde_json::to_string(&msg).unwrap())?; writeln!(stdout().lock(), "{}", serde_json::to_string(&msg).unwrap())?;
Ok(()) Ok(())
} }
} }