From f9b57ba2836f6e42ebc057bd92292271e84ced3e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 22 Oct 2026 15:50:55 +0530 Subject: [PATCH] Allow trailing comments in shader pipeline files\n\nFixes #10718 --- docs/custom-shaders.rst | 3 ++- kitty/shaders/slang.py | 8 +++++++- kitty_tests/slang.py | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/custom-shaders.rst b/docs/custom-shaders.rst index dcbda8606..8b9e76320 100644 --- a/docs/custom-shaders.rst +++ b/docs/custom-shaders.rst @@ -260,7 +260,8 @@ The pipeline part A pipeline file (:file:`.pipeline`) is a plain text file that controls how one or more shaders are assembled into a rendering pipeline. Lines starting -with ``#`` are comments; blank lines are ignored. +with ``#`` are comments, as is everything after a ``#`` that is preceded by +whitespace; blank lines are ignored. **Top-level directives** (outside any group): diff --git a/kitty/shaders/slang.py b/kitty/shaders/slang.py index 44923eb69..0201dd161 100644 --- a/kitty/shaders/slang.py +++ b/kitty/shaders/slang.py @@ -1658,6 +1658,11 @@ class Pipeline(TypedDict): pipeline_dir: str +@run_once +def trailing_comment_pat() -> re.Pattern[str]: + return re.compile(r'\s#.*') + + def parse_pipeline_definition(lines: Iterable[str], pipeline_name: str, pipeline_dir: str = '') -> Pipeline: slot = Slot.end textures: tuple[NamedTexture, ...] = () @@ -1701,7 +1706,8 @@ def parse_pipeline_definition(lines: Iterable[str], pipeline_name: str, pipeline } for line in lines: - line = line.strip() + # A # at the start of the line or preceded by whitespace starts a comment + line = trailing_comment_pat().sub('', line).strip() if not line or line.startswith('#'): continue parts = line.split() diff --git a/kitty_tests/slang.py b/kitty_tests/slang.py index 41328daa1..85ebd8147 100644 --- a/kitty_tests/slang.py +++ b/kitty_tests/slang.py @@ -118,6 +118,11 @@ class TestSlang(BaseTest): g = pipeline('animation_start user:find-cursor|tab-change\nanimation_stop user:x.y_z')['groups'][0] self.ae(g['animation_start'], ('user:find-cursor', 'tab-change')) self.ae(g['animation_end_events'], ('user:x.y_z',)) + # Trailing comments, including empty ones + for comment in ('# ', '#', '# some comment', '\t#x'): + g = pipeline(f'animation_toggle user:toggle-notch {comment}\nanimation_duration 600 {comment}')['groups'][0] + self.ae(g['animation_toggle'], ('user:toggle-notch',)) + self.ae(g['animation_duration'], 600_000_000) for bad in ('user:', 'user:a/b', 'user:' + 'x' * 100, 'usr:a'): self.assertRaises(ValueError, pipeline, f'animation_start {bad}') # A toggled group stays on until toggled off unless told otherwise