diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-07-10 21:59:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-10 21:59:27 -0400 |
| commit | 9a949467e3820af4477f6f7ea3bfe06a2a4fb7ae (patch) | |
| tree | 4ea36cab021f0fb3308859b1cd3366f454acc760 /cmd2.py | |
| parent | b9c56fd456b84f7eaeb98f393603907f4bf15e4d (diff) | |
| parent | 839646c947c2be134dfc054222ec4e1a490b6259 (diff) | |
| download | cmd2-git-9a949467e3820af4477f6f7ea3bfe06a2a4fb7ae.tar.gz | |
Merge pull request #187 from python-cmd2/empty_clipboard
Fix a couple clipboard related bugs on Linux
Diffstat (limited to 'cmd2.py')
| -rwxr-xr-x | cmd2.py | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -300,7 +300,12 @@ def options(option_list, arg_desc="arg"): # Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux try: - _ = pyperclip.paste() + if six.PY3 and sys.platform.startswith('linux'): + # Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents + pyperclip.copy('') + else: + # Try getting the contents of the clipboard + _ = pyperclip.paste() except pyperclip.exceptions.PyperclipException: can_clip = False else: @@ -314,7 +319,8 @@ def get_paste_buffer(): """ pb_str = pyperclip.paste() - if six.PY2: + # If value returned from the clipboard is unicode and this is Python 2, convert to a "normal" Python 2 string first + if six.PY2 and not isinstance(pb_str, str): import unicodedata pb_str = unicodedata.normalize('NFKD', pb_str).encode('ascii', 'ignore') |
