-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathunderline-words.rs
More file actions
54 lines (47 loc) · 1.42 KB
/
underline-words.rs
File metadata and controls
54 lines (47 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extern crate term;
extern crate difference;
use difference::{Difference, Changeset};
use std::io::Write;
// Screenshot:
// https://raw.githubusercontent.com/johannhof/difference.rs/master/assets/word-underline.png
#[allow(unused_must_use)]
fn main() {
let text1 = "Roses are red, violets are blue.";
let text2 = "Roses are blue, violets are";
let mut t = term::stdout().unwrap();
let Changeset { diffs, .. } = Changeset::new(text1, text2, "");
for c in &diffs {
match *c {
Difference::Same(ref z) => {
t.fg(term::color::RED).unwrap();
write!(t, "{}", z);
}
Difference::Rem(ref z) => {
t.fg(term::color::WHITE).unwrap();
t.bg(term::color::RED).unwrap();
write!(t, "{}", z);
t.reset().unwrap();
}
_ => (),
}
}
t.reset().unwrap();
writeln!(t, "");
for c in &diffs {
match *c {
Difference::Same(ref z) => {
t.fg(term::color::GREEN).unwrap();
write!(t, "{}", z);
}
Difference::Add(ref z) => {
t.fg(term::color::WHITE).unwrap();
t.bg(term::color::GREEN).unwrap();
write!(t, "{}", z);
t.reset().unwrap();
}
_ => (),
}
}
t.reset().unwrap();
t.flush().unwrap();
}