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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! This library is for helping you create diff for displaying on the terminal
//!
//! # Examples
//!
//! ```
//! use termdiff::{diff, ArrowsTheme};
//! let old = "The quick brown fox and\njumps over the sleepy dog";
//! let new = "The quick red fox and\njumps over the lazy dog";
//! let mut buffer: Vec<u8> = Vec::new();
//! let theme = ArrowsTheme::default();
//! diff(&mut buffer, old, new, &theme).unwrap();
//! let actual: String = String::from_utf8(buffer).expect("Not valid UTF-8");
//!
//! assert_eq!(
//! actual,
//! "< left / > right
//! <The quick brown fox and
//! <jumps over the sleepy dog
//! >The quick red fox and
//! >jumps over the lazy dog
//! "
//! );
//! ```
//!
//! Alternatively if you are dropping this into a `format!` or similar, you
//! might want to use the displayable instead
//!
//! ```
//! use termdiff::{DrawDiff, SignsTheme};
//! let old = "The quick brown fox and\njumps over the sleepy dog";
//! let new = "The quick red fox and\njumps over the lazy dog";
//! let theme = SignsTheme::default();
//! let actual = format!("{}", DrawDiff::new(old, new, &theme));
//!
//! assert_eq!(
//! actual,
//! "--- remove | insert +++
//! -The quick brown fox and
//! -jumps over the sleepy dog
//! +The quick red fox and
//! +jumps over the lazy dog
//! "
//! );
//! ```
//!
//! # Features
//!
//! This crate provides several features that can be enabled or disabled in your `Cargo.toml`:
//!
//! ## Diff Algorithms
//!
//! * `myers` - Provides a Myers diff algorithm variant. This is a from-scratch
//! implementation of Eugene Myers' O(ND) difference algorithm (1986) that
//! does not depend on the `similar` crate. It can be used on its own
//! (without the `similar` feature) and produces output compatible with the
//! `similar` feature.
//!
//! * `similar` - Uses the "similar" crate to compute diffs. This is the primary
//! algorithm implementation.
//!
//! ## Themes
//!
//! * `arrows` - A simple, colorless theme that uses arrow symbols (`<` and `>`) to indicate
//! deleted and inserted lines. The header shows "< left / > right".
//!
//! * `arrows_color` - A colored version of the arrows theme. Uses red for deleted content and
//! green for inserted content. Requires the "crossterm" crate for terminal color support.
//!
//! * `signs` - A simple, colorless theme that uses plus and minus signs (`-` and `+`) to indicate
//! deleted and inserted lines. The header shows "--- remove | insert +++". This style is
//! similar to traditional diff output.
//!
//! * `signs_color` - A colored version of the signs theme. Uses red for deleted content and
//! green for inserted content. Requires the "crossterm" crate for terminal color support.
//!
//! By default, all features are enabled. You can selectively disable features by specifying
//! `default-features = false` and then listing the features you want to enable.
//!
//! You can define your own theme if you like
//!
//!
//! ``` rust
//! use std::borrow::Cow;
//!
//! use crossterm::style::Stylize;
//! use termdiff::{DrawDiff, Theme};
//!
//! #[derive(Debug)]
//! struct MyTheme {}
//! impl Theme for MyTheme {
//! fn highlight_insert<'this>(&self, input: &'this str) -> Cow<'this, str> {
//! input.into()
//! }
//!
//! fn highlight_delete<'this>(&self, input: &'this str) -> Cow<'this, str> {
//! input.into()
//! }
//!
//! fn equal_content<'this>(&self, input: &'this str) -> Cow<'this, str> {
//! input.into()
//! }
//!
//! fn delete_content<'this>(&self, input: &'this str) -> Cow<'this, str> {
//! input.into()
//! }
//!
//! fn equal_prefix<'this>(&self) -> Cow<'this, str> {
//! "=".into()
//! }
//!
//! fn delete_prefix<'this>(&self) -> Cow<'this, str> {
//! "!".into()
//! }
//!
//! fn insert_line<'this>(&self, input: &'this str) -> Cow<'this, str> {
//! input.into()
//! }
//!
//! fn insert_prefix<'this>(&self) -> Cow<'this, str> {
//! "|".into()
//! }
//!
//! fn line_end<'this>(&self) -> Cow<'this, str> {
//! "\n".into()
//! }
//!
//! fn header<'this>(&self) -> Cow<'this, str> {
//! format!("{}\n", "Header").into()
//! }
//! }
//! let my_theme = MyTheme {};
//! let old = "The quick brown fox and\njumps over the sleepy dog";
//! let new = "The quick red fox and\njumps over the lazy dog";
//! let actual = format!("{}", DrawDiff::new(old, new, &my_theme));
//!
//! assert_eq!(
//! actual,
//! "Header
//! !The quick brown fox and
//! !jumps over the sleepy dog
//! |The quick red fox and
//! |jumps over the lazy dog
//! "
//! );
//! ```
pub use ;
pub use Algorithm;
pub use DrawDiff;
// Re-export the Theme trait and theme implementations
pub use ArrowsColorTheme;
pub use ArrowsTheme;
pub use SignsColorTheme;
pub use SignsTheme;
pub use Theme;