diff --git a/kitty/cli.py b/kitty/cli.py index a8b05e23b..0241d135e 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -2,13 +2,14 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2017, Kovid Goyal +import os import re import subprocess import sys from collections import deque -from .config import load_config -from .constants import appname, defconf, is_macos, str_version +from .config import compare_opts, load_config +from .constants import appname, defconf, is_macos, is_wayland, str_version from .layout import all_layouts OPTIONS = ''' @@ -133,6 +134,11 @@ Debug OpenGL commands. This will cause all OpenGL calls to check for errors inst --debug-font-fallback type=bool-set Print out information about the selection of fallback fonts for characters not present in the main font. + + +--debug-config +type=bool-set +Print out information about the system and kitty configuration. ''' @@ -491,8 +497,22 @@ def resolve_config(config_files_on_cmd_line): yield defconf -def create_opts(args): - config = resolve_config(args.config) +def create_opts(args, debug_config=False): + config = tuple(resolve_config(args.config)) + if debug_config: + print(appname, version) + print(' '.join(os.uname())) + if not is_macos: + print('Running under:', 'Wayland' if is_wayland else 'X11') + if os.path.exists('/etc/issue'): + print(open('/etc/issue', encoding='utf-8', errors='replace').read().strip()) + if os.path.exists('/etc/lsb-release'): + print(open('/etc/lsb-release', encoding='utf-8', errors='replace').read().strip()) + config = tuple(x for x in config if os.path.exists(x)) + if config: + print('Config files:', ', '.join(config)) overrides = (a.replace('=', ' ', 1) for a in args.override or ()) opts = load_config(*config, overrides=overrides) + if debug_config: + compare_opts(opts) return opts diff --git a/kitty/config.py b/kitty/config.py index 69218663f..66d65a530 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -492,3 +492,50 @@ def prepare_config_file_for_editing(): with open(defconf, 'w') as f: f.write(commented_out_default_config()) return defconf + + +def print_shortcut(key, action): + if not getattr(print_shortcut, 'maps', None): + from kitty.keys import defines + v = vars(defines) + mmap = {m.split('_')[-1].lower(): x for m, x in v.items() if m.startswith('GLFW_MOD_')} + kmap = {k.split('_')[-1].lower(): x for k, x in v.items() if k.startswith('GLFW_KEY_')} + krmap = {v: k for k, v in kmap.items()} + print_shortcut.maps = mmap, krmap + mmap, krmap = print_shortcut.maps + names = [] + mods, key = key + for name, val in mmap.items(): + if mods & val: + names.append(name) + if key: + names.append(krmap[key]) + print('\t', '+'.join(names), action) + + +def compare_keymaps(final, initial): + added = set(final) - set(initial) + removed = set(initial) - set(final) + changed = {k for k in set(final) & set(initial) if final[k] != initial[k]} + if added: + print('Added shortcuts:') + for k in added: + print_shortcut(k, final[k]) + if removed: + print('Removed shortcuts:') + for k in removed: + print_shortcut(k, initial[k]) + if changed: + print('Changed shortcuts:') + for k in changed: + print_shortcut(k, final[k]) + + +def compare_opts(opts): + print('\nConfig options different from defaults:') + for f in sorted(defaults._fields): + if getattr(opts, f) != getattr(defaults, f): + if f == 'keymap': + compare_keymaps(opts.keymap, defaults.keymap) + else: + print(f, getattr(opts, f)) diff --git a/kitty/main.py b/kitty/main.py index cf68e41a8..d1ee39ef0 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -145,6 +145,9 @@ def _main(): os.chdir(os.path.expanduser('~')) args, rest = parse_args(args=args) args.args = rest + if args.debug_config: + create_opts(args, debug_config=True) + return if getattr(args, 'detach', False): detach() if args.cmd: