mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 00:08:04 +02:00
Wire up color handling in the diff kitten
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
foreground black
|
||||
background #eeeeee
|
||||
title_fg black
|
||||
title_bg #eeeeee
|
||||
margin_bg #dddddd
|
||||
margin_fg #444444
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user