Initial public release of Warp.

Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
David Stern
2026-04-28 08:43:33 -05:00
commit 0dbd3d567a
4982 changed files with 1431549 additions and 0 deletions
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
"""Tests Kitty keyboard protocol apply-mode semantics (set, union, diff) and query responses.
Sends a sequence of CSI = u mode changes (set flags=1, union flags=8, diff flags=1)
with CSI ? u queries after each, then prints the query responses. Used by
test_keyboard_protocol_query_and_apply_modes to verify that the terminal
correctly tracks flag arithmetic (1 → 9 → 8).
"""
import re
import select
import sys
import termios
import time
import tty
def read_query_response(timeout_seconds: float) -> bytes:
deadline = time.time() + timeout_seconds
data = b""
pattern = re.compile(rb"\x1b\[\?[0-9]+u")
while time.time() < deadline:
ready, _, _ = select.select([sys.stdin], [], [], 0.05)
if not ready:
continue
chunk = sys.stdin.buffer.read1(64)
if not chunk:
break
data += chunk
match = pattern.search(data)
if match is not None:
return match.group(0)
return b""
def send(sequence: str) -> None:
sys.stdout.write(sequence)
sys.stdout.flush()
def out(msg: str) -> None:
sys.stdout.write(msg + "\r\n")
sys.stdout.flush()
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
out("Protocol test starting")
# Replace with disambiguate-only (1), then union report-all (8), then remove disambiguate (1).
send("\x1b[=1u")
send("\x1b[?u")
response_1 = read_query_response(timeout_seconds=2.0)
out(f"query_1={response_1!r}")
send("\x1b[=8;2u")
send("\x1b[?u")
response_2 = read_query_response(timeout_seconds=2.0)
out(f"query_2={response_2!r}")
send("\x1b[=1;3u")
send("\x1b[?u")
response_3 = read_query_response(timeout_seconds=2.0)
out(f"query_3={response_3!r}")
out("All queries done. Press Ctrl+C to exit.")
# Stay alive so the integration test can read output.
# Use blocking read (like the other test scripts) for immediate Ctrl+C response.
while True:
ch = sys.stdin.read(1)
if not ch or ord(ch) == 3: # EOF or Ctrl+C
break
finally:
termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, old_settings)
send("\x1b[=0u")
print("Done!")
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""Baseline key-reading script without the Kitty keyboard protocol.
Reads raw bytes from stdin and prints each as hex. Used by
test_keyboard_protocol_disabled_shift_enter to verify that Shift+Enter
and plain Enter produce legacy byte values (0x0a and 0x0d) when the
protocol is not enabled.
"""
import sys
import termios
import tty
# Put terminal in raw mode
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
print("Ready. Press Shift+Enter, then plain Enter, then Ctrl+C")
sys.stdout.flush()
bytes_received = []
while True:
char = sys.stdin.read(1)
byte_val = ord(char)
bytes_received.append(byte_val)
# Print each byte in hex
print(f"\nReceived byte: 0x{byte_val:02x} ({chr(byte_val) if 32 <= byte_val < 127 else repr(chr(byte_val))})")
sys.stdout.flush()
# Exit on Ctrl+C
if byte_val == 3:
break
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
print("\nDone!")
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
import sys
import termios
import tty
# Put terminal in raw mode
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
# Enable keyboard protocol with flags:
# - 1 = disambiguate escape codes
# - 4 = report alternate keys
# - 8 = report all keys as escape codes
# - 16 = report associated text
# Total flags = 29 (1 + 4 + 8 + 16)
# Use the set-flags form (CSI = flags u), which replaces active flags.
sys.stdout.write('\x1b[=29u')
sys.stdout.flush()
print("Protocol enabled. Press Shift+A, then plain 'a', then Ctrl+C")
sys.stdout.flush()
bytes_received = []
while True:
char = sys.stdin.read(1)
byte_val = ord(char)
bytes_received.append(byte_val)
# Print each byte in hex
if byte_val == 0x1b: # ESC
print(f"\nESC sequence start: 0x{byte_val:02x}")
else:
print(f"0x{byte_val:02x}", end=' ')
sys.stdout.flush()
# Exit on Ctrl+C (0x03)
if byte_val == 3:
break
# Also check for 'u' at end of CSI sequence to print summary
if byte_val == ord('u'):
# Extract the last CSI sequence
esc_start = len(bytes_received) - 1
while esc_start > 0 and bytes_received[esc_start] != 0x1b:
esc_start -= 1
sequence = ''.join(chr(b) for b in bytes_received[esc_start:])
print(f"\nComplete sequence: {repr(sequence)}")
sys.stdout.flush()
bytes_received = []
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
# Disable keyboard protocol by replacing flags with 0.
sys.stdout.write('\x1b[=0u')
print("\nDone!")
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
"""Key-reading script with Kitty keyboard protocol flags 1+2+8 (disambiguate + event types + report all).
Enables flags 11 via CSI =11u, then reads raw bytes and reassembles CSI u
sequences. Used by test_keyboard_protocol_modifier_key_reporting and
test_keyboard_protocol_modifier_self_bit to verify that standalone modifier
key press/release events produce CSI u sequences with the correct event type
field (:1 for press, :3 for release) and self-bit modifier encoding.
"""
import sys
import termios
import tty
# Put terminal in raw mode
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
# Enable keyboard protocol with flags 1+2+8=11
# 1 = disambiguate escape codes
# 2 = report event types (press/repeat/release)
# 8 = report all keys as escape codes
sys.stdout.write('\x1b[=11u')
sys.stdout.flush()
print("Protocol enabled. Press keys then Ctrl+C")
sys.stdout.flush()
bytes_received = []
while True:
char = sys.stdin.read(1)
byte_val = ord(char)
bytes_received.append(byte_val)
# Print each byte in hex
if byte_val == 0x1b: # ESC
print(f"\nESC sequence start: 0x{byte_val:02x}")
else:
print(f"0x{byte_val:02x}", end=' ')
sys.stdout.flush()
# Exit on Ctrl+C (0x03)
if byte_val == 3:
break
# Check for 'u' at end of CSI sequence to print summary
if byte_val == ord('u'):
esc_start = len(bytes_received) - 1
while esc_start > 0 and bytes_received[esc_start] != 0x1b:
esc_start -= 1
sequence = ''.join(chr(b) for b in bytes_received[esc_start:])
print(f"\nComplete sequence: {repr(sequence)}")
sys.stdout.flush()
bytes_received = []
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
# Disable keyboard protocol
sys.stdout.write('\x1b[=0u')
print("\nDone!")
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
"""Key-reading script with Kitty keyboard protocol flag 8 only (report all keys).
Enables flag 8 via CSI =8u, then reads raw bytes and identifies both CSI u
sequences and legacy arrow key sequences. Used by
test_keyboard_protocol_report_all_keys_printable_and_cursor to verify that
printable keys produce CSI u, cursor keys use legacy encoding, and multi-byte
UTF-8 characters (e.g. é) are handled correctly.
"""
import sys
import termios
import tty
# Put terminal in raw mode
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
# Enable keyboard protocol with flag 8 only (report all keys as escape codes).
# This means every key press gets a CSI u sequence, but without disambiguate (flag 1).
sys.stdout.write('\x1b[=8u')
sys.stdout.flush()
print("Protocol enabled. Press keys then Ctrl+C")
sys.stdout.flush()
bytes_received = []
while True:
char = sys.stdin.read(1)
byte_val = ord(char)
bytes_received.append(byte_val)
# Print each byte in hex
if byte_val == 0x1b: # ESC
print(f"\nESC sequence start: 0x{byte_val:02x}")
else:
print(f"0x{byte_val:02x}", end=' ')
sys.stdout.flush()
# Exit on Ctrl+C (0x03)
if byte_val == 3:
break
# Also check for 'u' at end of CSI sequence to print summary
if byte_val == ord('u'):
esc_start = len(bytes_received) - 1
while esc_start > 0 and bytes_received[esc_start] != 0x1b:
esc_start -= 1
sequence = ''.join(chr(b) for b in bytes_received[esc_start:])
print(f"\nComplete sequence: {repr(sequence)}")
sys.stdout.flush()
bytes_received = []
# Check for legacy arrow key sequences (ESC [ A/B/C/D)
if byte_val in (ord('A'), ord('B'), ord('C'), ord('D')) and len(bytes_received) >= 3:
tail = bytes_received[-3:]
if tail[0] == 0x1b and tail[1] == 0x5b:
sequence = ''.join(chr(b) for b in tail)
print(f"\nLegacy arrow: {repr(sequence)}")
sys.stdout.flush()
bytes_received = []
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
# Disable keyboard protocol
sys.stdout.write('\x1b[=0u')
print("\nDone!")
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""Key-reading script with Kitty keyboard protocol flags 1+8 (disambiguate + report all).
Enables protocol flags 9 via CSI =9u, then reads raw bytes and reassembles
CSI u sequences. Used by test_keyboard_protocol_enabled_shift_enter and
test_keyboard_protocol_enabled_shifted_symbol_uses_unshifted_keycode to
verify that keys produce the expected CSI u encodings.
"""
import sys
import termios
import tty
# Put terminal in raw mode
old_settings = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
# Enable keyboard protocol with flags:
# - 1 = disambiguate escape codes
# - 8 = report all keys as escape codes (including unmodified keys)
# Total flags = 9 (1 + 8)
# Use the set-flags form (CSI = flags u), which replaces active flags.
sys.stdout.write('\x1b[=9u')
sys.stdout.flush()
print("Protocol enabled. Press Shift+Enter, then plain Enter, then Ctrl+C")
sys.stdout.flush()
bytes_received = []
while True:
char = sys.stdin.read(1)
byte_val = ord(char)
bytes_received.append(byte_val)
# Print each byte in hex
if byte_val == 0x1b: # ESC
print(f"\nESC sequence start: 0x{byte_val:02x}")
else:
print(f"0x{byte_val:02x}", end=' ')
sys.stdout.flush()
# Exit on Ctrl+C (0x03)
if byte_val == 3:
break
# Also check for 'u' at end of CSI sequence to print summary
if byte_val == ord('u'):
# Extract the last CSI sequence
esc_start = len(bytes_received) - 1
while esc_start > 0 and bytes_received[esc_start] != 0x1b:
esc_start -= 1
sequence = ''.join(chr(b) for b in bytes_received[esc_start:])
print(f"\nComplete sequence: {repr(sequence)}")
sys.stdout.flush()
bytes_received = []
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
# Disable keyboard protocol by replacing flags with 0.
sys.stdout.write('\x1b[=0u')
print("\nDone!")