Skip to content

Add optional parameter literal to Pane.send_keys #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2019
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