| 1 | use crate::delta::{State, StateMachine}; |
| 2 | use crate::paint::{BgShouldFill, StyleSectionSpecifier}; |
| 3 | use crate::utils::process; |
| 4 | |
| 5 | impl StateMachine<'_> { |
| 6 | // If this is a line of `git show $revision:/path/to/file.ext` output then |
| 7 | // syntax-highlight it as language `ext`. |
| 8 | pub fn handle_git_show_file_line(&mut self) -> std::io::Result<bool> { |
| 9 | self.painter.emit()?; |
| 10 | let mut handled_line = false; |
| 11 | if matches!(self.state, State::Unknown) { |
| 12 | if let process::CallingProcess::GitShow(_, Some(filename)) = |
| 13 | &*process::calling_process() |
| 14 | { |
| 15 | self.state = State::GitShowFile; |
| 16 | self.painter.set_syntax(Some(filename)); |
| 17 | } else { |
| 18 | return Ok(handled_line); |
| 19 | } |
| 20 | } |
| 21 | if matches!(self.state, State::GitShowFile) { |
| 22 | self.painter.set_highlighter(); |
| 23 | self.painter.syntax_highlight_and_paint_line( |
| 24 | &self.line, |
| 25 | StyleSectionSpecifier::Style(self.config.zero_style), |
| 26 | self.state.clone(), |
| 27 | BgShouldFill::default(), |
| 28 | ); |
| 29 | handled_line = true; |
| 30 | } |
| 31 | Ok(handled_line) |
| 32 | } |
| 33 | } |