Skip to content

Commit

Permalink
wip: OCS52 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlax committed Jun 4, 2024
1 parent dc38312 commit 31b2e09
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pgactivity/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,13 +1181,22 @@ def copy_focused_query_to_clipboard(self) -> str:
return "no focused process found"
if proc.query is None:
return "process has no query"
else:
try:
pyperclip.copy(proc.query)
except pyperclip.PyperclipException as exc:
logger.error(str(exc))
return "failed to copy to clipboard"
return f"query of process {proc.pid} copied to clipboard"

try:
raise pyperclip.PyperclipException
pyperclip.copy(proc.query)
return f"query of process {proc.pid} copied to display clipboard"
except pyperclip.PyperclipException as exc:
logger.warning("failed to copy using pyperclip: %s", exc)

# Use OCS 52
import base64
import sys

file = sys.__stderr__
base64_text = base64.b64encode(proc.query.encode()).decode()
file.write(";".join(["\x1b]52", "c", base64_text]) + "\a")
return f"query of process {proc.pid} copied to OCS52 clipboard"


ActivityStats = Union[
Expand Down

0 comments on commit 31b2e09

Please sign in to comment.