()
| 503 | |
| 504 | |
| 505 | def init_wsl_clipboard(): |
| 506 | def copy_wsl(text): |
| 507 | text = _stringifyText(text) # Converts non-str values to str. |
| 508 | with subprocess.Popen(["clip.exe"], stdin=subprocess.PIPE, close_fds=True) as p: |
| 509 | p.communicate(input=text.encode(ENCODING)) |
| 510 | |
| 511 | def paste_wsl(): |
| 512 | with subprocess.Popen( |
| 513 | ["powershell.exe", "-command", "Get-Clipboard"], |
| 514 | stdout=subprocess.PIPE, |
| 515 | stderr=subprocess.PIPE, |
| 516 | close_fds=True, |
| 517 | ) as p: |
| 518 | stdout = p.communicate()[0] |
| 519 | # WSL appends "\r\n" to the contents. |
| 520 | return stdout[:-2].decode(ENCODING) |
| 521 | |
| 522 | return copy_wsl, paste_wsl |
| 523 | |
| 524 | |
| 525 | # Automatic detection of clipboard mechanisms |
no outgoing calls
no test coverage detected