Skip to content

Commit

Permalink
diff kitten: New option to control the background color for filler li…
Browse files Browse the repository at this point in the history
…nes in the margin

Fixes #2518
  • Loading branch information
kovidgoyal committed Apr 8, 2020
1 parent e39df50 commit 4e7bf80
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- Render known country flags designated by a pair of unicode codepoints
in two cells instead of four.

- diff kitten: New option to control the background color for filler lines in
the margin (:iss:`2518`)


0.17.2 [2020-03-29]
--------------------
Expand Down
3 changes: 2 additions & 1 deletion kittens/diff/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

defaults: Optional[DiffOptions] = None

formats = {
formats: Dict[str, str] = {
'title': '',
'margin': '',
'text': '',
Expand All @@ -35,6 +35,7 @@ def set_formats(opts: DiffOptions) -> None:
formats['added'] = '48' + color_as_sgr(opts.added_bg)
formats['removed'] = '48' + color_as_sgr(opts.removed_bg)
formats['filler'] = '48' + color_as_sgr(opts.filler_bg)
formats['margin_filler'] = '48' + color_as_sgr(opts.margin_filler_bg or opts.filler_bg)
formats['hunk_margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_margin_bg)
formats['hunk'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.hunk_bg)
formats['removed_highlight'] = '48' + color_as_sgr(opts.highlight_removed_bg)
Expand Down
6 changes: 5 additions & 1 deletion kittens/diff/config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from typing import Any, Dict, Sequence, Union

from kitty.conf.definition import Option, Shortcut, option_func
from kitty.conf.utils import positive_int, python_string, to_color
from kitty.conf.utils import (
positive_int, python_string, to_color, to_color_or_none
)

# }}}

Expand Down Expand Up @@ -78,6 +80,8 @@ def syntax_aliases(raw: str) -> Dict[str, str]:
c('added_margin_bg', '#cdffd8')

c('filler_bg', '#fafbfc', long_text=_('Filler (empty) line background'))
c('margin_filler_bg', 'none', option_type=to_color_or_none, long_text=_(
'Filler (empty) line background in margins, defaults to the filler background'))

c('hunk_margin_bg', '#dbedff', long_text=_('Hunk header colors'))
c('hunk_bg', '#f1f8ff')
Expand Down
3 changes: 2 additions & 1 deletion kittens/diff/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def formatted(text: str) -> str:
removed_margin_format = format_func('removed_margin')
added_margin_format = format_func('added_margin')
filler_format = format_func('filler')
margin_filler_format = format_func('margin_filler')
hunk_margin_format = format_func('hunk_margin')
hunk_format = format_func('hunk')
highlight_map = {'remove': ('removed_highlight', 'removed'), 'add': ('added_highlight', 'added')}
Expand Down Expand Up @@ -214,7 +215,7 @@ def split_with_highlights(line: str, width: int, highlights: List, bg_highlight:
return _split_with_highlights(line, truncate_pts, highlights, bg_highlight)


margin_bg_map = {'filler': filler_format, 'remove': removed_margin_format, 'add': added_margin_format, 'context': margin_format}
margin_bg_map = {'filler': margin_filler_format, 'remove': removed_margin_format, 'add': added_margin_format, 'context': margin_format}
text_bg_map = {'filler': filler_format, 'remove': removed_format, 'add': added_format, 'context': text_format}


Expand Down

0 comments on commit 4e7bf80

Please sign in to comment.