-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
16 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
"""Utils module.""" | ||
|
||
from functools import wraps | ||
from typing import Any | ||
from typing import Callable | ||
from typing import TypeVar | ||
from typing import cast | ||
|
||
import pyperclip | ||
from typing_extensions import ParamSpec | ||
|
||
|
||
F = TypeVar("F", bound=Callable[..., str]) | ||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
|
||
|
||
def use_clipboard(func: F) -> F: | ||
def use_clipboard(func: Callable[P, T]) -> Callable[P, str]: | ||
"""Augument decorated functions argument to copy the output to the clipboard.""" | ||
|
||
@wraps(func) | ||
def wrapper_func(*args: Any, **kwargs: Any) -> str: | ||
def wrapper_func(*args: P.args, **kwargs: P.kwargs) -> str: | ||
"""Wrapped function.""" | ||
out = func(*args, **kwargs) | ||
|
||
if kwargs.get("to_clp"): | ||
pyperclip.copy(out) | ||
print("ArrayTeX: copied to clipboard") | ||
|
||
return out | ||
return str(out) | ||
|
||
return cast(F, wrapper_func) | ||
return wrapper_func |