Skip to content

Commit c0fd362

Browse files
committed
refactor: Reuse existing anstream dep for stripping
We are already getting `anstream` through `clap`, so this is no extra cost and let's us drop some dependencies. The `anstream` implementation is also orders of magnitude faster (last I benchmarked)
1 parent ab5ebba commit c0fd362

File tree

4 files changed

+7
-49
lines changed

4 files changed

+7
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ edition = "2021"
1616
license = "MIT OR Apache-2.0"
1717

1818
[workspace.dependencies]
19+
anstream = { version = "0.6.3", default-features = false }
1920
anstyle = "1.0.3"
2021
anstyle-termcolor = "1.1.0"
2122
anyhow = "1.0.75"
@@ -87,7 +88,6 @@ sha1 = "0.10.5"
8788
sha2 = "0.10.7"
8889
shell-escape = "0.1.5"
8990
snapbox = { version = "0.4.13", features = ["diff", "path"] }
90-
strip-ansi-escapes = "0.1.1"
9191
syn = { version = "2.0.29", features = ["extra-traits", "full"] }
9292
tar = { version = "0.4.40", default-features = false }
9393
tempfile = "3.8.0"
@@ -123,8 +123,9 @@ name = "cargo"
123123
path = "src/cargo/lib.rs"
124124

125125
[dependencies]
126-
anstyle.workspace = true
126+
anstream.workspace = true
127127
anstyle-termcolor.workspace = true
128+
anstyle.workspace = true
128129
anyhow.workspace = true
129130
base64.workspace = true
130131
bytesize.workspace = true
@@ -175,7 +176,6 @@ serde_ignored.workspace = true
175176
serde_json = { workspace = true, features = ["raw_value"] }
176177
sha1.workspace = true
177178
shell-escape.workspace = true
178-
strip-ansi-escapes.workspace = true
179179
syn.workspace = true
180180
tar.workspace = true
181181
tempfile.workspace = true

src/cargo/core/compiler/future_incompat.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ impl OnDiskReports {
272272
let to_display = if shell.err_supports_color() && shell.out_supports_color() {
273273
to_display
274274
} else {
275-
strip_ansi_escapes::strip(&to_display)
276-
.map(|v| String::from_utf8(v).expect("utf8"))
277-
.expect("strip should never fail")
275+
anstream::adapter::strip_str(&to_display).to_string()
278276
};
279277
Ok(to_display)
280278
}

src/cargo/core/compiler/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,9 +1591,7 @@ fn on_stderr_line_inner(
15911591
} else {
15921592
// Strip only fails if the Writer fails, which is Cursor
15931593
// on a Vec, which should never fail.
1594-
strip_ansi_escapes::strip(&msg.rendered)
1595-
.map(|v| String::from_utf8(v).expect("utf8"))
1596-
.expect("strip should never fail")
1594+
anstream::adapter::strip_str(&msg.rendered).to_string()
15971595
};
15981596
if options.show_diagnostics {
15991597
let machine_applicable: bool = msg
@@ -1625,9 +1623,7 @@ fn on_stderr_line_inner(
16251623
other: std::collections::BTreeMap<String, serde_json::Value>,
16261624
}
16271625
if let Ok(mut error) = serde_json::from_str::<CompilerMessage>(compiler_message.get()) {
1628-
error.rendered = strip_ansi_escapes::strip(&error.rendered)
1629-
.map(|v| String::from_utf8(v).expect("utf8"))
1630-
.unwrap_or(error.rendered);
1626+
error.rendered = anstream::adapter::strip_str(&error.rendered).to_string();
16311627
let new_line = serde_json::to_string(&error)?;
16321628
let new_msg: Box<serde_json::value::RawValue> = serde_json::from_str(&new_line)?;
16331629
compiler_message = new_msg;

0 commit comments

Comments
 (0)