Skip to content

Commit

Permalink
Actually fully disable system clipboard (xonsh#5155) (xonsh#5261)
Browse files Browse the repository at this point in the history
Allow to fully disable system clipboard

Fixes xonsh#5155

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

After discussion in xonsh#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>
  • Loading branch information
2 people authored and theadam committed Mar 11, 2024
1 parent 3b7c9d4 commit 4730bd8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
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.",
)
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

0 comments on commit 4730bd8

Please sign in to comment.