diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-12-12 21:54:48 -0500 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-12-12 23:34:34 -0500 |
commit | 1767b3be296c68be294749603ffd766c68704900 (patch) | |
tree | 8d9ba85af3f845a0ad470c8f64837de2e1d5f062 | |
parent | fbf88e4686cdc0d70f1905c2b16a0cd732399447 (diff) |
Refactor: make state available when determining whether line should be emitted raw
-rw-r--r-- | src/config.rs | 1 | ||||
-rw-r--r-- | src/handlers/hunk.rs | 16 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs index 61369cc0..d7798550 100644 --- a/src/config.rs +++ b/src/config.rs @@ -152,6 +152,7 @@ impl Config { pub fn get_style(&self, state: &State) -> &Style { match state { State::HunkMinus(_, _) => &self.minus_style, + State::HunkZero(_, _) => &self.zero_style, State::HunkPlus(_, _) => &self.plus_style, State::CommitMeta => &self.commit_style, State::DiffHeader(_) => &self.file_style, diff --git a/src/handlers/hunk.rs b/src/handlers/hunk.rs index f7aedb5f..aca11158 100644 --- a/src/handlers/hunk.rs +++ b/src/handlers/hunk.rs @@ -79,6 +79,9 @@ impl<'a> StateMachine<'a> { if let State::HunkHeader(_, parsed_hunk_header, line, raw_line) = &self.state.clone() { self.emit_hunk_header_line(parsed_hunk_header, line, raw_line)?; } + // TODO: The following code is pretty convoluted currently and has been volving. It may be + // heading for (state, line | raw_line) to be held together in an enum variant representing + // a line. self.state = match new_line_state(&self.line, &self.state) { Some(HunkMinus(diff_type, _)) => { if let HunkPlus(_, _) = self.state { @@ -89,6 +92,7 @@ impl<'a> StateMachine<'a> { let n_parents = diff_type.n_parents(); let line = self.painter.prepare(&self.line, n_parents); let raw_line = self.maybe_raw_line( + HunkMinus(diff_type.clone(), None), // TODO n_parents, &[*style::GIT_DEFAULT_MINUS_STYLE, self.config.git_minus_style], ); @@ -100,6 +104,7 @@ impl<'a> StateMachine<'a> { let n_parents = diff_type.n_parents(); let line = self.painter.prepare(&self.line, n_parents); let raw_line = self.maybe_raw_line( + HunkPlus(diff_type.clone(), None), // TODO n_parents, &[*style::GIT_DEFAULT_PLUS_STYLE, self.config.git_plus_style], ); @@ -118,7 +123,8 @@ impl<'a> StateMachine<'a> { diff_type.n_parents() }; let line = self.painter.prepare(&self.line, n_parents); - let raw_line = self.maybe_raw_line(n_parents, &[]); + let raw_line = + self.maybe_raw_line(HunkZero(diff_type.clone(), None), n_parents, &[]); // TODO let state = State::HunkZero(diff_type, raw_line); self.painter.paint_zero_line(&line, state.clone()); state @@ -139,7 +145,13 @@ impl<'a> StateMachine<'a> { Ok(true) } - fn maybe_raw_line(&self, n_parents: usize, non_raw_styles: &[style::Style]) -> Option<String> { + // Return Some(prepared_raw_line) if delta should emit this line raw. + fn maybe_raw_line( + &self, + _state: State, + n_parents: usize, + non_raw_styles: &[style::Style], + ) -> Option<String> { let emit_raw_line = is_word_diff() || self.config.inspect_raw_lines == cli::InspectRawLines::True && style::line_has_style_other_than(&self.raw_line, non_raw_styles); |