|
46 | 46 | import pyparsing |
47 | 47 | import pyperclip |
48 | 48 |
|
| 49 | +# Newer versions of pyperclip are released as a single file, but older versions had a more complicated structure |
| 50 | +try: |
| 51 | + from pyperclip.exceptions import PyperclipException |
| 52 | +except ImportError: |
| 53 | + # noinspection PyUnresolvedReferences |
| 54 | + from pyperclip import PyperclipException |
| 55 | + |
49 | 56 | # On some systems, pyperclip will import gtk for its clipboard functionality. |
50 | 57 | # The following code is a workaround for gtk interfering with printing from a background |
51 | 58 | # thread while the CLI thread is blocking in raw_input() in Python 2 on Linux. |
|
98 | 105 | else: |
99 | 106 | BROKEN_PIPE_ERROR = IOError |
100 | 107 |
|
101 | | -__version__ = '0.7.8a' |
| 108 | +__version__ = '0.7.8' |
102 | 109 |
|
103 | 110 | # Pyparsing enablePackrat() can greatly speed up parsing, but problems have been seen in Python 3 in the past |
104 | 111 | pyparsing.ParserElement.enablePackrat() |
@@ -324,13 +331,17 @@ def new_func(instance, arg): |
324 | 331 | # Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux |
325 | 332 | # noinspection PyUnresolvedReferences |
326 | 333 | try: |
327 | | - if sys.platform.startswith('linux'): |
| 334 | + # Get the version of the pyperclip module as a float |
| 335 | + pyperclip_ver = float('.'.join(pyperclip.__version__.split('.')[:2])) |
| 336 | + |
| 337 | + # The extraneous output bug in pyperclip on Linux using xclip was fixed in more recent versions of pyperclip |
| 338 | + if sys.platform.startswith('linux') and pyperclip_ver < 1.6: |
328 | 339 | # Avoid extraneous output to stderr from xclip when clipboard is empty at cost of overwriting clipboard contents |
329 | 340 | pyperclip.copy('') |
330 | 341 | else: |
331 | 342 | # Try getting the contents of the clipboard |
332 | 343 | _ = pyperclip.paste() |
333 | | -except pyperclip.exceptions.PyperclipException: |
| 344 | +except PyperclipException: |
334 | 345 | can_clip = False |
335 | 346 | else: |
336 | 347 | can_clip = True |
@@ -582,7 +593,7 @@ def poutput(self, msg, end='\n'): |
582 | 593 | Also handles BrokenPipeError exceptions for when a commands's output has been piped to another process and |
583 | 594 | that process terminates before the cmd2 command is finished executing. |
584 | 595 |
|
585 | | - :param msg: str - message to print to current stdout - anyting convertible to a str with '{}'.format() is OK |
| 596 | + :param msg: str - message to print to current stdout - anything convertible to a str with '{}'.format() is OK |
586 | 597 | :param end: str - string appended after the end of the message if not already present, default a newline |
587 | 598 | """ |
588 | 599 | if msg is not None and msg != '': |
|
0 commit comments