Repository: saulpw/visidata

Issue:
Pasting from Clipboard in Windows 10
**Small description**
I cannot get any results pasted from the clipboard onto a visidata cell, selected cell or range of cells. 

On the most basic test:
- Create new sheet
- Create 1 cell
- I copy a short string from another app to the clipboard
- trying:
    - syspaste-cells or 
    - syspaste-cells-selected (while selecting a single cell), or
    - zP
- I get the following message "INFO: Type "CLIP /?" for usage."

This is a message from Windows regarding its CLIP application.

I have tried this, having multiple clipboard history activated, or deactivated. In both cases I get the same result.

Copying from visidata onto clipboard works alright with zY

**Expected result**
Pasted content in cell

**Actual result with screenshot**
If you get an unexpected error, please include the full stack trace that you get with `Ctrl-E`.
![image](https://github.com/saulpw/visidata/assets/1893701/ba3f066b-b46f-4055-9170-37af2bd5e87b)

No error captured (no ctrl-E)

**Steps to reproduce with sample data and a .vd**
First try reproducing without any user configuration by using the flag `-N`.
e.g. `echo "abc" | vd -f txt -N`

Same result.

Please attach the commandlog (saved with `Ctrl-D`)
[paste_problem_win.zip](https://github.com/saulpw/visidata/files/11748544/paste_problem_win.zip)

 to show the steps that led to the issue.
See [here](http://visidata.org/docs/save-restore/) for more details.

**Additional context**
Please include the version of VisiData and Python.
Visidata v2.11
Python 3.9.7


Discussion:
Hi @benignoc!

Thanks for such a thorough bug report! 

I just wanted to let you know that none of the maintaners have access to a Windows computer. Resolving of Windows issues largely relies on the Windows community putting love into the project.

We might take a look later to see if we can figure things out based on research, but you are probably in a better position to help with further debugging.

This is the relevant code: https://github.com/saulpw/visidata/blob/c53b28634182f98bedfaa7a3b9304af1b9716d6d/visidata/clipboard.py#LL13C27-L13C27
The trouble seems to be that [the paste command is "clip.exe"](https://github.com/saulpw/visidata/blob/c53b28634182f98bedfaa7a3b9304af1b9716d6d/visidata/clipboard.py#L15) which will cut but not paste. Stack Overflow has a relevant discussion of [ideas for paste tools](https://stackoverflow.com/a/54910545).

@benignoc I do not have a Windows machine to test on, but does this work from Powershell?
`vd --clipboard_paste_cmd='powershell -command "Get-Clipboard"'`

If so, then you should be able to get paste working if you add this line to your .visidatarc:
`options.clipboard_paste_cmd='powershell -command "Get-Clipboard"'`
@midichef hello, yes, by making it call Get-Clipboard, it works when launching vd from Powershell.
`vd --clipboard_paste_cmd='powershell -command "Get-Clipboard"'`
![image](https://github.com/saulpw/visidata/assets/1893701/87adff01-7545-4b40-afa1-13e19f01ddcf)

However, strangely enough, when I set .visidatarc with `options.clipboard_paste_cmd='powershell -command "Get-Clipboard"'`, I launch visidata and when I try to paste, it will always paste the string _Get-Clipboard_
![image](https://github.com/saulpw/visidata/assets/1893701/32b14307-ff33-4363-8b6c-6bfdd27516d6)
![image](https://github.com/saulpw/visidata/assets/1893701/8fd3f684-7f18-40bb-ae3c-3cfcb4d02b19)

@anjakefala I understand. Looking at the code, the only thing I spot (and I am by no means no expert) is
`if sys.platform == 'win32':
    syscopy_cmd_default = 'clip.exe'
    syspaste_cmd_default = 'clip.exe'`

I think that clip.exe is only meant to send stuff from command to clipboard, but not from clipboard to command line.

@midichef idea of calling powershell Get-Clipboard seems good, I do not know why setting the same option in .visidatarc does not seem to be working in the same way.
@benignoc I bet it gets dynamically over-written in that code-block =/ Because it is the one option whose default gets set based on operating system.

I will change the default, and try to address the option bug! Thanks @midichef =))

Resolving patch:
diff --git a/visidata/clipboard.py b/visidata/clipboard.py
--- a/visidata/clipboard.py
+++ b/visidata/clipboard.py
@@ -12,7 +12,7 @@
 
 if sys.platform == 'win32':
     syscopy_cmd_default = 'clip.exe'
-    syspaste_cmd_default = 'clip.exe'
+    syspaste_cmd_default = 'powershell -command Get-Clipboard'
 elif sys.platform == 'darwin':
     syscopy_cmd_default = 'pbcopy w'
     syspaste_cmd_default = 'pbpaste'


Test patch: