Get rid of the default diff.conf
This commit is contained in:
parent
2b0d8bfe46
commit
d39cf5d702
21
docs/conf.py
21
docs/conf.py
@ -255,7 +255,7 @@ def add_html_context(app, pagename, templatename, context, *args):
|
|||||||
|
|
||||||
|
|
||||||
# CLI docs {{{
|
# CLI docs {{{
|
||||||
def write_cli_docs():
|
def write_cli_docs(all_kitten_names):
|
||||||
from kitty.cli import option_spec_as_rst
|
from kitty.cli import option_spec_as_rst
|
||||||
with open('generated/cli-kitty.rst', 'w') as f:
|
with open('generated/cli-kitty.rst', 'w') as f:
|
||||||
f.write(option_spec_as_rst(appname='kitty').replace(
|
f.write(option_spec_as_rst(appname='kitty').replace(
|
||||||
@ -274,8 +274,8 @@ def write_cli_docs():
|
|||||||
p('kitty @', func.name + '\n' + '-' * 120)
|
p('kitty @', func.name + '\n' + '-' * 120)
|
||||||
p('.. program::', 'kitty @', func.name)
|
p('.. program::', 'kitty @', func.name)
|
||||||
p('\n\n' + as_rst(*cli_params_for(func)))
|
p('\n\n' + as_rst(*cli_params_for(func)))
|
||||||
from kittens.runner import all_kitten_names, get_kitten_cli_docs
|
from kittens.runner import get_kitten_cli_docs
|
||||||
for kitten in all_kitten_names():
|
for kitten in all_kitten_names:
|
||||||
data = get_kitten_cli_docs(kitten)
|
data = get_kitten_cli_docs(kitten)
|
||||||
if data:
|
if data:
|
||||||
with open(f'generated/cli-kitten-{kitten}.rst', 'w') as f:
|
with open(f'generated/cli-kitten-{kitten}.rst', 'w') as f:
|
||||||
@ -448,7 +448,7 @@ def process_shortcut_link(env, refnode, has_explicit_title, title, target):
|
|||||||
return title, target
|
return title, target
|
||||||
|
|
||||||
|
|
||||||
def write_conf_docs(app):
|
def write_conf_docs(app, all_kitten_names):
|
||||||
app.add_object_type(
|
app.add_object_type(
|
||||||
'opt', 'opt',
|
'opt', 'opt',
|
||||||
indextemplate="pair: %s; Config Setting",
|
indextemplate="pair: %s; Config Setting",
|
||||||
@ -473,6 +473,13 @@ def write_conf_docs(app):
|
|||||||
print('.. highlight:: ini\n', file=f)
|
print('.. highlight:: ini\n', file=f)
|
||||||
f.write(render_conf('kitty', all_options.values()))
|
f.write(render_conf('kitty', all_options.values()))
|
||||||
|
|
||||||
|
from kittens.runner import get_kitten_conf_docs
|
||||||
|
for kitten in all_kitten_names:
|
||||||
|
all_options = get_kitten_conf_docs(kitten)
|
||||||
|
if all_options:
|
||||||
|
with open(f'generated/conf-kitten-{kitten}.rst', 'w', encoding='utf-8') as f:
|
||||||
|
print('.. highlight:: ini\n', file=f)
|
||||||
|
f.write(render_conf(kitten, all_options.values()))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
@ -481,8 +488,10 @@ def setup(app):
|
|||||||
os.mkdir('generated')
|
os.mkdir('generated')
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
write_cli_docs()
|
from kittens.runner import all_kitten_names
|
||||||
write_conf_docs(app)
|
all_kitten_names = all_kitten_names()
|
||||||
|
write_cli_docs(all_kitten_names)
|
||||||
|
write_conf_docs(app, all_kitten_names)
|
||||||
app.add_role('link', link_role)
|
app.add_role('link', link_role)
|
||||||
app.add_role('iss', partial(num_role, 'issues'))
|
app.add_role('iss', partial(num_role, 'issues'))
|
||||||
app.add_role('pull', partial(num_role, 'pull'))
|
app.add_role('pull', partial(num_role, 'pull'))
|
||||||
|
|||||||
@ -86,16 +86,16 @@ Restore default context ``=``
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Configuring kitty-diff
|
Configuration
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
You can configure the colors used, keyboard shortcuts, the diff implementation,
|
You can configure the colors used, keyboard shortcuts, the diff implementation,
|
||||||
the default lines of context, etc. by creating a diff.conf in your :ref:`kitty
|
the default lines of context, etc. by creating a :file:`diff.conf` file in
|
||||||
config folder <confloc>`. The default :file:`diff.conf` is below.
|
your :ref:`kitty config folder <confloc>`. See below for the supported
|
||||||
|
configuration directives.
|
||||||
|
|
||||||
.. literalinclude:: ../../kittens/diff/diff.conf
|
|
||||||
:language: ini
|
|
||||||
|
|
||||||
|
.. include:: /generated/conf-kitten-diff.rst
|
||||||
|
|
||||||
|
|
||||||
Integrating with git
|
Integrating with git
|
||||||
|
|||||||
@ -5,17 +5,16 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from kitty.conf.utils import (
|
from kitty.conf.utils import (
|
||||||
init_config, key_func, load_config as _load_config, merge_dicts,
|
init_config as _init_config, key_func, load_config as _load_config, merge_dicts,
|
||||||
parse_config_base, parse_kittens_key, python_string, resolve_config,
|
parse_config_base, parse_kittens_key, resolve_config
|
||||||
to_color
|
|
||||||
)
|
)
|
||||||
|
from kitty.conf.definition import config_lines
|
||||||
from kitty.constants import config_dir
|
from kitty.constants import config_dir
|
||||||
from kitty.rgb import color_as_sgr
|
from kitty.rgb import color_as_sgr
|
||||||
|
|
||||||
|
from .config_data import type_map, all_options
|
||||||
|
|
||||||
defaults = None
|
defaults = None
|
||||||
default_config_path = os.path.join(
|
|
||||||
os.path.dirname(os.path.abspath(__file__)), 'diff.conf'
|
|
||||||
)
|
|
||||||
|
|
||||||
formats = {
|
formats = {
|
||||||
'title': '',
|
'title': '',
|
||||||
@ -39,26 +38,6 @@ def set_formats(opts):
|
|||||||
formats['added_highlight'] = '48' + color_as_sgr(opts.highlight_added_bg)
|
formats['added_highlight'] = '48' + color_as_sgr(opts.highlight_added_bg)
|
||||||
|
|
||||||
|
|
||||||
def syntax_aliases(raw):
|
|
||||||
ans = {}
|
|
||||||
for x in raw.split():
|
|
||||||
a, b = x.partition(':')[::2]
|
|
||||||
if a and b:
|
|
||||||
ans[a.lower()] = b
|
|
||||||
return ans
|
|
||||||
|
|
||||||
|
|
||||||
type_map = {
|
|
||||||
'syntax_aliases': syntax_aliases,
|
|
||||||
'num_context_lines': int,
|
|
||||||
'replace_tab_by': python_string,
|
|
||||||
}
|
|
||||||
|
|
||||||
for name in (
|
|
||||||
'foreground background title_fg title_bg margin_bg margin_fg removed_bg removed_margin_bg added_bg added_margin_bg filler_bg hunk_bg hunk_margin_bg'
|
|
||||||
' highlight_removed_bg highlight_added_bg'
|
|
||||||
).split():
|
|
||||||
type_map[name] = to_color
|
|
||||||
func_with_args, args_funcs = key_func()
|
func_with_args, args_funcs = key_func()
|
||||||
|
|
||||||
|
|
||||||
@ -125,7 +104,7 @@ def parse_defaults(lines, check_keys=False):
|
|||||||
return parse_config(lines, check_keys)
|
return parse_config(lines, check_keys)
|
||||||
|
|
||||||
|
|
||||||
Options, defaults = init_config(default_config_path, parse_defaults)
|
Options, defaults = _init_config(config_lines(all_options), parse_defaults)
|
||||||
|
|
||||||
|
|
||||||
def load_config(*paths, overrides=None):
|
def load_config(*paths, overrides=None):
|
||||||
|
|||||||
111
kittens/diff/config_data.py
Normal file
111
kittens/diff/config_data.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
# Utils {{{
|
||||||
|
from gettext import gettext as _
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from kitty.conf.definition import option_func
|
||||||
|
from kitty.conf.utils import (
|
||||||
|
positive_int, python_string, to_color
|
||||||
|
)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
all_options = {}
|
||||||
|
o, k, g, all_groups = option_func(all_options, {
|
||||||
|
'colors': [_('Colors')],
|
||||||
|
'diff': [_('Diffing'), ],
|
||||||
|
'shortcuts': [_('Keyboard shortcuts')],
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
g('diff')
|
||||||
|
|
||||||
|
|
||||||
|
def syntax_aliases(raw):
|
||||||
|
ans = {}
|
||||||
|
for x in raw.split():
|
||||||
|
a, b = x.partition(':')[::2]
|
||||||
|
if a and b:
|
||||||
|
ans[a.lower()] = b
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
o('syntax_aliases', 'pyj:py recipe:py', option_type=syntax_aliases, long_text=_('''
|
||||||
|
File extension aliases for syntax highlight
|
||||||
|
For example, to syntax highlight :file:`file.xyz` as
|
||||||
|
:file:`file.abc` use a setting of :code:`xyz:abc`
|
||||||
|
'''))
|
||||||
|
|
||||||
|
o('num_context_lines', 3, option_type=positive_int, long_text=_('''
|
||||||
|
The number of lines of context to show around each change.'''))
|
||||||
|
|
||||||
|
o('diff_cmd', 'auto', long_text=_('''
|
||||||
|
The diff command to use. Must contain the placeholder :code:`_CONTEXT_`
|
||||||
|
which will be replaced by the number of lines of context. The default
|
||||||
|
is to search the system for either git or diff and use that, if found.
|
||||||
|
'''))
|
||||||
|
|
||||||
|
o('replace_tab_by', r'\x20\x20\x20\x20', option_type=python_string, long_text=_('''
|
||||||
|
The string to replace tabs with. Default is to use four spaces.'''))
|
||||||
|
|
||||||
|
|
||||||
|
g('colors')
|
||||||
|
|
||||||
|
o('pygments_style', 'default', long_text=_('''
|
||||||
|
The pygments color scheme to use for syntax highlighting.
|
||||||
|
See :link:`pygments colors schemes <https://help.farbox.com/pygments.html>` for a list of schemes.'''))
|
||||||
|
|
||||||
|
|
||||||
|
c = partial(o, option_type=to_color)
|
||||||
|
c('foreground', 'black', long_text=_('Basic colors'))
|
||||||
|
c('background', 'white')
|
||||||
|
|
||||||
|
c('title_fg', 'black', long_text=_('Title colors'))
|
||||||
|
c('title_bg', 'white')
|
||||||
|
|
||||||
|
c('margin_bg', '#fafbfc', long_text=_('Margin colors'))
|
||||||
|
c('margin_fg', '#aaaaaa')
|
||||||
|
|
||||||
|
c('removed_bg', '#ffeef0', long_text=_('Removed text backgrounds'))
|
||||||
|
c('highlight_removed_bg', '#fdb8c0')
|
||||||
|
c('removed_margin_bg', '#ffdce0')
|
||||||
|
|
||||||
|
c('added_bg', '#e6ffed', long_text=_('Added text backgrounds'))
|
||||||
|
c('highlight_added_bg', '#acf2bd')
|
||||||
|
c('added_margin_bg', '#cdffd8')
|
||||||
|
|
||||||
|
c('filler_bg', '#fafbfc', long_text=_('Filler (empty) line background'))
|
||||||
|
|
||||||
|
c('hunk_margin_bg', '#dbedff', long_text=_('Hunk header colors'))
|
||||||
|
c('hunk_bg', '#f1f8ff')
|
||||||
|
|
||||||
|
|
||||||
|
g('shortcuts')
|
||||||
|
k('quit', 'q', 'quit', _('Quit'))
|
||||||
|
k('quit', 'esc', 'quit', _('Quit'))
|
||||||
|
|
||||||
|
k('scroll_down', 'j', 'scroll_by 1', _('Scroll down'))
|
||||||
|
k('scroll_down', 'down', 'scroll_by 1', _('Scroll down'))
|
||||||
|
k('scroll_up', 'k', 'scroll_by -1', _('Scroll up'))
|
||||||
|
k('scroll_up', 'up', 'scroll_by -1', _('Scroll up'))
|
||||||
|
|
||||||
|
k('scroll_top', 'home', 'scroll_to start', _('Scroll to top'))
|
||||||
|
k('scroll_bottom', 'end', 'scroll_to end', _('Scroll to bottom'))
|
||||||
|
|
||||||
|
k('scroll_page_down', 'page_down', 'scroll_to next-page', _('Scroll to next page'))
|
||||||
|
k('scroll_page_down', 'space', 'scroll_to next-page', _('Scroll to next page'))
|
||||||
|
k('scroll_page_up', 'page_up', 'scroll_to prev-page', _('Scroll to previous page'))
|
||||||
|
|
||||||
|
k('next_change', 'n', 'scroll_to next-change', _('Scroll to next change'))
|
||||||
|
k('prev_change', 'p', 'scroll_to prev-change', _('Scroll to previous change'))
|
||||||
|
|
||||||
|
k('all_context', 'a', 'change_context all', _('Show all context'))
|
||||||
|
k('default_context', '=', 'change_context default', _('Show default context'))
|
||||||
|
k('increase_context', '+', 'change_context 5', _('Increase context'))
|
||||||
|
k('decrease_context', '-', 'change_context -5', _('Decrease context'))
|
||||||
|
|
||||||
|
type_map = {o.name: o.option_type for o in all_options.values() if hasattr(o, 'option_type')}
|
||||||
@ -1,58 +0,0 @@
|
|||||||
# vim:fileencoding=utf-8:ft=conf
|
|
||||||
|
|
||||||
# File extension aliases for syntax highlight
|
|
||||||
# For example, to syntax highlight file.xyz as
|
|
||||||
# file.abc use a setting of xyz:abc
|
|
||||||
syntax_aliases pyj:py recipe:py
|
|
||||||
|
|
||||||
# The pygments color scheme to use for syntax highlighting.
|
|
||||||
# See https://help.farbox.com/pygments.html for a list of schemes.
|
|
||||||
pygments_style default
|
|
||||||
|
|
||||||
# The number of lines of context to show around each change.
|
|
||||||
num_context_lines 3
|
|
||||||
|
|
||||||
# The diff command to use. Must contain the placeholder _CONTEXT_
|
|
||||||
# which will be replaced by the number of lines of context. The default
|
|
||||||
# is to search the system for either git or diff and use that, if found.
|
|
||||||
diff_cmd auto
|
|
||||||
|
|
||||||
# The string to replace tabs with. Default is to use four spaces.
|
|
||||||
replace_tab_by \x20\x20\x20\x20
|
|
||||||
|
|
||||||
# Colors
|
|
||||||
foreground black
|
|
||||||
background white
|
|
||||||
title_fg black
|
|
||||||
title_bg white
|
|
||||||
margin_bg #fafbfc
|
|
||||||
margin_fg #aaaaaa
|
|
||||||
removed_bg #ffeef0
|
|
||||||
highlight_removed_bg #fdb8c0
|
|
||||||
removed_margin_bg #ffdce0
|
|
||||||
added_bg #e6ffed
|
|
||||||
highlight_added_bg #acf2bd
|
|
||||||
added_margin_bg #cdffd8
|
|
||||||
filler_bg #fafbfc
|
|
||||||
hunk_margin_bg #dbedff
|
|
||||||
hunk_bg #f1f8ff
|
|
||||||
|
|
||||||
|
|
||||||
# Keyboard shortcuts
|
|
||||||
map q quit
|
|
||||||
map esc quit
|
|
||||||
map j scroll_by 1
|
|
||||||
map k scroll_by -1
|
|
||||||
map down scroll_by 1
|
|
||||||
map up scroll_by -1
|
|
||||||
map home scroll_to start
|
|
||||||
map end scroll_to end
|
|
||||||
map page_down scroll_to next-page
|
|
||||||
map page_up scroll_to prev-page
|
|
||||||
map space scroll_to next-page
|
|
||||||
map n scroll_to next-change
|
|
||||||
map p scroll_to prev-change
|
|
||||||
map a change_context all
|
|
||||||
map = change_context default
|
|
||||||
map + change_context 5
|
|
||||||
map - change_context -5
|
|
||||||
@ -419,3 +419,6 @@ elif __name__ == '__doc__':
|
|||||||
sys.cli_docs['usage'] = usage
|
sys.cli_docs['usage'] = usage
|
||||||
sys.cli_docs['options'] = OPTIONS
|
sys.cli_docs['options'] = OPTIONS
|
||||||
sys.cli_docs['help_text'] = help_text
|
sys.cli_docs['help_text'] = help_text
|
||||||
|
elif __name__ == '__conf__':
|
||||||
|
from .config import all_options
|
||||||
|
sys.all_options = all_options
|
||||||
|
|||||||
@ -110,6 +110,14 @@ def get_kitten_cli_docs(kitten):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
def get_kitten_conf_docs(kitten):
|
||||||
|
sys.all_options = None
|
||||||
|
run_kitten(kitten, run_name='__conf__')
|
||||||
|
ans = sys.all_options
|
||||||
|
del sys.all_options
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user