summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2021-07-07 22:19:46 -0700
committerWilfred Hughes <me@wilfred.me.uk>2021-07-07 22:19:46 -0700
commit6f871407030d3167952b8a332da5ed890d9f10c8 (patch)
tree0cece3745708e65f4b53ed823b213be82282b04e
parent3e199ed6454d465bf0f1946136f0858251a0750b (diff)
Don't crash if file is unchanged0.3
Fixes #4
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/main.rs16
2 files changed, 13 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8141c8fa0..715866da1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,8 @@ Improved punctuation parsing for OCaml and JS.
Fixed an issue where the diff calculated may not be minimal.
+Fixed a crash on files with no changes.
+
## 0.2
First version using Dijkstra's algorithm for calculating diffs.
diff --git a/src/main.rs b/src/main.rs
index 8d0d1d5fa..90a8a2ab4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -93,7 +93,18 @@ fn main() {
let lhs_matched_lines = matching_lines(&lhs);
+ let lang_name = match &lang {
+ Some(lang) => lang.name.clone(),
+ None => "plain text".to_string(),
+ };
+ println!("{}", style::header(rhs_path, &lang_name));
+
let mut groups = visible_groups(&lhs_positions, &rhs_positions);
+ if groups.is_empty() {
+ println!("No changes found.");
+ return;
+ }
+
for group in &mut groups {
group.pad(3, lhs_src.max_line(), rhs_src.max_line());
}
@@ -118,11 +129,6 @@ fn main() {
let lhs_colored = apply_colors(&lhs_src, true, &lhs_positions);
let rhs_colored = apply_colors(&rhs_src, false, &rhs_positions);
- let lang_name = match &lang {
- Some(lang) => lang.name.clone(),
- None => "plain text".to_string(),
- };
- println!("{}", style::header(rhs_path, &lang_name));
print!(
"{}",
apply_groups(