@@ -62,15 +62,42 @@ def wait_for_prompt() -> bool:
62
62
63
63
def test_send_keys (session : Session ) -> None :
64
64
"""Verify Pane.send_keys()."""
65
- pane = session .active_window .active_pane
65
+ window = setup_shell_window (session , "test_send_keys" )
66
+ pane = window .active_pane
66
67
assert pane is not None
67
- pane .send_keys ("c-c" , literal = True )
68
68
69
- pane_contents = " \n " . join ( pane . cmd ( "capture-pane" , "-p" ). stdout )
70
- assert "c-c" in pane_contents
69
+ # Test literal input
70
+ pane . send_keys ( "echo 'test-literal'" , literal = True )
71
71
72
- pane .send_keys ("c-a" , literal = False )
73
- assert "c-a" not in pane_contents , "should not print to pane"
72
+ def wait_for_literal () -> bool :
73
+ try :
74
+ pane_contents = "\n " .join (pane .capture_pane ())
75
+ return (
76
+ "test-literal" in pane_contents
77
+ and "echo 'test-literal'" in pane_contents
78
+ and pane_contents .count ("READY>" ) >= 2
79
+ )
80
+ except Exception :
81
+ return False
82
+
83
+ retry_until (wait_for_literal , 2 , raises = True )
84
+
85
+ # Test non-literal input (should be interpreted as keystrokes)
86
+ pane .send_keys ("c-c" , literal = False ) # Send Ctrl-C
87
+
88
+ def wait_for_ctrl_c () -> bool :
89
+ try :
90
+ pane_contents = "\n " .join (pane .capture_pane ())
91
+ # Ctrl-C should add a new prompt without executing a command
92
+ return (
93
+ # Previous prompt + command + new prompt
94
+ pane_contents .count ("READY>" ) >= 3
95
+ and "c-c" not in pane_contents # The literal string should not appear
96
+ )
97
+ except Exception :
98
+ return False
99
+
100
+ retry_until (wait_for_ctrl_c , 2 , raises = True )
74
101
75
102
76
103
def test_set_height (session : Session ) -> None :
@@ -389,9 +416,35 @@ def test_split_pane_size(session: Session) -> None:
389
416
390
417
def test_pane_context_manager (session : Session ) -> None :
391
418
"""Test Pane context manager functionality."""
392
- window = session .new_window ()
393
- with window .split () as pane :
394
- pane .send_keys ('echo "Hello"' )
419
+ env = shutil .which ("env" )
420
+ assert env is not None , "Cannot find usable `env` in PATH."
421
+
422
+ window = setup_shell_window (session , "test_context_manager" )
423
+ with window .split (shell = f"{ env } PROMPT_COMMAND='' PS1='READY>' sh" ) as pane :
424
+ # Wait for shell to be ready in the split pane
425
+ def wait_for_shell () -> bool :
426
+ try :
427
+ pane_contents = "\n " .join (pane .capture_pane ())
428
+ return "READY>" in pane_contents and len (pane_contents .strip ()) > 0
429
+ except Exception :
430
+ return False
431
+
432
+ retry_until (wait_for_shell , 2 , raises = True )
433
+
434
+ pane .send_keys ('echo "Hello"' , literal = True )
435
+
436
+ def wait_for_output () -> bool :
437
+ try :
438
+ pane_contents = "\n " .join (pane .capture_pane ())
439
+ return (
440
+ 'echo "Hello"' in pane_contents
441
+ and "Hello" in pane_contents
442
+ and pane_contents .count ("READY>" ) >= 2
443
+ )
444
+ except Exception :
445
+ return False
446
+
447
+ retry_until (wait_for_output , 2 , raises = True )
395
448
assert pane in window .panes
396
449
assert len (window .panes ) == 2 # Initial pane + new pane
397
450
0 commit comments