From 7b0222a9cfc2fce99c6ccdec88cc412a89c45bad Mon Sep 17 00:00:00 2001 From: ritiek Date: Tue, 22 May 2018 11:14:47 +0530 Subject: [PATCH 1/2] Add optional parameter literal to Pane.send_keys --- libtmux/pane.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libtmux/pane.py b/libtmux/pane.py index e39855437..4adbc4f37 100644 --- a/libtmux/pane.py +++ b/libtmux/pane.py @@ -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. @@ -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() From 122d68eac343068c0638d6749fa3f61c24f455fc Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 26 Jan 2019 09:49:54 -0600 Subject: [PATCH 2/2] :white_check_mark: Test send_keys literal / non-literal --- tests/test_pane.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_pane.py b/tests/test_pane.py index 24e3e91a3..bcd74d183 100644 --- a/tests/test_pane.py +++ b/tests/test_pane.py @@ -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()