Wire up color handling in the diff kitten

This commit is contained in:
Kovid Goyal 2018-04-24 10:58:15 +05:30
parent 5c4b14468c
commit 7a543fac86
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 27 additions and 8 deletions

View File

@ -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

View File

@ -1,2 +1,6 @@
foreground black
background #eeeeee
title_fg black
title_bg #eeeeee
margin_bg #dddddd
margin_fg #444444

View File

@ -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):

4
kitty/rgb.py generated
View File

@ -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()