Added virtual newline handling and example
This commit is contained in:
parent
da32711e1a
commit
96bbaf1fdf
5 changed files with 129 additions and 3 deletions
24
examples/terminal.rs
Normal file
24
examples/terminal.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
use console::Style;
|
||||
use similar::text::{ChangeTag, TextDiff};
|
||||
|
||||
fn main() {
|
||||
let diff = TextDiff::from_lines(
|
||||
"Hello World\nThis is the second line.\nThis is the third.",
|
||||
"Hallo Welt\nThis is the second line.\nThis is life.\nMoar and more",
|
||||
);
|
||||
|
||||
for op in diff.ops() {
|
||||
for change in diff.iter_changes(op) {
|
||||
let (sign, style) = match change.tag() {
|
||||
ChangeTag::Delete => ("-", Style::new().red()),
|
||||
ChangeTag::Insert => ("+", Style::new().green()),
|
||||
ChangeTag::Equal => (" ", Style::new()),
|
||||
};
|
||||
print!(
|
||||
"{}{}",
|
||||
style.apply_to(sign).bold(),
|
||||
style.apply_to(change.value())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue