Make the clipboard command user-configurable

Add config item clipboard_cmd, with a default of 'pbcopy w' on Darwin
and 'xclip' on everything else. This will allow the user to use any
command for the clipboard, including 'wl-copy' for Wayland (addressing
issue #693 on Github). With his change, significant simplifications
could be made to clipboard.py - the copy_*() functions have been removed
and combined into copy().

With this simplification, the old OSX test is obsolete, and new OSX
tests are needed (need a way to simulate sys.platform).
This commit is contained in:
John Helmert
2019-06-08 15:18:15 -05:00
parent e545c7052c
commit 7423a43e50
4 changed files with 22 additions and 49 deletions

View File

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import pytest
from rtv.clipboard import copy_linux, copy_osx
from rtv.clipboard import copy
from rtv.exceptions import ProgramError
@@ -23,20 +23,13 @@ def test_copy():
p.communicate = mock.Mock()
Popen.return_value = p
# If the `which` command can't find a program to use
call.return_value = 1 # Returns an error code
with pytest.raises(ProgramError):
copy_linux('test')
call.return_value = 0
copy_linux('test')
copy('test', 'xsel -b -i')
assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
p.communicate.assert_called_with(input='test'.encode('utf-8'))
copy_linux('test ❤')
copy('test ❤', 'xclip')
assert Popen.call_args[0][0] == ['xclip']
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
copy_osx('test')
assert Popen.call_args[0][0] == ['pbcopy', 'w']
p.communicate.assert_called_with(input='test'.encode('utf-8'))
copy_osx('test ❤')
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
# Need OSX tests, can't simulate sys.platform