diff_trees/
diff_tag.rs

1use owo_colors::Style;
2
3/// This is a local equivalent of the [`similar::DiffTag`][1] enum.
4///
5/// [1]: https://docs.rs/similar/latest/similar/enum.DiffTag.html
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum DiffTag {
8    /// An entry that is equal in both sides of the diff.
9    Equal,
10    /// An entry that is present in the 'old' side of the diff and absent in the 'new' side.
11    Delete,
12    /// An entry that is present in both sides of the diff, but with changed contents.
13    Replace,
14    /// An entry that is absent in the 'old' side of the diff and present in the 'new' side.
15    Insert,
16}
17
18impl DiffTag {
19    /// TODO: Should probably be customizable.
20    pub(crate) fn style(&self) -> Style {
21        match self {
22            DiffTag::Equal => Style::new(),
23            DiffTag::Delete => Style::new().red(),
24            DiffTag::Replace => Style::new().yellow(),
25            DiffTag::Insert => Style::new().green(),
26        }
27    }
28
29    /// TODO: Should probably be customizable.
30    pub(crate) fn marker(&self) -> char {
31        match self {
32            DiffTag::Equal => ' ',
33            DiffTag::Delete => '-',
34            DiffTag::Replace => '~',
35            DiffTag::Insert => '+',
36        }
37    }
38}