Skip to content

Commit 631c9ee

Browse files
committed
Do not rely on a color term crate to generate ANSI character
1 parent b38c2e0 commit 631c9ee

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-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: 12 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,32 @@ fn compress_common_lines(common_lines: Vec<&str>) -> String {
154152
truncated_lines
155153
}
156154

155+
// See
157156
struct LineStyle {
158-
ansi: Style,
157+
ansi_prefix: &'static str,
158+
ansi_suffix: &'static str,
159159
header: char,
160160
}
161161

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

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

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

178+
// No ansi styling
175179
fn unchanged_style() -> Self {
176-
Self { ansi: Style::new(), header: ' ' }
180+
Self { ansi_prefix: "", ansi_suffix: "", header: ' ' }
177181
}
178182

179183
fn style(self, line: &str) -> StyledLine<'_> {
@@ -192,10 +196,7 @@ impl<'a> Display for StyledLine<'a> {
192196
write!(
193197
f,
194198
"{}{}{}{}",
195-
self.style.header,
196-
self.style.ansi.prefix(),
197-
self.line,
198-
self.style.ansi.suffix()
199+
self.style.header, self.style.ansi_prefix, self.line, self.style.ansi_suffix
199200
)
200201
} else {
201202
write!(f, "{}{}", self.style.header, self.line)

0 commit comments

Comments
 (0)