()
| 163 | |
| 164 | |
| 165 | def init_xclip_clipboard(): |
| 166 | DEFAULT_SELECTION = "c" |
| 167 | PRIMARY_SELECTION = "p" |
| 168 | |
| 169 | def copy_xclip(text, primary=False): |
| 170 | text = _stringifyText(text) # Converts non-str values to str. |
| 171 | selection = DEFAULT_SELECTION |
| 172 | if primary: |
| 173 | selection = PRIMARY_SELECTION |
| 174 | with subprocess.Popen( |
| 175 | ["xclip", "-selection", selection], stdin=subprocess.PIPE, close_fds=True |
| 176 | ) as p: |
| 177 | p.communicate(input=text.encode(ENCODING)) |
| 178 | |
| 179 | def paste_xclip(primary=False): |
| 180 | selection = DEFAULT_SELECTION |
| 181 | if primary: |
| 182 | selection = PRIMARY_SELECTION |
| 183 | with subprocess.Popen( |
| 184 | ["xclip", "-selection", selection, "-o"], |
| 185 | stdout=subprocess.PIPE, |
| 186 | stderr=subprocess.PIPE, |
| 187 | close_fds=True, |
| 188 | ) as p: |
| 189 | stdout = p.communicate()[0] |
| 190 | # Intentionally ignore extraneous output on stderr when clipboard is empty |
| 191 | return stdout.decode(ENCODING) |
| 192 | |
| 193 | return copy_xclip, paste_xclip |
| 194 | |
| 195 | |
| 196 | def init_xsel_clipboard(): |
no outgoing calls
no test coverage detected