Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually fully disable system clipboard (#5155) #5261

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/disable-system-clipboard.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* System clipboard can be fully disabled using ``$XONSH_USE_SYSTEM_CLIPBOARD``.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
9 changes: 8 additions & 1 deletion xonsh/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,14 @@ class PTKSetting(PromptSetting): # sub-classing -> sub-group
)
XONSH_COPY_ON_DELETE = Var.with_default(
False,
"Whether to copy words/lines to clipboard on deletion (must be set in .xonshrc file)."
"Whether to copy words/lines to clipboard on deletion (must be set in the run control file)."
"Does not have any effect in ``vi_mode``."
"Only available under the prompt-toolkit shell.",
azertyfun marked this conversation as resolved.
Show resolved Hide resolved
)
XONSH_USE_SYSTEM_CLIPBOARD = Var.with_default(
True,
"Whether to let the shell use the system clipboard (must be set in the run control file)."
"The main use-case is to fully disable clipboard integration in ``vi_mode``."
"Only available under the prompt-toolkit shell.",
)
XONSH_CTRL_BKSP_DELETION = Var.with_default(
Expand Down
8 changes: 6 additions & 2 deletions xonsh/ptk_shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from prompt_toolkit import ANSI
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.clipboard import InMemoryClipboard
from prompt_toolkit.enums import EditingMode
from prompt_toolkit.formatted_text import PygmentsTokens, to_formatted_text
from prompt_toolkit.history import ThreadedHistory
Expand Down Expand Up @@ -193,8 +194,11 @@ def __init__(self, **kwargs):
ptk_args.setdefault("history", self.history)
if not XSH.env.get("XONSH_COPY_ON_DELETE", False):
disable_copy_on_deletion()
if HAVE_SYS_CLIPBOARD:
ptk_args.setdefault("clipboard", PyperclipClipboard())
if HAVE_SYS_CLIPBOARD and (XSH.env.get("XONSH_USE_SYSTEM_CLIPBOARD", True)):
default_clipboard = PyperclipClipboard()
else:
default_clipboard = InMemoryClipboard()
ptk_args.setdefault("clipboard", default_clipboard)
self.prompter: PromptSession = PromptSession(**ptk_args)

self.prompt_formatter = PTKPromptFormatter(self)
Expand Down