mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-16 13:08:25 +00:00
The new render_interval option either syncs redraws to the monitor (the default), optionally with a minimum interval between frames, or redraws on a schedule with a minimum interval between frames. The interval is now enforced per OS window, including when output is being parsed, which the old repaint_delay was not. On X11, render frames are now provided by the Present extension, with libxcb-present loaded at runtime. Frames are requested lazily on X11, since a pending NotifyMSC request delays buffer presentation by the GPU driver under Xwayland. Xwayland completing requests early and failing to report vertical blanks for long periods are handled. Without Present, kitty falls back to blocking buffer swaps as before. Render frames now only wake up the main loop when something is waiting for them, so animations such as the eased cursor blink are no longer sampled at the monitor refresh rate. On Wayland, frame callbacks are also used when not syncing to the monitor, to stop rendering hidden windows. The removed options are converted to render_interval if it is not specified anywhere, including in other config files and overrides, otherwise they are ignored with a warning. Also fix gen config failing on options whose type is a builtin.
749 lines
33 KiB
Python
749 lines
33 KiB
Python
#!/usr/bin/env python
|
|
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
from kitty.constants import SOFTWARE_GPU_DRIVERS, available_gpu_drivers, gpu_driver_path, kitty_exe
|
|
from kitty.fast_data_types import Color, test_cursor_blink_easing_function
|
|
from kitty.options.utils import DELETE_ENV_VAR, EasingFunction, build_action_aliases, to_color
|
|
from kitty.utils import log_error, shlex_split
|
|
|
|
from .base import BaseTest
|
|
|
|
|
|
class TestConfParsing(BaseTest):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.error_messages = []
|
|
log_error.redirect = self.error_messages.append
|
|
self.tdir = tempfile.mkdtemp()
|
|
|
|
def tearDown(self):
|
|
del log_error.redirect
|
|
shutil.rmtree(self.tdir)
|
|
super().tearDown()
|
|
|
|
def test_conf_parsing(self):
|
|
conf_parsing(self)
|
|
|
|
def test_launcher(self):
|
|
launcher(self)
|
|
|
|
def test_cli_parsing(self):
|
|
cli_parsing(self)
|
|
|
|
def test_render_interval(self):
|
|
render_interval_parsing(self)
|
|
|
|
def test_font_size_clamping(self):
|
|
font_size_clamping(self)
|
|
|
|
def test_patch_global_special_colors(self):
|
|
from kitty.fast_data_types import patch_global_colors
|
|
|
|
self.set_options()
|
|
try:
|
|
for name, value in (
|
|
('wayland_titlebar_color', 0x80000002),
|
|
('scrollbar_handle_color', 0xFF000002),
|
|
('scrollbar_track_color', 0xFFFFFF02),
|
|
('macos_titlebar_color', -1),
|
|
('macos_titlebar_color', -2),
|
|
):
|
|
with self.subTest(name=name, value=value):
|
|
patch_global_colors({name: value}, False)
|
|
# These options are decoded as unsigned, so negative values must be
|
|
# rejected on all platforms, not silently stored.
|
|
for name in ('wayland_titlebar_color', 'scrollbar_handle_color', 'scrollbar_track_color'):
|
|
with self.subTest(name=name, value=-1), self.assertRaises(OverflowError):
|
|
patch_global_colors({name: -1}, False)
|
|
finally:
|
|
self.set_options()
|
|
|
|
def test_session_launch_option_expansion(self) -> None:
|
|
from kitty.launch import LaunchSpec
|
|
from kitty.options.types import defaults
|
|
from kitty.session import parse_session
|
|
|
|
for command in (
|
|
'--title bash --cwd $SESSION_DIR bash $COMMAND_ARG',
|
|
'--title=bash --cwd=$SESSION_DIR bash $COMMAND_ARG',
|
|
'--title bash --cwd $SESSION_DIR -- bash $COMMAND_ARG',
|
|
'--title other --cwd $SESSION_DIR bash $COMMAND_ARG',
|
|
):
|
|
with self.subTest(command=command):
|
|
(session,) = parse_session(f'launch {command}', defaults, environ={'SESSION_DIR': '/tmp/session', 'COMMAND_ARG': 'expanded'})
|
|
spec = session.tabs[0].windows[0].launch_spec
|
|
assert isinstance(spec, LaunchSpec)
|
|
self.ae(spec.opts.cwd, '/tmp/session')
|
|
self.ae(spec.args, ['bash', '$COMMAND_ARG'])
|
|
|
|
def test_session_discovery(self):
|
|
from unittest.mock import patch
|
|
|
|
from kitty.config import load_config
|
|
from kitty.constants import config_dir
|
|
from kitty.fast_data_types import set_options
|
|
from kitty.session import get_all_known_sessions, seen_session_paths
|
|
|
|
def discover(*lines):
|
|
bad_lines = []
|
|
opts = load_config(overrides=('clear_all_shortcuts yes', *lines), accumulate_bad_lines=bad_lines)
|
|
self.assertFalse(bad_lines)
|
|
set_options(opts)
|
|
return get_all_known_sessions()
|
|
|
|
with patch.dict(seen_session_paths, {}, clear=True):
|
|
for args, name in (
|
|
('work.kitty-session', 'work'),
|
|
('--sort-by alphabetical work.kitty-session', 'work'),
|
|
('--sort-by=alphabetical work.kitty-session', 'work'),
|
|
('--active-only=no --sort-by recent work.kitty-session', 'work'),
|
|
('work.kitty-session --sort-by alphabetical', 'work'),
|
|
('-- "-work project.kitty-session"', '-work project'),
|
|
('-- -0', '-0'),
|
|
('', ''),
|
|
('--sort-by alphabetical', ''),
|
|
('--sort-by=alphabetical', ''),
|
|
('--active-only', ''),
|
|
('-1', ''),
|
|
('-- -1', ''),
|
|
('--sort-by alphabetical -- -2', ''),
|
|
('--sort-by', ''),
|
|
('--sort-by invalid work.kitty-session', ''),
|
|
('--unknown work.kitty-session', ''),
|
|
('--active-only=invalid work.kitty-session', ''),
|
|
):
|
|
with self.subTest(args=args):
|
|
filename = f'{name}.kitty-session' if name != '-0' else name
|
|
expected = {name: os.path.join(config_dir, filename)} if name else {}
|
|
self.ae(discover(f'map f7 goto_session {args}'), expected)
|
|
|
|
seen_path = os.path.join(self.tdir, 'work.kitty-session')
|
|
seen_session_paths['work'] = seen_path
|
|
self.ae(
|
|
discover(
|
|
'action_alias project goto_session --sort-by alphabetical',
|
|
'map f7 project work.kitty-session',
|
|
'map f8 combine : goto_session --sort-by : project other.kitty-session',
|
|
),
|
|
{'work': seen_path, 'other': os.path.join(config_dir, 'other.kitty-session')},
|
|
)
|
|
|
|
def test_launch_transparent_color_overrides(self) -> None:
|
|
from kitty.launch import apply_colors
|
|
from kitty.window import Window
|
|
|
|
cases = (
|
|
(('transparent_background_colors=#ffffff@0.5', 'foreground=red'), ((Color(255, 255, 255), 0.5),)),
|
|
(('foreground=red', 'transparent_background_colors=#ffffff@0.5'), ((Color(255, 255, 255), 0.5),)),
|
|
(('transparent_background_colors=#ffffff@0.5', 'foreground=red', 'transparent_background_colors='), ()),
|
|
(('transparent_background_colors=#ffffff@0.5', 'transparent_background_colors=#000000@0.25', 'foreground=red'), ((Color(0, 0, 0), 0.25),)),
|
|
)
|
|
for colors, expected in cases:
|
|
with self.subTest(colors=colors):
|
|
window = Window.__new__(Window)
|
|
window.screen = self.create_screen()
|
|
apply_colors(window, colors)
|
|
actual = window.screen.color_profile.as_dict()
|
|
self.ae(actual.get('transparent_background_colors', ()), expected)
|
|
self.ae(actual['foreground'], 0xFF0000)
|
|
|
|
# colors that do not mention transparent_background_colors must leave existing ones unchanged
|
|
window = Window.__new__(Window)
|
|
window.screen = self.create_screen()
|
|
apply_colors(window, ('transparent_background_colors=#ffffff@0.5',))
|
|
apply_colors(window, ('foreground=red',))
|
|
self.ae(window.screen.color_profile.as_dict().get('transparent_background_colors', ()), ((Color(255, 255, 255), 0.5),))
|
|
apply_colors(window, ('transparent_background_colors=',))
|
|
self.ae(window.screen.color_profile.as_dict().get('transparent_background_colors', ()), ())
|
|
|
|
|
|
def render_interval_parsing(self) -> None:
|
|
from kitty.config import load_config
|
|
from kitty.options.types import defaults
|
|
from kitty.options.utils import RenderInterval
|
|
|
|
bad_lines: list = []
|
|
|
|
def p(*lines: str, paths: tuple[str, ...] = (), bad_line_num: int = 0) -> RenderInterval:
|
|
del bad_lines[:]
|
|
del self.error_messages[:]
|
|
opts = load_config(*paths, overrides=lines, accumulate_bad_lines=bad_lines)
|
|
self.ae(len(bad_lines), bad_line_num, bad_lines)
|
|
return opts.render_interval
|
|
|
|
def write_conf(name: str, *lines: str) -> str:
|
|
path = os.path.join(self.tdir, name)
|
|
with open(path, 'w') as f:
|
|
f.write('\n'.join(lines))
|
|
return path
|
|
|
|
def warned_about_conflict() -> bool:
|
|
return any('as render_interval is also specified' in m for m in self.error_messages)
|
|
|
|
self.ae(defaults.render_interval, RenderInterval(True, 0))
|
|
self.ae(p(), RenderInterval(True, 0))
|
|
self.ae(p('render_interval monitor'), RenderInterval(True, 0))
|
|
self.ae(p('render_interval Monitor 16.5'), RenderInterval(True, 16.5))
|
|
self.ae(p('render_interval 8'), RenderInterval(False, 8))
|
|
self.ae(p('render_interval 0'), RenderInterval(False, 0))
|
|
for bad in ('xyz', 'monitor 1 2', '-1', 'monitor -3', 'nan', '1 monitor'):
|
|
self.ae(p(f'render_interval {bad}', bad_line_num=1), defaults.render_interval, bad)
|
|
for ri in (RenderInterval(True, 0), RenderInterval(True, 16.5), RenderInterval(False, 8)):
|
|
self.ae(p(f'render_interval {ri}'), ri)
|
|
|
|
# The removed options are converted to render_interval
|
|
self.ae(p('sync_to_monitor yes'), RenderInterval(True, 0))
|
|
self.ae(p('sync_to_monitor no'), RenderInterval(False, 10))
|
|
self.ae(p('repaint_delay 5'), RenderInterval(True, 5))
|
|
self.ae(p('repaint_delay 0'), RenderInterval(True, 0))
|
|
self.ae(p('sync_to_monitor no', 'repaint_delay 3'), RenderInterval(False, 3))
|
|
self.ae(p('repaint_delay 3', 'sync_to_monitor no'), RenderInterval(False, 3))
|
|
self.ae(p('sync_to_monitor no', 'repaint_delay 3', 'sync_to_monitor yes'), RenderInterval(True, 3))
|
|
self.ae(p('repaint_delay 3', 'repaint_delay 7'), RenderInterval(True, 7))
|
|
self.ae(p('repaint_delay x', bad_line_num=1), defaults.render_interval)
|
|
self.assertFalse(warned_about_conflict())
|
|
# render_interval takes precedence over the removed options regardless of order
|
|
for lines in (('render_interval monitor', 'sync_to_monitor no'), ('sync_to_monitor no', 'repaint_delay 2', 'render_interval monitor')):
|
|
self.ae(p(*lines), RenderInterval(True, 0))
|
|
self.assertTrue(warned_about_conflict())
|
|
self.ae(p('repaint_delay 2', 'render_interval 6'), RenderInterval(False, 6))
|
|
self.assertTrue(warned_about_conflict())
|
|
|
|
# Precedence and conversion work across config files and overrides
|
|
new_conf = write_conf('new.conf', 'render_interval 8')
|
|
old_conf = write_conf('old.conf', 'sync_to_monitor no')
|
|
included = write_conf('included.conf', 'include old.conf', 'repaint_delay 4')
|
|
self.ae(p(paths=(new_conf,)), RenderInterval(False, 8))
|
|
self.ae(p('sync_to_monitor yes', 'repaint_delay 2', paths=(new_conf,)), RenderInterval(False, 8))
|
|
self.assertTrue(warned_about_conflict())
|
|
self.ae(p(paths=(new_conf, old_conf)), RenderInterval(False, 8))
|
|
self.ae(p(paths=(old_conf, new_conf)), RenderInterval(False, 8))
|
|
self.ae(p('render_interval monitor 20', paths=(old_conf,)), RenderInterval(True, 20))
|
|
self.ae(p(paths=(old_conf,)), RenderInterval(False, 10))
|
|
self.ae(p('repaint_delay 4', paths=(old_conf,)), RenderInterval(False, 4))
|
|
self.ae(p('sync_to_monitor yes', paths=(old_conf,)), RenderInterval(True, 0))
|
|
self.ae(p(paths=(included,)), RenderInterval(False, 4))
|
|
self.assertFalse(warned_about_conflict())
|
|
|
|
|
|
def cli_parsing(self):
|
|
from kitty.cli import CLIOptions, Options, parse_cmdline, parse_option_spec
|
|
|
|
seq, disabled = parse_option_spec("""\
|
|
--simple-string -s
|
|
a simple string
|
|
|
|
|
|
--list -l
|
|
type=list
|
|
a list
|
|
|
|
|
|
--choice -c
|
|
choices=a,b,c
|
|
some choices
|
|
|
|
|
|
--bool-set -1
|
|
type=bool-set
|
|
set a bool
|
|
|
|
|
|
--bool-reset -0
|
|
type=bool-reset
|
|
unset a bool
|
|
|
|
|
|
--int -i
|
|
type=int
|
|
a integer
|
|
|
|
|
|
--float -f
|
|
type=float
|
|
a float
|
|
|
|
|
|
--version -v
|
|
type=bool-set
|
|
version
|
|
""")
|
|
oc = Options(seq, usage='xxx', message='yyy', appname='test')
|
|
oc.do_print = False
|
|
|
|
def t(args, leftover=(), fails=False, version_called=False, help_called=False, **expected):
|
|
oc.help_called = oc.version_called = False
|
|
args = list(shlex_split(args))
|
|
ans = CLIOptions()
|
|
if fails:
|
|
if isinstance(fails, str):
|
|
with self.assertRaisesRegex(SystemExit, fails):
|
|
parse_cmdline(oc, disabled, ans, args=args)
|
|
else:
|
|
with self.assertRaises(SystemExit):
|
|
parse_cmdline(oc, disabled, ans, args=args)
|
|
else:
|
|
actual_leftover = parse_cmdline(oc, disabled, ans, args=args)
|
|
self.assertEqual(tuple(leftover), tuple(actual_leftover), f'{args}\n{ans}')
|
|
for dest, defval in oc.values_map.items():
|
|
val = expected.get(dest, defval)
|
|
self.assertEqual(val, getattr(ans, dest, BaseTest), f'Failed to parse {dest} correctly for: {args}\n{ans}')
|
|
self.assertEqual(version_called, oc.version_called, f'Failed to call version for: {args}\n{ans}')
|
|
self.assertEqual(help_called, oc.help_called, f'Failed to call help for: {args}\n{ans}')
|
|
|
|
t('-1', bool_set=True)
|
|
t('-01', bool_reset=False, bool_set=True)
|
|
t('-01=y', bool_reset=False, bool_set=True)
|
|
t('-01=n', bool_reset=False, bool_set=False)
|
|
t('--simple-string xx moo -1', leftover=['moo', '-1'], simple_string='xx')
|
|
t('--si -0 -- -1', leftover=['-1'], simple_string='-0')
|
|
t('--simple-string=-0 -- -1', leftover=['-1'], simple_string='-0')
|
|
t('--simple-string=--help -- -1', leftover=['-1'], simple_string='--help')
|
|
t('--simple-string --help -- -1', leftover=['-1'], simple_string='--help')
|
|
t('-1l=a --list=b -c b --list c', bool_set=True, choice='b', list=list('abc'))
|
|
t('-1s= -l "" --list= x', leftover=['x'], bool_set=True, simple_string='', list=['', ''])
|
|
t('--choice moo', fails=r'moo')
|
|
t('--bool', fails='mbiguous')
|
|
t('-1c moo', fails=r'moo')
|
|
t('-10c=moo', fails=r'moo')
|
|
t('-1 -h', fails=True, help_called=True)
|
|
t('-1 --help', fails=True, help_called=True)
|
|
t('-1 -0v', fails=True, version_called=True)
|
|
t('-1 -v0', fails=True, version_called=True)
|
|
t('-1 --version', fails=True, version_called=True)
|
|
t('-f=3.142 --int 17', float=3.142, int=17)
|
|
|
|
|
|
def font_size_clamping(self: 'BaseTest') -> None:
|
|
from kitty.options.utils import MAXIMUM_FONT_SIZE, MINIMUM_FONT_SIZE, clamp_font_size
|
|
|
|
# the floor applies whatever the configured size
|
|
self.ae(clamp_font_size(0, 11), MINIMUM_FONT_SIZE)
|
|
self.ae(clamp_font_size(-100, 11), MINIMUM_FONT_SIZE)
|
|
|
|
# sizes inside the range come back untouched
|
|
self.ae(clamp_font_size(11, 11), 11)
|
|
self.ae(clamp_font_size(64, 11), 64)
|
|
|
|
# the ceiling is the larger of the multiple and the absolute maximum, so a
|
|
# small configured size no longer implies a small maximum zoom
|
|
self.ae(clamp_font_size(1e6, 4), MAXIMUM_FONT_SIZE)
|
|
self.ae(clamp_font_size(1e6, 11), MAXIMUM_FONT_SIZE)
|
|
self.ae(clamp_font_size(200, 4), 200)
|
|
|
|
# a large configured size keeps its proportional ceiling
|
|
self.ae(clamp_font_size(1e6, 40), 400)
|
|
self.ae(clamp_font_size(1e6, 100), 1000)
|
|
|
|
# and the ceiling is never below the absolute maximum
|
|
for configured in (1, 4, 11, 25.6, 40, 100):
|
|
self.assertGreaterEqual(clamp_font_size(1e6, configured), MAXIMUM_FONT_SIZE)
|
|
|
|
|
|
def launcher(self):
|
|
import tempfile
|
|
|
|
from kitty.constants import is_macos
|
|
|
|
kexe = kitty_exe()
|
|
cfgdir = None
|
|
|
|
def get_report(cmdline: str, launch_services=False, config_dir: str = ''):
|
|
nonlocal cfgdir
|
|
args = list(shlex_split(cmdline))
|
|
env = dict(os.environ)
|
|
if launch_services:
|
|
env['KITTY_LAUNCHED_BY_LAUNCH_SERVICES'] = '1'
|
|
if config_dir:
|
|
env['KITTY_CONFIG_DIRECTORY'] = config_dir
|
|
cp = subprocess.run([kexe, '+testing-launcher-code'] + args, env=env, stdout=subprocess.PIPE)
|
|
self.assertEqual(cp.returncode, 0)
|
|
ans = {}
|
|
for line in cp.stdout.decode().split('\n'):
|
|
if not line:
|
|
continue
|
|
try:
|
|
key, val = line.split(':')
|
|
except ValueError:
|
|
raise AssertionError(f'Unexpected output from launcher: {line!r}\n{cp.stdout.decode()}')
|
|
if '\x1e' in val:
|
|
val = [x for x in val.split('\x1e') if x]
|
|
else:
|
|
val = val.strip()
|
|
ans[key] = val
|
|
if key == 'config_dir':
|
|
cfgdir = val
|
|
return ans, cp.stdout.decode().replace('\x1e', ' ')
|
|
|
|
def test(cmdline, assertions):
|
|
r, output = get_report(cmdline, launch_services=assertions.get('launched_by_launch_services', '0') != '0')
|
|
for key, expected in assertions.items():
|
|
self.assertEqual(expected, r.get(key), f'Failed for {key} with command line: {cmdline}\nOutput:\n{output}')
|
|
return output
|
|
|
|
def t(cmdline, **assertions):
|
|
assertions['is_quick_access_terminal'] = '0'
|
|
if cfgdir:
|
|
assertions['config_dir'] = cfgdir
|
|
assertions.setdefault('launched_by_launch_services', '0')
|
|
test(cmdline, assertions)
|
|
|
|
def si(cmdline, **assertions):
|
|
assertions['single_instance'] = '1'
|
|
test(cmdline, assertions)
|
|
|
|
def dt(cmdline, **assertions):
|
|
assertions['detach'] = 'true'
|
|
test(cmdline, assertions)
|
|
|
|
def k(cmdline):
|
|
assertions = {}
|
|
assertions['argv'] = ['kitten'] + cmdline.split()
|
|
for prefix in ('+kitten', '+ kitten'):
|
|
output = test(prefix + ' ' + cmdline, assertions)
|
|
self.assertIn('kitten_exe:', output)
|
|
|
|
def pn(cmdline, **assertions):
|
|
ig = assertions.get('instance_group')
|
|
assertions['instance_group'] = f'panel-{ig}' if ig else 'panel'
|
|
assertions['single_instance'] = '1'
|
|
assertions['session'] = ''
|
|
test(cmdline, assertions)
|
|
|
|
t('', original_argv=[kexe], argv=[])
|
|
t(
|
|
'--title=xxx --start-as maximized -c=a -c b cat',
|
|
title='xxx',
|
|
start_as='maximized',
|
|
config=['a', 'b'],
|
|
original_argv=[kexe, '--title=xxx', '--start-as', 'maximized', '-c=a', '-c', 'b', 'cat'],
|
|
argv=['cat'],
|
|
)
|
|
k('icat abc xyz')
|
|
t('+kitten unwrapped xyz', argv=['+kitten', 'unwrapped', 'xyz'])
|
|
t('+ kitten unwrapped xyz', original_argv=[kexe, '+', 'kitten', 'unwrapped', 'xyz'])
|
|
si('--single-instance --instance-group=g -T 3', argv=[kexe, '--single-instance', '--instance-group=g', '-T', '3'])
|
|
t('+open --help', argv=['+open', '--help'])
|
|
t('+open -1 --help', argv=['+open', '-1', '--help'])
|
|
si('+open -1 moose', argv=[kexe, '+open', '-1', 'moose'], open_urls=['moose'])
|
|
si('+open -1 --instance-group=g x y', instance_group='g', open_urls=['x', 'y'])
|
|
dt('--detach --session=moose --detached-log=xyz', detached_log='xyz', session='moose')
|
|
pn('+kitten panel -1 --edge=left', edge='left')
|
|
|
|
if is_macos:
|
|
with tempfile.TemporaryDirectory() as tdir:
|
|
with open(tdir + '/macos-launch-services-cmdline', 'w') as f:
|
|
f.write('kitty --title from-file\n')
|
|
# File args are used when launched by launch services
|
|
r, output = get_report('', launch_services=True, config_dir=tdir)
|
|
self.assertEqual(r.get('title'), 'from-file', f'Expected title=from-file in:\n{output}')
|
|
# User args passed via open --args are appended after file args (and override them)
|
|
r, output = get_report('--title from-args', launch_services=True, config_dir=tdir)
|
|
self.assertEqual(r.get('title'), 'from-args', f'Expected title=from-args to override from-file in:\n{output}')
|
|
|
|
|
|
def conf_parsing(self):
|
|
from kitty.config import defaults, load_config
|
|
from kitty.constants import is_macos
|
|
from kitty.fast_data_types import LEFT_EDGE, RIGHT_EDGE
|
|
from kitty.fonts import FontModification, ModificationType, ModificationUnit, ModificationValue
|
|
from kitty.options.utils import to_modifiers
|
|
|
|
bad_lines = []
|
|
|
|
def p(*lines, bad_line_num=0, num_err=None):
|
|
del bad_lines[:]
|
|
del self.error_messages[:]
|
|
ans = load_config(overrides=lines, accumulate_bad_lines=bad_lines)
|
|
if bad_line_num:
|
|
self.ae(len(bad_lines), bad_line_num)
|
|
else:
|
|
self.assertFalse(bad_lines)
|
|
if num_err is not None:
|
|
self.ae(len(self.error_messages), num_err, '\n'.join(self.error_messages))
|
|
return ans
|
|
|
|
def keys_for_func(opts, name):
|
|
for key, defns in opts.keyboard_modes[''].keymap.items():
|
|
for action in opts.alias_map.resolve_aliases(defns[0].definition):
|
|
if action.func == name:
|
|
yield key
|
|
|
|
opts = p('font_size 11.37', 'clear_all_shortcuts y', 'color23 red')
|
|
self.ae(opts.font_size, 11.37)
|
|
self.ae(defaults.gpu_driver, ('metal', 'vulkan', 'opengl', 'software'))
|
|
self.ae(p('gpu_driver vulkan, opengl opengl').gpu_driver, ('vulkan', 'opengl'))
|
|
self.ae(p('gpu_driver software opengl').gpu_driver, ('software', 'opengl'))
|
|
present = {name for name in ('metal', 'vulkan', 'opengl') if os.path.exists(gpu_driver_path(name))}
|
|
self.ae(
|
|
available_gpu_drivers(defaults.gpu_driver),
|
|
[(name, gpu_driver_path(name), False) for name in ('metal', 'vulkan', 'opengl') if name in present]
|
|
+ [(name, gpu_driver_path(name), True) for name in SOFTWARE_GPU_DRIVERS if name in present],
|
|
)
|
|
self.ae(p('gpu_driver opengl,vulkan').gpu_driver, ('opengl', 'vulkan'))
|
|
self.ae(p('gpu_driver directx opengl', bad_line_num=1).gpu_driver, defaults.gpu_driver)
|
|
radius_opts = p('window_border_radius 7px')
|
|
self.ae(radius_opts.window_border_radius, (7.0, 'px'))
|
|
self.ae(defaults.hyperlink_target_position, 'top')
|
|
for pos in ('top', 'bottom', 'below', 'tooltip'):
|
|
self.ae(p(f'hyperlink_target_position {pos}').hyperlink_target_position, pos)
|
|
self.ae(p('hyperlink_target_position xxx', bad_line_num=1).hyperlink_target_position, 'top')
|
|
radius_opts = p('window_border_radius -2')
|
|
self.ae(radius_opts.window_border_radius, (0.0, 'pt'))
|
|
self.ae(opts.mouse_hide_wait[0], 0 if is_macos else 3)
|
|
self.ae(opts.mouse_hide_wait[1], 0)
|
|
self.ae(opts.mouse_hide_wait[2], 40)
|
|
self.ae(opts.mouse_hide_wait[3], True)
|
|
self.ae(opts.color23, Color(255, 0, 0))
|
|
self.assertFalse(opts.keyboard_modes[''].keymap)
|
|
opts = p("url_excluded_characters '''")
|
|
self.ae(opts.url_excluded_characters, "'''")
|
|
opts = p("url_excluded_characters abc'")
|
|
self.ae(opts.url_excluded_characters, "abc'")
|
|
opts = p('tab_bar_edge left')
|
|
self.ae(opts.tab_bar_edge, LEFT_EDGE)
|
|
opts = p('tab_bar_edge right')
|
|
self.ae(opts.tab_bar_edge, RIGHT_EDGE)
|
|
opts = p('tab_bar_align start')
|
|
self.ae(opts.tab_bar_align, 'start')
|
|
opts = p('tab_bar_align end')
|
|
self.ae(opts.tab_bar_align, 'end')
|
|
opts = p('tab_bar_align left')
|
|
self.ae(opts.tab_bar_align, 'left')
|
|
opts = p('tab_bar_align right')
|
|
self.ae(opts.tab_bar_align, 'right')
|
|
opts = p('clear_all_shortcuts y', 'map f1 next_window')
|
|
self.ae(len(opts.keyboard_modes[''].keymap), 1)
|
|
opts = p('clear_all_mouse_actions y', 'mouse_map left click ungrabbed mouse_click_url_or_select')
|
|
self.ae(len(opts.mousemap), 1)
|
|
opts = p(
|
|
'clear_all_mouse_actions y',
|
|
'mouse_map ctrl+wheel_up press ungrabbed,grabbed change_font_size all +1',
|
|
'mouse_map shift+wheel_right press ungrabbed next_tab',
|
|
)
|
|
self.ae(
|
|
{k.human_repr() for k in opts.mousemap},
|
|
{'ctrl+wheel_up press ungrabbed', 'ctrl+wheel_up press grabbed', 'shift+wheel_right press ungrabbed'},
|
|
)
|
|
opts = p('strip_trailing_spaces always')
|
|
self.ae(opts.strip_trailing_spaces, 'always')
|
|
self.assertFalse(bad_lines)
|
|
opts = p('pointer_shape_when_grabbed XXX', bad_line_num=1)
|
|
self.ae(opts.pointer_shape_when_grabbed, defaults.pointer_shape_when_grabbed)
|
|
opts = p('modify_font underline_position -2', 'modify_font underline_thickness 150%', 'modify_font size Test -1px')
|
|
self.ae(
|
|
opts.modify_font,
|
|
{
|
|
'underline_position': FontModification(ModificationType.underline_position, ModificationValue(-2.0, ModificationUnit.pt)),
|
|
'underline_thickness': FontModification(ModificationType.underline_thickness, ModificationValue(150, ModificationUnit.percent)),
|
|
'size:Test': FontModification(ModificationType.size, ModificationValue(-1.0, ModificationUnit.pixel), 'Test'),
|
|
},
|
|
)
|
|
|
|
# test the aliasing options
|
|
opts = p('env A=1', 'env B=x$A', 'env C=', 'env D', 'clear_all_shortcuts y', 'kitten_alias a b --moo', 'map f1 kitten a arg')
|
|
self.ae(opts.env, {'A': '1', 'B': 'x1', 'C': '', 'D': DELETE_ENV_VAR})
|
|
|
|
def ac(which=0):
|
|
ka = tuple(opts.keyboard_modes[''].keymap.values())[0][0]
|
|
acs = opts.alias_map.resolve_aliases(ka.definition)
|
|
return acs[which]
|
|
|
|
ka = ac()
|
|
self.ae(ka.func, 'kitten')
|
|
self.ae(ka.args, ('b', '--moo', 'arg'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'kitten_alias hints hints --hi', 'map f1 kitten hints XXX')
|
|
ka = ac()
|
|
self.ae(ka.func, 'kitten')
|
|
self.ae(ka.args, ('hints', '--hi', 'XXX'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias la launch --moo', 'map f1 la XXX')
|
|
ka = ac()
|
|
self.ae(ka.func, 'launch')
|
|
self.ae(ka.args, ('--moo', 'XXX'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias one launch --moo', 'action_alias two one recursive', 'map f1 two XXX')
|
|
ka = ac()
|
|
self.ae(ka.func, 'launch')
|
|
self.ae(ka.args, ('--moo', 'recursive', 'XXX'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias launch two 1', 'action_alias two launch 2', 'map f1 launch 3')
|
|
ka = ac()
|
|
self.ae(ka.func, 'launch')
|
|
self.ae(ka.args, ('2', '1', '3'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias launch launch --moo', 'map f1 launch XXX')
|
|
ka = ac()
|
|
self.ae(ka.func, 'launch')
|
|
self.ae(ka.args, ('--moo', 'XXX'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias cfs change_font_size current', 'map f1 cfs +2')
|
|
ka = ac()
|
|
self.ae(ka.func, 'change_font_size')
|
|
self.ae(ka.args, (False, '+', 2.0))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias la launch --moo', 'map f1 combine : new_window : la ')
|
|
self.ae((ac().func, ac(1).func), ('new_window', 'launch'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias cc combine : new_window : launch --moo', 'map f1 cc XXX')
|
|
self.ae((ac().func, ac(1).func), ('new_window', 'launch'))
|
|
self.ae(ac(1).args, ('--moo', 'XXX'))
|
|
|
|
opts = p('clear_all_shortcuts y', 'action_alias ss kitten "space 1"', 'map f1 ss "space 2"')
|
|
self.ae(ac().args, ('space 1', 'space 2'))
|
|
|
|
am = build_action_aliases({'la': 'launch --moo'})
|
|
self.ae(am.resolve_aliases('la XXX')[0].args, ('--moo', 'XXX'))
|
|
am.update(build_action_aliases({'la': 'launch --baa'}))
|
|
self.ae(am.resolve_aliases('la XXX')[0].args, ('--baa', 'XXX'))
|
|
|
|
opts = p('kitty_mod alt')
|
|
self.ae(opts.kitty_mod, to_modifiers('alt'))
|
|
self.ae(next(keys_for_func(opts, 'next_layout')).mods, opts.kitty_mod)
|
|
|
|
opts = p('inactive_text_alpha 0.25')
|
|
self.ae(opts.inactive_text_alpha, 0.25)
|
|
opts = p('inactive_text_alpha -0.25')
|
|
self.ae(opts.inactive_text_alpha, -0.25)
|
|
opts = p('inactive_text_alpha 2')
|
|
self.ae(opts.inactive_text_alpha, 1.0)
|
|
opts = p('inactive_text_alpha -2')
|
|
self.ae(opts.inactive_text_alpha, -1.0)
|
|
|
|
# deprecation handling
|
|
opts = p('clear_all_shortcuts y', 'send_text all f1 hello')
|
|
self.ae(len(opts.keyboard_modes[''].keymap), 1)
|
|
opts = p('macos_hide_titlebar y' if is_macos else 'x11_hide_window_decorations y')
|
|
self.assertTrue(opts.hide_window_decorations)
|
|
self.ae(len(self.error_messages), 1)
|
|
|
|
# line breaks
|
|
opts = p(' font', ' \t \t \\_size', ' \\ 12', '\\.35', 'col', '\\o', '\t \t\\r', '\\25', ' \\ blue')
|
|
self.ae(opts.font_size, 12.35)
|
|
self.ae(opts.color25, Color(0, 0, 255))
|
|
|
|
# cursor_blink_interval
|
|
def cb(src, interval=-1, first=EasingFunction(), second=EasingFunction()):
|
|
opts = p('cursor_blink_interval ' + src)
|
|
self.ae((float(interval), first, second), (float(opts.cursor_blink_interval[0]), opts.cursor_blink_interval[1], opts.cursor_blink_interval[2]))
|
|
|
|
cb('3', 3)
|
|
cb('-2.3', -2.3)
|
|
cb('linear', first=EasingFunction('cubic-bezier', cubic_bezier_points=(0, 0.0, 1.0, 1.0)))
|
|
cb('linear 19', 19, EasingFunction('cubic-bezier', cubic_bezier_points=(0, 0.0, 1.0, 1.0)))
|
|
cb(
|
|
'ease-in-out cubic-bezier(0.1, 0.2, 0.3, 0.4) 11',
|
|
11,
|
|
EasingFunction('cubic-bezier', cubic_bezier_points=(0.42, 0, 0.58, 1)),
|
|
EasingFunction('cubic-bezier', cubic_bezier_points=(0.1, 0.2, 0.3, 0.4)),
|
|
)
|
|
cb('step-start', first=EasingFunction('steps', num_steps=1, jump_type='start'))
|
|
cb('steps(7, jump-none)', first=EasingFunction('steps', num_steps=7, jump_type='none'))
|
|
cb('linear(0, 0.25, 1)', first=EasingFunction('linear', linear_x=(0.0, 0.5, 1.0), linear_y=(0, 0.25, 1.0)))
|
|
cb('linear(0, 0.25 75%, 1)', first=EasingFunction('linear', linear_x=(0.0, 0.75, 1.0), linear_y=(0, 0.25, 1.0)))
|
|
cb('linear(0, 0.25 25% 75%, 1)', first=EasingFunction('linear', linear_x=(0.0, 0.25, 0.75, 1.0), linear_y=(0, 0.25, 0.25, 1.0)))
|
|
|
|
# test that easing functions give expected values
|
|
def ef(spec, tests, only_single=True, duration=0.5, accuracy=0):
|
|
cfv = p('cursor_blink_interval ' + spec).cursor_blink_interval
|
|
self.set_options({'cursor_blink_interval': cfv})
|
|
for t, expected in tests.items():
|
|
actual = test_cursor_blink_easing_function(t, only_single, duration)
|
|
if abs(actual - expected) > accuracy:
|
|
self.ae(expected, actual, f'Failed for {spec=} with {t=}: {expected} != {actual}')
|
|
|
|
ef('linear', {0: 1, 0.25: 0.5, 0.5: 0, 0.75: 0.5, 1: 1}, only_single=False)
|
|
|
|
ef('linear(0, 0.25 25% 75%, 1)', {0: 0, 0.25: 0.25, 0.3: 0.25, 0.75: 0.25, 1: 1})
|
|
linear_vals = {0: 0, 1: 1, 0.1234: 0.1234, 0.6453: 0.6453}
|
|
for spec in ('linear', 'linear(0, 1)', 'cubic-bezier(0, 0, 1, 1)', 'cubic-bezier(0.2, 0.2, 0.7, 0.7)'):
|
|
ef(spec, linear_vals)
|
|
# test an almost linear function to test cubic bezier implementation
|
|
ef('cubic-bezier(0.2, 0.2, 0.7, 0.71)', linear_vals, accuracy=0.01)
|
|
ef('cubic-bezier(0.23, 0.2, 0.7, 0.71)', linear_vals, accuracy=0.01)
|
|
|
|
ef('steps(5)', {0: 0, 0.1: 0, 0.3: 0.2, 0.9: 0.8})
|
|
ef('steps(5, start)', {0: 0.2, 0.1: 0.2, 0.3: 0.4, 0.9: 1})
|
|
ef('steps(4, jump-both)', {0: 0.2, 0.1: 0.2, 0.3: 0.4, 0.9: 1})
|
|
ef('steps(6, jump-none)', {0: 0, 0.1: 0.0, 0.3: 0.2, 0.9: 1})
|
|
|
|
# test various include modes
|
|
base = os.path.join(self.tdir, 'glob')
|
|
os.mkdir(base)
|
|
with open(os.path.join(base, 'fg'), 'w') as f:
|
|
print('foreground red', file=f)
|
|
opts = p(f'include {f.name}', num_err=0)
|
|
self.ae(opts.foreground, to_color('red'))
|
|
with open(os.path.join(self.tdir, 'bg'), 'w') as f:
|
|
print('background white', file=f)
|
|
print('globinclude glob/*', file=f)
|
|
print('envinclude ENVINCLUDE', file=f)
|
|
print('geninclude g.py', file=f)
|
|
print('geninclude g', file=f)
|
|
with open(os.path.join(self.tdir, 'g.py'), 'w') as g:
|
|
print('print("background_opacity .77")', file=g)
|
|
print('print("background_blur 77")', file=g)
|
|
with open(os.path.join(self.tdir, 'g'), 'w') as g:
|
|
print('#!/bin/sh', file=g)
|
|
print('echo background_image_linear y', file=g)
|
|
print('echo background_image_layout clamped', file=g)
|
|
os.chmod(g.fileno(), 0o700)
|
|
os.environ['ENVINCLUDE'] = 'cursor yellow'
|
|
opts = p(f'include {f.name}', num_err=0)
|
|
os.environ.pop('ENVINCLUDE')
|
|
self.ae(opts.foreground, to_color('red'))
|
|
self.ae(opts.background, to_color('white'))
|
|
self.ae(opts.cursor, to_color('yellow'))
|
|
self.ae(opts.background_opacity, 0.77)
|
|
self.ae(opts.background_blur, 77)
|
|
self.ae(opts.background_image_linear, True)
|
|
self.ae(opts.background_image_layout, 'clamped')
|
|
with open(os.path.join(self.tdir, 'a'), 'w') as a:
|
|
print('background red', file=a)
|
|
print('include b', file=a)
|
|
with open(os.path.join(self.tdir, 'b'), 'w') as a:
|
|
print('foreground red', file=a)
|
|
print('include a', file=a)
|
|
opts = p(f'include {a.name}', num_err=0, bad_line_num=1)
|
|
self.ae(opts.foreground, to_color('red'))
|
|
self.ae(opts.background, to_color('red'))
|
|
|
|
# remap_modifier. NOTE: parsing only. Whether the permutation is applied
|
|
# simultaneously rather than sequentially is a property of
|
|
# apply_modifier_remap() in C and is NOT observable from this dict - a
|
|
# sequential implementation would produce an identical one. That property is
|
|
# covered end to end by tests/test-remap-e2e.sh, which asserts that the
|
|
# encoded bytes actually exchange.
|
|
self.ae(p().remap_modifiers, {})
|
|
ctrl, hyper, sup = to_modifiers('ctrl'), to_modifiers('hyper'), to_modifiers('super')
|
|
self.ae(p('remap_modifiers ctrl:hyper').remap_modifiers, {ctrl: hyper})
|
|
# both directions of a swap are recorded
|
|
self.ae(p('remap_modifiers ctrl:hyper hyper:ctrl').remap_modifiers, {ctrl: hyper, hyper: ctrl})
|
|
# the last declaration for a given source wins, wherever it appears
|
|
self.ae(p('remap_modifiers ctrl:hyper', 'kitty_mod ctrl', 'remap_modifiers ctrl:super').remap_modifiers, {ctrl: sup})
|
|
# the destination may name more than one modifier
|
|
self.ae(p('remap_modifiers ctrl:ctrl+shift').remap_modifiers, {ctrl: to_modifiers('ctrl+shift')})
|
|
# every rejection must be REPORTED, never silently ignored: wrong arity, unknown
|
|
# or non-remappable modifier names, a source naming more than one modifier, and
|
|
# a mapping that does nothing
|
|
for bad in (
|
|
'remap_modifiers ctrl',
|
|
'remap_modifiers ctrl:hyper super',
|
|
'remap_modifiers ctrl:nosuchmod',
|
|
'remap_modifiers nosuchmod:ctrl',
|
|
'remap_modifiers ctrl+shift:hyper',
|
|
'remap_modifiers ctrl:none',
|
|
'remap_modifiers none:ctrl',
|
|
'remap_modifiers ctrl:kitty_mod',
|
|
'remap_modifiers kitty_mod:ctrl',
|
|
'remap_modifiers caps_lock:ctrl',
|
|
'remap_modifiers ctrl:num_lock',
|
|
'remap_modifiers ctrl:ctrl',
|
|
):
|
|
self.ae(p(bad, num_err=1).remap_modifiers, {}, f'not rejected: {bad}')
|