|
| 1 | +"""Examples of operations with tmux panes.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import time |
| 6 | + |
| 7 | +from libtmux.constants import PaneDirection |
| 8 | + |
| 9 | + |
| 10 | +def test_pane_functions(pane) -> None: |
| 11 | + """Test basic pane functions.""" |
| 12 | + # Send a command to the pane |
| 13 | + pane.send_keys("echo 'Hello from pane'", enter=True) |
| 14 | + |
| 15 | + # Give the command time to execute |
| 16 | + time.sleep(0.5) |
| 17 | + |
| 18 | + # Capture and verify the output |
| 19 | + output = pane.capture_pane() |
| 20 | + assert any("Hello from pane" in line for line in output) |
| 21 | + |
| 22 | + |
| 23 | +def test_window_functions(window) -> None: |
| 24 | + """Test basic window functions.""" |
| 25 | + # Get the active pane |
| 26 | + pane = window.active_pane |
| 27 | + assert pane is not None |
| 28 | + |
| 29 | + # Split the window |
| 30 | + window.split_window() |
| 31 | + assert len(window.panes) == 2 |
| 32 | + |
| 33 | + |
| 34 | +def test_pane_resizing(window) -> None: |
| 35 | + """Test resizing panes.""" |
| 36 | + # Start with a single pane |
| 37 | + original_pane = window.active_pane |
| 38 | + |
| 39 | + # Split horizontally |
| 40 | + second_pane = window.split(direction=PaneDirection.Right, percent=50) |
| 41 | + assert len(window.panes) == 2 |
| 42 | + |
| 43 | + # Resize the first pane to be larger |
| 44 | + original_pane.resize(width=60) |
| 45 | + time.sleep(0.5) |
| 46 | + |
| 47 | + # Get updated dimensions |
| 48 | + dimensions1 = original_pane.dimensions |
| 49 | + dimensions2 = second_pane.dimensions |
| 50 | + |
| 51 | + # The first pane should be wider |
| 52 | + assert dimensions1["width"] > dimensions2["width"] |
| 53 | + |
| 54 | + # Now resize the second pane to be larger |
| 55 | + second_pane.resize(width=60) |
| 56 | + time.sleep(0.5) |
| 57 | + |
| 58 | + # Get updated dimensions |
| 59 | + dimensions1 = original_pane.dimensions |
| 60 | + dimensions2 = second_pane.dimensions |
| 61 | + |
| 62 | + # The second pane should now be wider |
| 63 | + assert dimensions2["width"] > dimensions1["width"] |
| 64 | + |
| 65 | + |
| 66 | +def test_pane_capturing(pane) -> None: |
| 67 | + """Test capturing pane content in different formats.""" |
| 68 | + # Send multiple lines of content |
| 69 | + pane.send_keys("echo 'Line 1'", enter=True) |
| 70 | + pane.send_keys("echo 'Line 2'", enter=True) |
| 71 | + pane.send_keys("echo 'Line 3'", enter=True) |
| 72 | + time.sleep(0.5) |
| 73 | + |
| 74 | + # Capture as a list of lines |
| 75 | + output_lines = pane.capture_pane() |
| 76 | + assert isinstance(output_lines, list) |
| 77 | + assert any("Line 1" in line for line in output_lines) |
| 78 | + assert any("Line 2" in line for line in output_lines) |
| 79 | + assert any("Line 3" in line for line in output_lines) |
| 80 | + |
| 81 | + # Capture as a single string |
| 82 | + output_str = pane.capture_pane(as_str=True) |
| 83 | + assert isinstance(output_str, str) |
| 84 | + assert "Line 1" in output_str |
| 85 | + assert "Line 2" in output_str |
| 86 | + assert "Line 3" in output_str |
0 commit comments