Don't crash if file is unchanged

Fixes #4
pull/25/head 0.3
Wilfred Hughes 2021-07-07 22:19:46 +07:00
parent 3e199ed645
commit 6f87140703
2 changed files with 13 additions and 5 deletions

@ -9,6 +9,8 @@ Improved punctuation parsing for OCaml and JS.
Fixed an issue where the diff calculated may not be minimal. Fixed an issue where the diff calculated may not be minimal.
Fixed a crash on files with no changes.
## 0.2 ## 0.2
First version using Dijkstra's algorithm for calculating diffs. First version using Dijkstra's algorithm for calculating diffs.

@ -93,7 +93,18 @@ fn main() {
let lhs_matched_lines = matching_lines(&lhs); 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); let mut groups = visible_groups(&lhs_positions, &rhs_positions);
if groups.is_empty() {
println!("No changes found.");
return;
}
for group in &mut groups { for group in &mut groups {
group.pad(3, lhs_src.max_line(), rhs_src.max_line()); 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 lhs_colored = apply_colors(&lhs_src, true, &lhs_positions);
let rhs_colored = apply_colors(&rhs_src, false, &rhs_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!( print!(
"{}", "{}",
apply_groups( apply_groups(