summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-11-14 14:14:51 -0500
committerDan Davison <dandavison7@gmail.com>2021-11-22 13:18:15 -0500
commitc8432915b702cae2308cd775fe913fa3a9c54832 (patch)
tree0edacc85fd50544c5416ec89f6c7bda90d5987c9
parent7acbafa1e81883864d396fc23c0c3aa7eb7971e5 (diff)
Refactor: StyleSectionSpecifier enum for syntax_highlight_and_paint_line
-rw-r--r--src/handlers/blame.rs3
-rw-r--r--src/handlers/hunk_header.rs4
-rw-r--r--src/paint.rs10
3 files changed, 12 insertions, 5 deletions
diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs
index e62332f2..ed645c6d 100644
--- a/src/handlers/blame.rs
+++ b/src/handlers/blame.rs
@@ -10,6 +10,7 @@ use crate::config::delta_unreachable;
use crate::delta::{self, State, StateMachine};
use crate::format::{self, Placeholder};
use crate::paint::BgShouldFill;
+use crate::paint::StyleSectionSpecifier;
use crate::style::Style;
use crate::utils;
@@ -84,7 +85,7 @@ impl<'a> StateMachine<'a> {
self.state = State::Blame(blame.commit.to_owned(), repeat_blame_line.to_owned());
self.painter.syntax_highlight_and_paint_line(
&format!("{}\n", blame.code),
- style,
+ StyleSectionSpecifier::Style(style),
self.state.clone(),
BgShouldFill::default(),
);
diff --git a/src/handlers/hunk_header.rs b/src/handlers/hunk_header.rs
index 525b749d..d1b4706d 100644
--- a/src/handlers/hunk_header.rs
+++ b/src/handlers/hunk_header.rs
@@ -28,7 +28,7 @@ use super::draw;
use crate::config::Config;
use crate::delta::{self, State, StateMachine};
use crate::features;
-use crate::paint::{BgShouldFill, Painter};
+use crate::paint::{BgShouldFill, Painter, StyleSectionSpecifier};
use crate::style::DecorationStyle;
impl<'a> StateMachine<'a> {
@@ -254,7 +254,7 @@ fn write_to_output_buffer(
if !line.is_empty() {
painter.syntax_highlight_and_paint_line(
&line,
- config.hunk_header_style,
+ StyleSectionSpecifier::Style(config.hunk_header_style),
delta::State::HunkHeader("".to_owned(), "".to_owned()),
BgShouldFill::No,
);
diff --git a/src/paint.rs b/src/paint.rs
index 32a5978d..20481ae2 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -55,6 +55,10 @@ impl Default for BgShouldFill {
}
}
+pub enum StyleSectionSpecifier<'l> {
+ Style(Style),
+}
+
impl<'p> Painter<'p> {
pub fn new(writer: &'p mut dyn Write, config: &'p config::Config) -> Self {
let default_syntax = Self::get_syntax(&config.syntax_set, None);
@@ -409,7 +413,7 @@ impl<'p> Painter<'p> {
pub fn syntax_highlight_and_paint_line(
&mut self,
line: &str,
- style: Style,
+ style_sections: StyleSectionSpecifier,
state: State,
background_color_extends_to_terminal_width: BgShouldFill,
) {
@@ -420,7 +424,9 @@ impl<'p> Painter<'p> {
self.highlighter.as_mut(),
self.config,
);
- let diff_style_sections = vec![vec![(style, lines[0].0.as_str())]]; // TODO: compute style from state
+ let diff_style_sections = match style_sections {
+ StyleSectionSpecifier::Style(style) => vec![vec![(style, lines[0].0.as_str())]],
+ };
Painter::paint_lines(
syntax_style_sections,
diff_style_sections,