Only use bold for keywords in novel tokens

This makes added/removed regions slightly less prominent, but easier
to read. It also makes them more consistent with the styling on the
surrounding text.
pull/70/head
Wilfred Hughes 2021-10-27 23:55:33 +07:00
parent 9df3089199
commit c23a36411d
4 changed files with 27 additions and 5 deletions

@ -6,6 +6,10 @@ Every hunk is now shown with the file name and a hunk number. This
makes it easier to see which file you're looking at when there are
many changes.
Keywords in added/removed regions are now shown in bold, to give
modified regions basic syntax highlighting. Previously, all
added/removed regions were bold.
### Command Line Interface
The difftastic binary is now named `difft`, to reduce typing during

@ -171,7 +171,9 @@ impl LineGroup {
let opposite_pos: Vec<SingleLineSpan> = match &mp.kind {
MatchKind::Unchanged { opposite_pos, .. } => opposite_pos.1.clone(),
MatchKind::Novel { prev_opposite_pos } => prev_opposite_pos.clone(),
MatchKind::Novel {
prev_opposite_pos, ..
} => prev_opposite_pos.clone(),
MatchKind::UnchangedCommentPart { opposite_pos } => opposite_pos.clone(),
MatchKind::ChangedCommentPart { prev_opposite_pos } => prev_opposite_pos.clone(),
};
@ -225,7 +227,9 @@ impl LineGroup {
// here?
opposite_pos.1.clone()
}
MatchKind::Novel { prev_opposite_pos } => prev_opposite_pos.clone(),
MatchKind::Novel {
prev_opposite_pos, ..
} => prev_opposite_pos.clone(),
MatchKind::UnchangedCommentPart { opposite_pos } => opposite_pos.clone(),
MatchKind::ChangedCommentPart { prev_opposite_pos } => prev_opposite_pos.clone(),
};
@ -242,7 +246,9 @@ impl LineGroup {
// here?
opposite_pos.1.clone()
}
MatchKind::Novel { prev_opposite_pos } => prev_opposite_pos.clone(),
MatchKind::Novel {
prev_opposite_pos, ..
} => prev_opposite_pos.clone(),
MatchKind::UnchangedCommentPart { opposite_pos } => opposite_pos.clone(),
MatchKind::ChangedCommentPart { prev_opposite_pos } => prev_opposite_pos.clone(),
};

@ -110,14 +110,24 @@ pub fn apply_colors(s: &str, is_lhs: bool, positions: &[MatchedPos]) -> String {
bold: highlight == TokenKind::Atom(AtomKind::Keyword),
dimmed: highlight == TokenKind::Atom(AtomKind::Comment),
},
MatchKind::Novel { .. } | MatchKind::ChangedCommentPart { .. } => Style {
MatchKind::Novel { highlight, .. } => Style {
foreground: if is_lhs {
Color::BrightRed
} else {
Color::BrightGreen
},
background: None,
bold: true,
bold: highlight == TokenKind::Atom(AtomKind::Keyword),
dimmed: false,
},
MatchKind::ChangedCommentPart { .. } => Style {
foreground: if is_lhs {
Color::BrightRed
} else {
Color::BrightGreen
},
background: None,
bold: false,
dimmed: false,
},
MatchKind::UnchangedCommentPart { .. } => Style {

@ -499,6 +499,7 @@ pub enum MatchKind {
opposite_pos: (Vec<SingleLineSpan>, Vec<SingleLineSpan>),
},
Novel {
highlight: TokenKind,
prev_opposite_pos: Vec<SingleLineSpan>,
},
UnchangedCommentPart {
@ -641,6 +642,7 @@ impl MatchedPos {
}
}
Novel => MatchKind::Novel {
highlight,
prev_opposite_pos: prev_opposite_pos.to_vec(),
},
};