Actually fully disable system clipboard (#5155) (#5261)

Allow to fully disable system clipboard

Fixes #5155

In VI mode, disabling "delete" hotkeys isn't enough.

After discussion in #5261, we don't change the default behavior but
allow fully disabling the system clipboard to better support the
use-case of VI mode user.

Co-authored-by: Nathan Monfils <nmo@escaux.com>
This commit is contained in:
Nathan Monfils 2024-01-15 11:25:23 +01:00 committed by GitHub
parent 062b84b30d
commit 5b20891975
Failed to generate hash of commit
3 changed files with 37 additions and 3 deletions

View file

@ -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>

View file

@ -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.",
)
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(

View file

@ -7,6 +7,7 @@ from types import MethodType
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
@ -193,8 +194,11 @@ class PromptToolkitShell(BaseShell):
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)