Skip to content

Commit a93bfcb

Browse files
committed
Print reports using shell to handle old Windows colors properly.
1 parent 7e2b31a commit a93bfcb

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/bin/cargo/commands/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ fn report_future_incompatibilies(config: &Config, args: &ArgMatches<'_>) -> CliR
4040
.unwrap_or_else(|| reports.last_id());
4141
let report = reports.get_report(id, config)?;
4242
drop_println!(config, "{}", REPORT_PREAMBLE);
43-
drop_println!(config, "{}", report);
43+
drop(config.shell().print_ansi_stdout(report.as_bytes()));
4444
Ok(())
4545
}

src/cargo/core/compiler/job_queue.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ use crate::core::compiler::future_incompat::{
7474
};
7575
use crate::core::resolver::ResolveBehavior;
7676
use crate::core::{FeatureValue, PackageId, Shell, TargetKind};
77-
use crate::drop_eprint;
7877
use crate::util::diagnostic_server::{self, DiagnosticPrinter};
7978
use crate::util::interning::InternedString;
8079
use crate::util::machine_message::{self, Message as _};
@@ -272,7 +271,7 @@ impl<'a> JobState<'a> {
272271
pub fn stderr(&self, stderr: String) -> CargoResult<()> {
273272
if let Some(config) = self.output {
274273
let mut shell = config.shell();
275-
shell.print_ansi(stderr.as_bytes())?;
274+
shell.print_ansi_stderr(stderr.as_bytes())?;
276275
shell.err().write_all(b"\n")?;
277276
} else {
278277
self.messages.push_bounded(Message::Stderr(stderr));
@@ -561,7 +560,7 @@ impl<'cfg> DrainState<'cfg> {
561560
}
562561
Message::Stderr(err) => {
563562
let mut shell = cx.bcx.config.shell();
564-
shell.print_ansi(err.as_bytes())?;
563+
shell.print_ansi_stderr(err.as_bytes())?;
565564
shell.err().write_all(b"\n")?;
566565
}
567566
Message::FixDiagnostic(msg) => {
@@ -841,7 +840,7 @@ impl<'cfg> DrainState<'cfg> {
841840

842841
if bcx.build_config.future_incompat_report {
843842
let rendered = on_disk_reports.get_report(report_id, bcx.config).unwrap();
844-
drop_eprint!(bcx.config, "{}", rendered);
843+
drop(bcx.config.shell().print_ansi_stderr(rendered.as_bytes()));
845844
drop(bcx.config.shell().note(&format!(
846845
"this report can be shown with `cargo report \
847846
future-incompatibilities -Z future-incompat-report --id {}`",

src/cargo/core/shell.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ impl Shell {
323323
}
324324
}
325325

326-
/// Prints a message and translates ANSI escape code into console colors.
327-
pub fn print_ansi(&mut self, message: &[u8]) -> CargoResult<()> {
326+
/// Prints a message to stderr and translates ANSI escape code into console colors.
327+
pub fn print_ansi_stderr(&mut self, message: &[u8]) -> CargoResult<()> {
328328
if self.needs_clear {
329329
self.err_erase_line();
330330
}
@@ -339,6 +339,22 @@ impl Shell {
339339
Ok(())
340340
}
341341

342+
/// Prints a message to stdout and translates ANSI escape code into console colors.
343+
pub fn print_ansi_stdout(&mut self, message: &[u8]) -> CargoResult<()> {
344+
if self.needs_clear {
345+
self.err_erase_line();
346+
}
347+
#[cfg(windows)]
348+
{
349+
if let ShellOut::Stream { stdout, .. } = &mut self.output {
350+
::fwdansi::write_ansi(stdout, message)?;
351+
return Ok(());
352+
}
353+
}
354+
self.out().write_all(message)?;
355+
Ok(())
356+
}
357+
342358
pub fn print_json<T: serde::ser::Serialize>(&mut self, obj: &T) -> CargoResult<()> {
343359
// Path may fail to serialize to JSON ...
344360
let encoded = serde_json::to_string(&obj)?;

tests/testsuite/future_incompat_report.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ fn test_multi_crate() {
217217
}
218218
assert!(count > 0);
219219
}
220-
assert_eq!(lines.next(), Some(""));
221220
assert_eq!(lines.next(), None);
222221
}
223222

0 commit comments

Comments
 (0)