Best-effort OS clipboard via subprocess; True on success.
(text: str)
| 155 | |
| 156 | |
| 157 | def _set_clipboard(text: str) -> bool: |
| 158 | """Best-effort OS clipboard via subprocess; True on success.""" |
| 159 | if sys.platform == "darwin": |
| 160 | candidates = [["pbcopy"]] |
| 161 | elif sys.platform.startswith("win"): |
| 162 | candidates = [["clip"]] |
| 163 | else: |
| 164 | candidates = [["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"]] |
| 165 | for cmd in candidates: |
| 166 | try: |
| 167 | proc = subprocess.run( |
| 168 | cmd, input=text.encode("utf-8"), capture_output=True, timeout=5 |
| 169 | ) |
| 170 | if proc.returncode == 0: |
| 171 | return True |
| 172 | except Exception: |
| 173 | continue |
| 174 | return False |
| 175 | |
| 176 | |
| 177 | def _write_to_file(text: str, filename: str) -> str: |
no test coverage detected