fix: preserve Ctrl+J newlines in Ghostty

This commit is contained in:
Seppe Gadeyne 2026-05-27 11:31:47 +02:00 committed by Teknium
parent 1386a7e478
commit cf8862cfa3
5 changed files with 82 additions and 8 deletions

View file

@ -180,9 +180,9 @@ class TestPromptToolkitTerminalCompatibility:
def test_lf_enter_binds_to_submit_handler_posix(self):
"""Some thin PTYs deliver Enter as LF/c-j instead of CR/enter.
On a bare local POSIX TTY (no SSH/WSL/WT) we keep c-j submit so
On a bare local POSIX TTY (no SSH/WSL/WT/Ghostty) we keep c-j submit so
Enter works on thin PTYs (docker exec, certain ssh configurations).
On Windows, WSL, SSH sessions, and Windows Terminal we leave c-j
On Windows, WSL, SSH sessions, Windows Terminal, and Ghostty we leave c-j
unbound here so it can be used as the Ctrl+Enter newline keystroke
without conflicting with submit. See issue #22379.
"""
@ -217,6 +217,17 @@ class TestPromptToolkitTerminalCompatibility:
assert bindings[("c-m",)] is submit_handler
assert ("c-j",) not in bindings
# Ghostty through tmux: TERM_PROGRAM is tmux, but Ghostty exports a
# stable env marker. Keep c-j free so Ctrl+J inserts a newline.
with _patch.object(_sys, "platform", "linux"), \
_patch.dict(_os.environ, {"TERM": "tmux-256color", "TERM_PROGRAM": "tmux", "GHOSTTY_RESOURCES_DIR": "/usr/share/ghostty"}, clear=True), \
_patch("builtins.open", side_effect=OSError("no /proc")):
kb = KeyBindings()
_bind_prompt_submit_keys(kb, submit_handler)
bindings = {tuple(key.value for key in binding.keys): binding.handler for binding in kb.bindings}
assert bindings[("c-m",)] is submit_handler
assert ("c-j",) not in bindings
# Windows: only enter submits; c-j is free for the newline binding
# added separately in the prompt setup.
with _patch.object(_sys, "platform", "win32"):