Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def cmd(self, cmd, *args, **kwargs):

return self.server.cmd(cmd, *args, **kwargs)

def send_keys(self, cmd, enter=True, suppress_history=True):
def send_keys(self, cmd, enter=True, suppress_history=True, literal=False):
"""
``$ tmux send-keys`` to the pane.

Expand All @@ -108,9 +108,15 @@ def send_keys(self, cmd, enter=True, suppress_history=True):
Send enter after sending the input, default True.
suppress_history : bool, optional
Don't add these keys to the shell history, default True.
literal : bool, optional
Send keys literally, default True.
"""
prefix = ' ' if suppress_history else ''
self.cmd('send-keys', prefix + cmd)

if literal:
self.cmd('send-keys', '-l', prefix + cmd)
else:
self.cmd('send-keys', prefix + cmd)

if enter:
self.enter()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def test_resize_pane(session):
assert int(pane1['pane_height']) == 3


def test_send_keys(session):
pane = session.attached_window.attached_pane
pane.send_keys('c-c', literal=True)

pane_contents = '\n'.join(pane.cmd('capture-pane', '-p').stdout)
assert 'c-c' in pane_contents

pane.send_keys('c-a', literal=False)
assert 'c-a' not in pane_contents, 'should not print to pane'


def test_set_height(session):
window = session.new_window(window_name='test_set_height')
window.split_window()
Expand Down