Skip to content

Commit 981021e

Browse files
Merge pull request #267 from google:no-color-crate
PiperOrigin-RevId: 549229428
2 parents b38c2e0 + 631c9ee commit 981021e

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

googletest/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ authors = [
3232

3333
[dependencies]
3434
googletest_macro = { path = "../googletest_macro", version = "0.9.0" }
35-
ansi_term = "0.12.0"
3635
anyhow = { version = "1", optional = true }
3736
num-traits = "0.2.15"
3837
regex = "1.6.0"

googletest/src/matcher_support/summarize_diff.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use std::borrow::Cow;
1717
use std::fmt::{Display, Write};
1818

19-
use nu_ansi_term::{Color, Style};
20-
2119
use crate::matcher_support::edit_distance;
2220

2321
/// Environment variable controlling the usage of ansi color in difference
@@ -154,26 +152,34 @@ fn compress_common_lines(common_lines: Vec<&str>) -> String {
154152
truncated_lines
155153
}
156154

155+
// Use ANSI code to enable styling on the summary lines.
156+
//
157+
// See https://en.wikipedia.org/wiki/ANSI_escape_code.
157158
struct LineStyle {
158-
ansi: Style,
159+
ansi_prefix: &'static str,
160+
ansi_suffix: &'static str,
159161
header: char,
160162
}
161163

162164
impl LineStyle {
165+
// Font in red and bold
163166
fn extra_actual_style() -> Self {
164-
Self { ansi: Style::new().fg(Color::Red).bold(), header: '-' }
167+
Self { ansi_prefix: "\x1B[1;31m", ansi_suffix: "\x1B[0m", header: '-' }
165168
}
166169

170+
// Font in green and bold
167171
fn extra_expected_style() -> Self {
168-
Self { ansi: Style::new().fg(Color::Green).bold(), header: '+' }
172+
Self { ansi_prefix: "\x1B[1;32m", ansi_suffix: "\x1B[0m", header: '+' }
169173
}
170174

175+
// Font in italic
171176
fn comment_style() -> Self {
172-
Self { ansi: Style::new().italic(), header: ' ' }
177+
Self { ansi_prefix: "\x1B[3m", ansi_suffix: "\x1B[0m", header: ' ' }
173178
}
174179

180+
// No ansi styling
175181
fn unchanged_style() -> Self {
176-
Self { ansi: Style::new(), header: ' ' }
182+
Self { ansi_prefix: "", ansi_suffix: "", header: ' ' }
177183
}
178184

179185
fn style(self, line: &str) -> StyledLine<'_> {
@@ -192,10 +198,7 @@ impl<'a> Display for StyledLine<'a> {
192198
write!(
193199
f,
194200
"{}{}{}{}",
195-
self.style.header,
196-
self.style.ansi.prefix(),
197-
self.line,
198-
self.style.ansi.suffix()
201+
self.style.header, self.style.ansi_prefix, self.line, self.style.ansi_suffix
199202
)
200203
} else {
201204
write!(f, "{}{}", self.style.header, self.line)

0 commit comments

Comments
 (0)