Skip to content

Commit

Permalink
refactor(report): Don't bother stripping ANSI escape codes
Browse files Browse the repository at this point in the history
`cargo report` calls `Shell::print_ansi_stdout`.  Previously, it didn't
always strip the colors when needed (e.g. `Write` is used).  Now it
does, so don't need to special case this when generating the report.
  • Loading branch information
epage committed Sep 29, 2023
1 parent 89b2a43 commit 98bba4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn report_future_incompatibilities(config: &Config, args: &ArgMatches) -> CliRes
.value_of_u32("id")?
.unwrap_or_else(|| reports.last_id());
let krate = args.get_one::<String>("package").map(String::as_str);
let report = reports.get_report(id, config, krate)?;
let report = reports.get_report(id, krate)?;
drop_println!(config, "{}", REPORT_PREAMBLE);
drop(config.shell().print_ansi_stdout(report.as_bytes()));
Ok(())
Expand Down
17 changes: 3 additions & 14 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::core::compiler::BuildContext;
use crate::core::{Dependency, PackageId, Workspace};
use crate::sources::source::QueryKind;
use crate::sources::SourceConfigMap;
use crate::util::{iter_join, CargoResult, Config};
use crate::util::{iter_join, CargoResult};
use anyhow::{bail, format_err, Context};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
Expand Down Expand Up @@ -224,12 +224,8 @@ impl OnDiskReports {
self.reports.last().map(|r| r.id).unwrap()
}

pub fn get_report(
&self,
id: u32,
config: &Config,
package: Option<&str>,
) -> CargoResult<String> {
/// Returns an ANSI-styled report
pub fn get_report(&self, id: u32, package: Option<&str>) -> CargoResult<String> {
let report = self.reports.iter().find(|r| r.id == id).ok_or_else(|| {
let available = iter_join(self.reports.iter().map(|r| r.id.to_string()), ", ");
format_err!(
Expand Down Expand Up @@ -267,13 +263,6 @@ impl OnDiskReports {
};
to_display += &package_report;

let shell = config.shell();

let to_display = if shell.err_supports_color() && shell.out_supports_color() {
to_display
} else {
anstream::adapter::strip_str(&to_display).to_string()
};
Ok(to_display)
}
}
Expand Down

0 comments on commit 98bba4b

Please sign in to comment.