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

Copy function propopsal #16

Closed
wants to merge 2 commits into from

Conversation

croketillo
Copy link
Contributor

Hi!
Here is a proposal for copying to the clipboard without using xclip. I haven't had time to test it, but I believe it might work.

I modified the copy_command function in utils and performed the clipboard copy using the pyperclip module, which I imported and should be added to the package installation requirements.

Please check to see if it works as you want.

@elkinaguas
Copy link
Owner

elkinaguas commented Nov 17, 2023

Hello,

Thanks again for your interest in Clir and contribution :)

Using pyperclip won't work without installing a "copy/paste mechanism for your system" first, like xclip or xsel. That's why I decided to use xclip directly. This is explained in Pyperclip's documentation.

I ran your code and I confirm this error in Ubuntu 22.04.

Traceback (most recent call last):
  File "/usr/local/bin/clir", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/rich_click/rich_command.py", line 126, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/clir/cli.py", line 80, in cp
    table.copy_command()
  File "/usr/local/lib/python3.10/dist-packages/clir/utils/objects.py", line 124, in copy_command
    to_clippboard(command)
  File "/usr/local/lib/python3.10/dist-packages/clir/utils/objects.py", line 109, in to_clippboard
    pyperclip.copy(command)
  File "/usr/local/lib/python3.10/dist-packages/pyperclip/__init__.py", line 659, in lazy_load_stub_copy
    return copy(text)
  File "/usr/local/lib/python3.10/dist-packages/pyperclip/__init__.py", line 336, in __call__
    raise PyperclipException(EXCEPT_MSG)
pyperclip.PyperclipException: 
    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 think it's better to stick with xclip and pbcopy until we find a way to copy commands using Python Standard Library.

Best,
Elkin

@croketillo
Copy link
Contributor Author

but xclip has to be installed (at least in Ubuntu) with apt... pyperclip can be installed with pip and therefore can be put as a dependency of the clir package when installed. That's why I proposed it.

but it may not be a valid option... you decide ;) don't worry.

It didn't give me problems in Ubuntu, but if it does... better look for another option.

We'll keep looking :D!

@croketillo croketillo closed this Nov 17, 2023
@elkinaguas
Copy link
Owner

Yes, we'll keep looking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants