diff --git a/kittens/diff/config.py b/kittens/diff/config.py index de5b678a6..0715967bb 100644 --- a/kittens/diff/config.py +++ b/kittens/diff/config.py @@ -9,6 +9,7 @@ from kitty.config_utils import ( resolve_config, to_color ) from kitty.constants import config_dir +from kitty.rgb import color_as_sgr defaults = None default_config_path = os.path.join( @@ -21,10 +22,17 @@ formats = { 'text': '', } + +def set_formats(opts): + formats['text'] = '38' + color_as_sgr(opts.foreground) + ';48' + color_as_sgr(opts.background) + formats['margin'] = '38' + color_as_sgr(opts.margin_fg) + ';48' + color_as_sgr(opts.margin_bg) + formats['title'] = '38' + color_as_sgr(opts.title_fg) + ';48' + color_as_sgr(opts.title_bg) + ';1' + + type_map = {} for name in ( - 'foreground background' + 'foreground background title_fg title_bg' ).split(): type_map[name] = to_color @@ -76,4 +84,5 @@ def init_config(args): config = tuple(resolve_config(SYSTEM_CONF, defconf, args.config)) overrides = (a.replace('=', ' ', 1) for a in args.override or ()) opts = load_config(*config, overrides=overrides) + set_formats(opts) return opts diff --git a/kittens/diff/diff.conf b/kittens/diff/diff.conf index 0a83c564a..32da0a320 100644 --- a/kittens/diff/diff.conf +++ b/kittens/diff/diff.conf @@ -1,2 +1,6 @@ foreground black background #eeeeee +title_fg black +title_bg #eeeeee +margin_bg #dddddd +margin_fg #444444 diff --git a/kittens/diff/render.py b/kittens/diff/render.py index 3efd9c7c4..d5114e680 100644 --- a/kittens/diff/render.py +++ b/kittens/diff/render.py @@ -4,7 +4,6 @@ import re from gettext import gettext as _ -from functools import partial from kitty.fast_data_types import wcswidth @@ -70,14 +69,17 @@ def fit_in(text, count): return text + '…' -def formatted(fmt, text): - return '\x1b[' + fmt + 'm' + text + '\x1b[0m' +def format_func(which): + def formatted(text): + fmt = formats[which] + return '\x1b[' + fmt + 'm' + text + '\x1b[0m' + formatted.__name__ = which + '_format' + return formatted -title_format = partial(formatted, formats['title']) -margin_format = partial(formatted, formats['margin']) -text_format = partial(formatted, formats['text']) -del formatted +text_format = format_func('text') +title_format = format_func('title') +margin_format = format_func('margin') def place_in(text, sz): diff --git a/kitty/rgb.py b/kitty/rgb.py index 92c1bbbc1..95598b97d 100644 --- a/kitty/rgb.py +++ b/kitty/rgb.py @@ -39,6 +39,10 @@ def color_as_sharp(x): return '#{:02x}{:02x}{:02x}'.format(*x) +def color_as_sgr(x): + return ':2:{}:{}:{}'.format(*x) + + def to_color(raw, validate=False): # See man XParseColor x = raw.strip().lower()