Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,17 @@ pub struct Opt {
/// "{timestamp}", "{author}", and "{commit}".
#[structopt(
long = "blame-format",
default_value = "{timestamp:<15} {author:<15.14} {commit:<8} │ "
default_value = "{timestamp:<15} {author:<15.14} {commit:<8} │"
)]
pub blame_format: String,

#[structopt(long = "blame-code-style")]
/// Style (foreground, background, attributes) for the code section of a line of `git blame`
/// output. By default the code will be syntax-highlighted with the same background color as the
/// blame format section of the line (the background color is determined by blame-palette). E.g.
/// setting this option to 'syntax' will syntax-highlight the code with no background color.
pub blame_code_style: Option<String>,

/// Background colors used for git blame lines (space-separated string).
/// Lines added by the same commit are painted with the same color; colors
/// are recycled as needed.
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ fn adapt_wrap_max_lines_argument(arg: String) -> usize {
pub struct Config {
pub available_terminal_width: usize,
pub background_color_extends_to_terminal_width: bool,
pub blame_code_style: Option<Style>,
pub blame_format: String,
pub blame_palette: Vec<String>,
pub blame_timestamp_format: String,
Expand Down Expand Up @@ -241,6 +242,7 @@ impl From<cli::Opt> for Config {
.computed
.background_color_extends_to_terminal_width,
blame_format: opt.blame_format,
blame_code_style: styles.get("blame-code-style").copied(),
blame_palette,
blame_timestamp_format: opt.blame_timestamp_format,
commit_style: styles["commit-style"],
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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),
StyleSectionSpecifier::Style(style),
StyleSectionSpecifier::Style(self.config.blame_code_style.unwrap_or(style)),
self.state.clone(),
BgShouldFill::default(),
);
Expand Down
1 change: 1 addition & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub fn set_options(

set_options!(
[
blame_code_style,
blame_format,
blame_palette,
blame_timestamp_format,
Expand Down
13 changes: 13 additions & 0 deletions src/parse_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ pub fn parse_styles(opt: &cli::Opt) -> HashMap<String, Style> {
_ => *style::GIT_DEFAULT_PLUS_STYLE,
}),
);
if let Some(style_string) = &opt.blame_code_style {
styles.insert(
"blame-code-style",
style_from_str(
style_string,
None,
None,
opt.computed.true_color,
opt.git_config.as_ref(),
),
);
};

let mut resolved_styles = resolve_style_references(styles, opt);
resolved_styles.get_mut("minus-emph-style").unwrap().is_emph = true;
resolved_styles.get_mut("plus-emph-style").unwrap().is_emph = true;
Expand Down