Skip to content

Commit

Permalink
fix: Match bat in gutter coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 13, 2022
1 parent a6a65e0 commit ec91549
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ encoding = "0.2.33"
git-config-env = "0.1.2"
shlex = "1.1.0"
atty = "0.2.14"
anstyle-syntect = "0.1.2"
34 changes: 18 additions & 16 deletions src/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,11 @@ pub fn blame(
} else {
"".to_owned()
};
let gutter_style = anstyle::Style::new()
.fg_color(
highlighter
.theme()
.settings
.gutter_foreground
.map(|c| (c.r, c.g, c.b).into()),
)
.bg_color(
highlighter
.theme()
.settings
.gutter
.map(|c| (c.r, c.g, c.b).into()),
);
let gutter_style = gutter_style.render();
let gutter_style = if colored_stdout {
gutter_style(highlighter.theme()).render().to_string()
} else {
"".to_owned()
};
let wrap = textwrap::Options::new(code_width)
.break_words(false)
.wrap_algorithm(textwrap::WrapAlgorithm::FirstFit);
Expand Down Expand Up @@ -436,6 +425,19 @@ impl<'a> Highlighter<'a> {
}
}

fn gutter_style(theme: &syntect::highlighting::Theme) -> anstyle::Style {
const DEFAULT_GUTTER_COLOR: u8 = 238;

// If the theme provides a gutter foreground color, use it.
let fg_color = theme
.settings
.gutter_foreground
.map(anstyle_syntect::to_anstyle_color)
.unwrap_or_else(|| anstyle::XTermColor(DEFAULT_GUTTER_COLOR).into());

fg_color.into()
}

const THEME_DEFAULT: &str = "base16-ocean.dark";
pub const THEME: DefaultField<String> =
RawField::<String>::new("dive.theme").default_value(|| THEME_DEFAULT.to_owned());

0 comments on commit ec91549

Please sign in to comment.