diff options
author | Tim Oram <dev@mitmaro.ca> | 2020-07-05 21:51:49 -0230 |
---|---|---|
committer | Tim Oram <dev@mitmaro.ca> | 2020-07-26 21:29:20 -0230 |
commit | f900d498be3ba0d999ad73230ce2c90bc9194736 (patch) | |
tree | d0a25e6ab6e362ef3620ee68a4f7d550d7115e3f /src/show_commit/delta.rs | |
parent | e8320a6d41d4f350ebd1ab714ffe4f316be1ad6e (diff) |
Add diff view to show commit
This change adds a diff view to the show commit that is similar to the
`git show` command.
Diffstat (limited to 'src/show_commit/delta.rs')
-rw-r--r-- | src/show_commit/delta.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/show_commit/delta.rs b/src/show_commit/delta.rs new file mode 100644 index 0000000..73c3219 --- /dev/null +++ b/src/show_commit/delta.rs @@ -0,0 +1,53 @@ +use crate::show_commit::diff_line::DiffLine; + +#[derive(Debug, Clone)] +pub(crate) struct Delta { + old_start: u32, + old_lines: u32, + new_start: u32, + new_lines: u32, + context: String, + lines: Vec<DiffLine>, +} + +impl Delta { + pub(super) fn new(header: &str, old_start: u32, new_start: u32, old_lines: u32, new_lines: u32) -> Self { + let context = header.split('@').last().unwrap_or("").trim(); + Self { + old_start, + old_lines, + new_start, + new_lines, + context: String::from(context), + lines: vec![], + } + } + + pub(crate) fn add_line(&mut self, diff_line: DiffLine) { + self.lines.push(diff_line); + } + + pub(crate) fn context(&self) -> &str { + self.context.as_str() + } + + pub(crate) fn lines(&self) -> &Vec<DiffLine> { + &self.lines + } + + pub(crate) fn old_start(&self) -> u32 { + self.old_start + } + + pub(crate) fn old_lines(&self) -> u32 { + self.old_lines + } + + pub(crate) fn new_start(&self) -> u32 { + self.new_start + } + + pub(crate) fn new_lines(&self) -> u32 { + self.new_lines + } +} |