-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: diff view with --diff (-d) flag
- Loading branch information
Showing
5 changed files
with
89 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use similar::TextDiff; | ||
use std::path::Path; | ||
|
||
use crate::error::{Error, Result}; | ||
|
||
pub(crate) fn create_udiff<UO: AsRef<[u8]>, UN: AsRef<[u8]>>( | ||
old: UO, | ||
new: UN, | ||
context: usize, | ||
path: Option<&Path>, | ||
) -> Result<String> { | ||
let diff = TextDiff::from_lines(old.as_ref(), new.as_ref()); | ||
let path = if let Some(path) = path { | ||
if let Some(spath) = path.to_str() { | ||
spath | ||
} else { | ||
return Err(Error::InvalidPath(path.into())); | ||
} | ||
} else { | ||
"" | ||
}; | ||
|
||
let mut udiff = diff.unified_diff(); | ||
udiff.header(path, path); | ||
udiff.context_radius(context); | ||
|
||
Ok(udiff.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters