Skip to content

Commit 9676735

Browse files
committed
Experiment with clipboard handing.
1 parent c8d0b7b commit 9676735

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tcod/sdl/sys.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
import enum
4+
import warnings
45
from typing import Any, Tuple
56

67
from tcod.loader import ffi, lib
7-
from tcod.sdl import _check
8+
from tcod.sdl import _check, _get_error
89

910

1011
class Subsystem(enum.IntFlag):
@@ -61,3 +62,16 @@ def _get_power_info() -> Tuple[_PowerState, int, int]:
6162
seconds_of_power = buffer[0]
6263
percenage = buffer[1]
6364
return power_state, seconds_of_power, percenage
65+
66+
67+
def _get_clipboard() -> str:
68+
"""Return the text of the clipboard."""
69+
text = str(ffi.string(lib.SDL_GetClipboardText()), encoding="utf-8")
70+
if not text: # Show the reason for an empty return, this should probably be logged instead.
71+
warnings.warn(f"Return string is empty because: {_get_error()}")
72+
return text
73+
74+
75+
def _set_clipboard(text: str) -> None:
76+
"""Replace the clipboard with text."""
77+
_check(lib.SDL_SetClipboardText(text.encode("utf-8")))

0 commit comments

Comments
 (0)