Skip to content

Commit 21ec4f8

Browse files
bagagepellouxprayer
authored andcommitted
Use pyperclip library to support Windows as well
1 parent 932a1c8 commit 21ec4f8

File tree

2 files changed

+4
-57
lines changed

2 files changed

+4
-57
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package_data={"": files},
2121
include_package_data=True,
2222
install_requires=[
23+
"pyperclip",
2324
"pygments",
2425
"wcwidth",
2526
"windows-curses; platform_system=='Windows'"

suplemon/modules/system_clipboard.py

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@
44

55
from suplemon.suplemon_module import Module
66

7+
import pyperclip
78

89
class SystemClipboard(Module):
910
"""Integrates the system clipboard with suplemon."""
1011

1112
def init(self):
1213
self.init_logging(__name__)
13-
if self.has_xsel_support():
14-
self.clipboard_type = "xsel"
15-
elif self.has_pb_support():
16-
self.clipboard_type = "pb"
17-
elif self.has_xclip_support():
18-
self.clipboard_type = "xclip"
19-
else:
20-
self.logger.warning(
21-
"Can't use system clipboard. Install 'xsel' or 'pbcopy' or 'xclip' for system clipboard support.")
22-
return False
2314
self.bind_event_before("insert", self.insert)
2415
self.bind_event_after("copy", self.copy)
2516
self.bind_event_after("cut", self.copy)
@@ -35,55 +26,10 @@ def insert(self, event):
3526
self.app.get_editor().set_buffer(lines)
3627

3728
def get_clipboard(self):
38-
try:
39-
if self.clipboard_type == "xsel":
40-
command = ["xsel", "-b"]
41-
elif self.clipboard_type == "pb":
42-
command = ["pbpaste", "-Prefer", "txt"]
43-
elif self.clipboard_type == "xclip":
44-
command = ["xclip", "-selection", "clipboard", "-out"]
45-
else:
46-
return False
47-
data = subprocess.check_output(command, universal_newlines=True)
48-
return data
49-
except:
50-
return False
29+
return pyperclip.paste()
5130

5231
def set_clipboard(self, data):
53-
try:
54-
if self.clipboard_type == "xsel":
55-
command = ["xsel", "-i", "-b"]
56-
elif self.clipboard_type == "pb":
57-
command = ["pbcopy"]
58-
elif self.clipboard_type == "xclip":
59-
command = ["xclip", "-selection", "clipboard", "-in"]
60-
else:
61-
return False
62-
p = subprocess.Popen(command, stdin=subprocess.PIPE)
63-
out, err = p.communicate(input=bytes(data, "utf-8"))
64-
return out
65-
except:
66-
return False
67-
68-
def has_pb_support(self):
69-
output = self.get_output(["which", "pbcopy"])
70-
return output
71-
72-
def has_xsel_support(self):
73-
output = self.get_output(["xsel", "--version"])
74-
return output
75-
76-
def has_xclip_support(self):
77-
output = self.get_output(["which", "xclip"]) # xclip -version outputs to stderr
78-
return output
79-
80-
def get_output(self, cmd):
81-
try:
82-
process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
83-
except (OSError, EnvironmentError): # can't use FileNotFoundError in Python 2
84-
return False
85-
out, err = process.communicate()
86-
return out
32+
pyperclip.copy(data)
8733

8834

8935
module = {

0 commit comments

Comments
 (0)