prompt-toolkit / prompt-toolkit/python-prompt-toolkit

When deleting word, Pyperclip could not find a copy/paste mechanism for your system.

Open
#1,412 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I recently updated my xonsh environment to xonsh 0.9.27 and prompt-toolkit 3.0.18 and in my headless Linux environment, I've started noticing that when I hit Option+Delete, I get a traceback:

Unhandled exception in event loop:
  File "/usr/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/input/vt100.py", line 168, in callback_wrapper
    callback()
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/application/application.py", line 691, in read_from_input
    self.key_processor.process_keys()
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 274, in process_keys
    self._process_coroutine.send(key_press)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 186, in _process
    self._call_handler(matches[-1], key_sequence=buffer[:])
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_processor.py", line 329, in _call_handler
    handler.call(event)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/key_bindings.py", line 102, in call
    result = self.handler(event)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/bindings/named_commands.py", line 420, in backward_kill_word
    unix_word_rubout(event, WORD=False)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/key_binding/bindings/named_commands.py", line 408, in unix_word_rubout
    event.app.clipboard.set_text(deleted)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/clipboard/base.py", line 101, in set_text
    self._clipboard().set_text(text)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/clipboard/base.py", line 52, in set_text
    self.set_data(ClipboardData(text))
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/prompt_toolkit/clipboard/pyperclip.py", line 25, in set_data
    pyperclip.copy(data.text)
  File "/usr/local/google/home/jaraco/.local/pipx/venvs/xonsh/lib/python3.9/site-packages/pyperclip/__init__.py", line 336, in __call__
    raise PyperclipException(EXCEPT_MSG)

Exception 
    Pyperclip could not find a copy/paste mechanism for your system.
    For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error 

I'm unsure who configures those bindings to cause Option+Delete to not only delete a word, but to put that word on the clipboard, but that behavior is concerning for two reasons:

  • The error above is obnoxious. Attempts to save to a non-existent clipboard should be suppressed.
  • In environments with a working clipboard, I want to be able to delete words without mutating the clipboard.

For the second reason, can you suggest how one can disable this behavior?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading prompt_toolkit/key_binding/bindings/named_commands.py around unix_word_rubout and prompt_toolkit/clipboard/pyperclip.py around set_data, using the traceback as the entry point. Determine how word deletion invokes clipboard writes and how unavailable clipboard support is surfaced. Done means headless deletion no longer raises this exception and the clipboard mutation can be disabled as requested, with focused tests added if the existing test layout identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.