We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `visidata/clipboard.py`
Content:
```
1 from copy import copy, deepcopy
2 import shutil
3 import subprocess
4 import io
5 import sys
6 import tempfile
7 import functools
8 import os
9 
10 from visidata import VisiData, vd, asyncthread
11 from visidata import Sheet, Path
12 
13 if sys.platform == 'win32':
14     syscopy_cmd_default = 'clip.exe'
15     syspaste_cmd_default = 'clip.exe'
16 elif sys.platform == 'darwin':
17     syscopy_cmd_default = 'pbcopy w'
18     syspaste_cmd_default = 'pbpaste'
19 else:
20     if 'WAYLAND_DISPLAY' in os.environ:
21         syscopy_cmd_default = 'wl-copy'
22         syspaste_cmd_default = 'wl-paste'
23     else:
24         syscopy_cmd_default = 'xclip -selection clipboard -filter'  # xsel --clipboard --input
25         syspaste_cmd_default = 'xclip -selection clipboard -o'  # xsel --clipboard
26 
27 vd.option('clipboard_copy_cmd', syscopy_cmd_default, 'command to copy stdin to system clipboard', sheettype=None)
28 vd.option('clipboard_paste_cmd', syspaste_cmd_default, 'command to send contents of system clipboard to stdout', sheettype=None)
29 
30 
31 @Sheet.api
32 def copyRows(sheet, rows):
33     vd.memory.cliprows = rows
34     vd.memory.clipcols = list(sheet.visibleCols)
35     if not rows:
36         vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)
37     else:
38         vd.status('copied %d %s to clipboard' % (len(rows), sheet.rowtype))
39 
40 @Sheet.api
41 def copyCells(sheet, col, rows):
42     vd.memory.clipcells = [col.getTypedValue(r) for r in rows]
43     if not rows:
44         vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)
45         return
46     vd.status('copied %d %s.%s to clipboard' % (len(rows), sheet.rowtype, col.name))
47 
48 
49 @Sheet.api
50 def syscopyValue(sheet, val):
51     # pipe val to stdin of clipboard command
52 
53     p = subprocess.run(
54         sheet.options.clipboard_copy_cmd.split(),
55         input=val,
56         encoding=sheet.options.encoding,
57         stdout=subprocess.DEVNULL)
58 
59     vd.status('copied value to system clipboard')
60 
61 
62 @Sheet.api
63 def syscopyCells(sheet, cols, rows, filetype=None):
64     filetype = filetype or vd.input("copy %d %s as filetype: " % (len(rows), sheet.rowtype), value=sheet.options.save_filetype or 'tsv')
65     sheet.syscopyCells_async(cols, rows, filetype)
66 
67 
68 @Sheet.api
69 @asyncthread
70 def syscopyCells_async(sheet, cols, rows, filetype):
71     vs = copy(sheet)
72     vs.rows = rows or vd.fail('no %s selected' % sheet.rowtype)
73     vs.columns = cols
74 
75     vd.status(f'copying {vs.nRows} {vs.rowtype} to system clipboard as {filetype}')
76 
77     with io.StringIO() as buf:
78         vd.sync(vd.saveSheets(Path(sheet.name+'.'+filetype, fptext=buf), vs))
79         subprocess.run(
80             sheet.options.clipboard_copy_cmd.split(),
81             input=buf.getvalue(),
82             encoding=sheet.options.encoding,
83             stdout=subprocess.DEVNULL)
84 
85 
86 @VisiData.api
87 def sysclipValue(vd):
88     cmd = vd.options.clipboard_paste_cmd
89     return subprocess.check_output(vd.options.clipboard_paste_cmd.split()).decode('utf-8')
90 
91 
92 @VisiData.api
93 @asyncthread
94 def pasteFromClipboard(vd, cols, rows):
95     text = vd.getLastArgs() or vd.sysclipValue().strip() or vd.fail('system clipboard is empty')
96 
97     vd.addUndoSetValues(cols, rows)
98     lines = text.split('\n')
99     if not lines:
100         vd.warning('nothing to paste')
101         return
102 
103     vs = cols[0].sheet
104     newrows = [vs.newRow() for i in range(len(lines)-len(rows))]
105     if newrows:
106         rows.extend(newrows)
107         vs.addRows(newrows)
108 
109     for line, r in zip(lines, rows):
110         for v, c in zip(line.split('\t'), cols):
111             c.setValue(r, v)
112 
113 
114 @Sheet.api
115 def delete_row(sheet, rowidx):
116     if not sheet.defer:
117         oldrow = sheet.rows.pop(rowidx)
118         vd.addUndo(sheet.rows.insert, rowidx, oldrow)
119         # clear the deleted row from selected rows
120         if sheet.isSelected(oldrow):
121             sheet.addUndoSelection()
122             sheet.unselectRow(oldrow)
123     else:
124         oldrow = sheet.rows[rowidx]
125         sheet.rowDeleted(oldrow)
126 
127     sheet.setModified()
128     return oldrow
129 
130 @Sheet.api
131 def paste_after(sheet, rowidx):
132     if not vd.memory.cliprows:  #1793
133         vd.warning('nothing to paste')
134         return
135     to_paste = list(deepcopy(r) for r in reversed(vd.memory.cliprows))
136     sheet.addRows(to_paste, index=rowidx)
137 
138 
139 
140 Sheet.addCommand('y', 'copy-row', 'copyRows([cursorRow])', 'yank (copy) current row to clipboard')
141 
142 Sheet.addCommand('p', 'paste-after', 'paste_after(cursorRowIndex)', 'paste clipboard rows after current row')
143 Sheet.addCommand('P', 'paste-before', 'paste_after(cursorRowIndex-1)', 'paste clipboard rows before current row')
144 
145 Sheet.addCommand('gy', 'copy-selected', 'copyRows(onlySelectedRows)', 'yank (copy) selected rows to clipboard')
146 
147 Sheet.addCommand('zy', 'copy-cell', 'copyCells(cursorCol, [cursorRow]); vd.memo("clipval", cursorCol, cursorRow)', 'yank (copy) current cell to clipboard')
148 Sheet.addCommand('zp', 'paste-cell', 'cursorCol.setValuesTyped([cursorRow], vd.memory.clipval)', 'set contents of current cell to last clipboard value')
149 
150 Sheet.addCommand('d', 'delete-row', 'delete_row(cursorRowIndex); defer and cursorDown(1)', 'delete current row')
151 Sheet.addCommand('gd', 'delete-selected', 'deleteSelected()', 'delete selected rows')
152 Sheet.addCommand('zd', 'delete-cell', 'cursorCol.setValues([cursorRow], options.null_value)', 'delete current cell (set to None)')
153 Sheet.addCommand('gzd', 'delete-cells', 'cursorCol.setValues(onlySelectedRows, options.null_value)', 'delete contents of current column for selected rows (set to None)')
154 
155 Sheet.bindkey('BUTTON2_PRESSED', 'go-mouse')
156 Sheet.addCommand('BUTTON2_RELEASED', 'syspaste-cells', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], rows[cursorRowIndex:])', 'paste from system clipboard to region starting at cursor')
157 Sheet.bindkey('BUTTON2_CLICKED', 'go-mouse')
158 Sheet.bindkey('zP', 'syspaste-cells')
159 Sheet.addCommand('gzP', 'syspaste-cells-selected', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], someSelectedRows)', 'paste from system clipboard to selected cells')
160 
161 Sheet.addCommand('gzy', 'copy-cells', 'copyCells(cursorCol, onlySelectedRows)', 'yank (copy) contents of current column for selected rows to clipboard')
162 Sheet.addCommand('gzp', 'setcol-clipboard', 'for r, v in zip(onlySelectedRows, itertools.cycle(vd.memory.clipcells or [None])): cursorCol.setValuesTyped([r], v)', 'set cells of current column for selected rows to last clipboard value')
163 
164 Sheet.addCommand('Y', 'syscopy-row', 'syscopyCells(visibleCols, [cursorRow])', 'yank (copy) current row to system clipboard (using options.clipboard_copy_cmd)')
165 
166 Sheet.addCommand('gY', 'syscopy-selected', 'syscopyCells(visibleCols, onlySelectedRows)', 'yank (copy) selected rows to system clipboard (using options.clipboard_copy_cmd)')
167 Sheet.addCommand('zY', 'syscopy-cell', 'syscopyValue(cursorDisplay)', 'yank (copy) current cell to system clipboard (using options.clipboard_copy_cmd)')
168 Sheet.addCommand('gzY', 'syscopy-cells', 'syscopyCells([cursorCol], onlySelectedRows, filetype="txt")', 'yank (copy) contents of current column from selected rows to system clipboard (using options.clipboard_copy_cmd')
169 
170 Sheet.addCommand('x', 'cut-row', 'copyRows([sheet.delete_row(cursorRowIndex)]); defer and cursorDown(1)', 'delete (cut) current row and move it to clipboard')
171 Sheet.addCommand('gx', 'cut-selected', 'copyRows(onlySelectedRows); deleteSelected()', 'delete (cut) selected rows and move them to clipboard')
172 Sheet.addCommand('zx', 'cut-cell', 'copyCells(cursorCol, [cursorRow]); cursorCol.setValues([cursorRow], None)', 'delete (cut) current cell and move it to clipboard')
173 Sheet.addCommand('gzx', 'cut-cells', 'copyCells(cursorCol, onlySelectedRows); cursorCol.setValues(onlySelectedRows, None)', 'delete (cut) contents of current column for selected rows and move them to clipboard')
174 
175 
176 Sheet.bindkey('KEY_DC', 'delete-cell'),
177 Sheet.bindkey('gKEY_DC', 'delete-cells'),
178 
179 vd.addMenuItems('''
180     Edit > Delete > current row > delete-row
181     Edit > Delete > current cell > delete-cell
182     Edit > Delete > selected rows > delete-selected
183     Edit > Delete > selected cells > delete-cells
184     Edit > Copy > current cell > copy-cell
185     Edit > Copy > current row > copy-row
186     Edit > Copy > selected cells > copy-cells
187     Edit > Copy > selected rows > copy-selected
188     Edit > Copy > to system clipboard > current cell > syscopy-cell
189     Edit > Copy > to system clipboard > current row > syscopy-row
190     Edit > Copy > to system clipboard > selected cells > syscopy-cells
191     Edit > Copy > to system clipboard > selected rows > syscopy-selected
192     Edit > Cut > current row > cut-row
193     Edit > Cut > selected cells > cut-selected
194     Edit > Cut > current cell > cut-cell
195     Edit > Paste > row after > paste-after
196     Edit > Paste > row before > paste-before
197     Edit > Paste > into selected cells > setcol-clipboard
198     Edit > Paste > into current cell > paste-cell
199     Edit > Paste > from system clipboard > cells at cursor > syspaste-cells
200     Edit > Paste > from system clipboard > selected cells > syspaste-cells-selected
201 ''')
202
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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'

{"golden_diff": "diff --git a/visidata/clipboard.py b/visidata/clipboard.py\n--- a/visidata/clipboard.py\n+++ b/visidata/clipboard.py\n@@ -12,7 +12,7 @@\n \n if sys.platform == 'win32':\n     syscopy_cmd_default = 'clip.exe'\n-    syspaste_cmd_default = 'clip.exe'\n+    syspaste_cmd_default = 'powershell -command Get-Clipboard'\n elif sys.platform == 'darwin':\n     syscopy_cmd_default = 'pbcopy w'\n     syspaste_cmd_default = 'pbpaste'\n", "issue": "Pasting from Clipboard in Windows 10\n**Small description**\r\nI cannot get any results pasted from the clipboard onto a visidata cell, selected cell or range of cells. \r\n\r\nOn the most basic test:\r\n- Create new sheet\r\n- Create 1 cell\r\n- I copy a short string from another app to the clipboard\r\n- trying:\r\n    - syspaste-cells or \r\n    - syspaste-cells-selected (while selecting a single cell), or\r\n    - zP\r\n- I get the following message \"INFO: Type \"CLIP /?\" for usage.\"\r\n\r\nThis is a message from Windows regarding its CLIP application.\r\n\r\nI have tried this, having multiple clipboard history activated, or deactivated. In both cases I get the same result.\r\n\r\nCopying from visidata onto clipboard works alright with zY\r\n\r\n**Expected result**\r\nPasted content in cell\r\n\r\n**Actual result with screenshot**\r\nIf you get an unexpected error, please include the full stack trace that you get with `Ctrl-E`.\r\n![image](https://github.com/saulpw/visidata/assets/1893701/ba3f066b-b46f-4055-9170-37af2bd5e87b)\r\n\r\nNo error captured (no ctrl-E)\r\n\r\n**Steps to reproduce with sample data and a .vd**\r\nFirst try reproducing without any user configuration by using the flag `-N`.\r\ne.g. `echo \"abc\" | vd -f txt -N`\r\n\r\nSame result.\r\n\r\nPlease attach the commandlog (saved with `Ctrl-D`)\r\n[paste_problem_win.zip](https://github.com/saulpw/visidata/files/11748544/paste_problem_win.zip)\r\n\r\n to show the steps that led to the issue.\r\nSee [here](http://visidata.org/docs/save-restore/) for more details.\r\n\r\n**Additional context**\r\nPlease include the version of VisiData and Python.\r\nVisidata v2.11\r\nPython 3.9.7\n", "before_files": [{"content": "from copy import copy, deepcopy\nimport shutil\nimport subprocess\nimport io\nimport sys\nimport tempfile\nimport functools\nimport os\n\nfrom visidata import VisiData, vd, asyncthread\nfrom visidata import Sheet, Path\n\nif sys.platform == 'win32':\n    syscopy_cmd_default = 'clip.exe'\n    syspaste_cmd_default = 'clip.exe'\nelif sys.platform == 'darwin':\n    syscopy_cmd_default = 'pbcopy w'\n    syspaste_cmd_default = 'pbpaste'\nelse:\n    if 'WAYLAND_DISPLAY' in os.environ:\n        syscopy_cmd_default = 'wl-copy'\n        syspaste_cmd_default = 'wl-paste'\n    else:\n        syscopy_cmd_default = 'xclip -selection clipboard -filter'  # xsel --clipboard --input\n        syspaste_cmd_default = 'xclip -selection clipboard -o'  # xsel --clipboard\n\nvd.option('clipboard_copy_cmd', syscopy_cmd_default, 'command to copy stdin to system clipboard', sheettype=None)\nvd.option('clipboard_paste_cmd', syspaste_cmd_default, 'command to send contents of system clipboard to stdout', sheettype=None)\n\n\n@Sheet.api\ndef copyRows(sheet, rows):\n    vd.memory.cliprows = rows\n    vd.memory.clipcols = list(sheet.visibleCols)\n    if not rows:\n        vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)\n    else:\n        vd.status('copied %d %s to clipboard' % (len(rows), sheet.rowtype))\n\n@Sheet.api\ndef copyCells(sheet, col, rows):\n    vd.memory.clipcells = [col.getTypedValue(r) for r in rows]\n    if not rows:\n        vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)\n        return\n    vd.status('copied %d %s.%s to clipboard' % (len(rows), sheet.rowtype, col.name))\n\n\n@Sheet.api\ndef syscopyValue(sheet, val):\n    # pipe val to stdin of clipboard command\n\n    p = subprocess.run(\n        sheet.options.clipboard_copy_cmd.split(),\n        input=val,\n        encoding=sheet.options.encoding,\n        stdout=subprocess.DEVNULL)\n\n    vd.status('copied value to system clipboard')\n\n\n@Sheet.api\ndef syscopyCells(sheet, cols, rows, filetype=None):\n    filetype = filetype or vd.input(\"copy %d %s as filetype: \" % (len(rows), sheet.rowtype), value=sheet.options.save_filetype or 'tsv')\n    sheet.syscopyCells_async(cols, rows, filetype)\n\n\n@Sheet.api\n@asyncthread\ndef syscopyCells_async(sheet, cols, rows, filetype):\n    vs = copy(sheet)\n    vs.rows = rows or vd.fail('no %s selected' % sheet.rowtype)\n    vs.columns = cols\n\n    vd.status(f'copying {vs.nRows} {vs.rowtype} to system clipboard as {filetype}')\n\n    with io.StringIO() as buf:\n        vd.sync(vd.saveSheets(Path(sheet.name+'.'+filetype, fptext=buf), vs))\n        subprocess.run(\n            sheet.options.clipboard_copy_cmd.split(),\n            input=buf.getvalue(),\n            encoding=sheet.options.encoding,\n            stdout=subprocess.DEVNULL)\n\n\n@VisiData.api\ndef sysclipValue(vd):\n    cmd = vd.options.clipboard_paste_cmd\n    return subprocess.check_output(vd.options.clipboard_paste_cmd.split()).decode('utf-8')\n\n\n@VisiData.api\n@asyncthread\ndef pasteFromClipboard(vd, cols, rows):\n    text = vd.getLastArgs() or vd.sysclipValue().strip() or vd.fail('system clipboard is empty')\n\n    vd.addUndoSetValues(cols, rows)\n    lines = text.split('\\n')\n    if not lines:\n        vd.warning('nothing to paste')\n        return\n\n    vs = cols[0].sheet\n    newrows = [vs.newRow() for i in range(len(lines)-len(rows))]\n    if newrows:\n        rows.extend(newrows)\n        vs.addRows(newrows)\n\n    for line, r in zip(lines, rows):\n        for v, c in zip(line.split('\\t'), cols):\n            c.setValue(r, v)\n\n\n@Sheet.api\ndef delete_row(sheet, rowidx):\n    if not sheet.defer:\n        oldrow = sheet.rows.pop(rowidx)\n        vd.addUndo(sheet.rows.insert, rowidx, oldrow)\n        # clear the deleted row from selected rows\n        if sheet.isSelected(oldrow):\n            sheet.addUndoSelection()\n            sheet.unselectRow(oldrow)\n    else:\n        oldrow = sheet.rows[rowidx]\n        sheet.rowDeleted(oldrow)\n\n    sheet.setModified()\n    return oldrow\n\n@Sheet.api\ndef paste_after(sheet, rowidx):\n    if not vd.memory.cliprows:  #1793\n        vd.warning('nothing to paste')\n        return\n    to_paste = list(deepcopy(r) for r in reversed(vd.memory.cliprows))\n    sheet.addRows(to_paste, index=rowidx)\n\n\n\nSheet.addCommand('y', 'copy-row', 'copyRows([cursorRow])', 'yank (copy) current row to clipboard')\n\nSheet.addCommand('p', 'paste-after', 'paste_after(cursorRowIndex)', 'paste clipboard rows after current row')\nSheet.addCommand('P', 'paste-before', 'paste_after(cursorRowIndex-1)', 'paste clipboard rows before current row')\n\nSheet.addCommand('gy', 'copy-selected', 'copyRows(onlySelectedRows)', 'yank (copy) selected rows to clipboard')\n\nSheet.addCommand('zy', 'copy-cell', 'copyCells(cursorCol, [cursorRow]); vd.memo(\"clipval\", cursorCol, cursorRow)', 'yank (copy) current cell to clipboard')\nSheet.addCommand('zp', 'paste-cell', 'cursorCol.setValuesTyped([cursorRow], vd.memory.clipval)', 'set contents of current cell to last clipboard value')\n\nSheet.addCommand('d', 'delete-row', 'delete_row(cursorRowIndex); defer and cursorDown(1)', 'delete current row')\nSheet.addCommand('gd', 'delete-selected', 'deleteSelected()', 'delete selected rows')\nSheet.addCommand('zd', 'delete-cell', 'cursorCol.setValues([cursorRow], options.null_value)', 'delete current cell (set to None)')\nSheet.addCommand('gzd', 'delete-cells', 'cursorCol.setValues(onlySelectedRows, options.null_value)', 'delete contents of current column for selected rows (set to None)')\n\nSheet.bindkey('BUTTON2_PRESSED', 'go-mouse')\nSheet.addCommand('BUTTON2_RELEASED', 'syspaste-cells', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], rows[cursorRowIndex:])', 'paste from system clipboard to region starting at cursor')\nSheet.bindkey('BUTTON2_CLICKED', 'go-mouse')\nSheet.bindkey('zP', 'syspaste-cells')\nSheet.addCommand('gzP', 'syspaste-cells-selected', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], someSelectedRows)', 'paste from system clipboard to selected cells')\n\nSheet.addCommand('gzy', 'copy-cells', 'copyCells(cursorCol, onlySelectedRows)', 'yank (copy) contents of current column for selected rows to clipboard')\nSheet.addCommand('gzp', 'setcol-clipboard', 'for r, v in zip(onlySelectedRows, itertools.cycle(vd.memory.clipcells or [None])): cursorCol.setValuesTyped([r], v)', 'set cells of current column for selected rows to last clipboard value')\n\nSheet.addCommand('Y', 'syscopy-row', 'syscopyCells(visibleCols, [cursorRow])', 'yank (copy) current row to system clipboard (using options.clipboard_copy_cmd)')\n\nSheet.addCommand('gY', 'syscopy-selected', 'syscopyCells(visibleCols, onlySelectedRows)', 'yank (copy) selected rows to system clipboard (using options.clipboard_copy_cmd)')\nSheet.addCommand('zY', 'syscopy-cell', 'syscopyValue(cursorDisplay)', 'yank (copy) current cell to system clipboard (using options.clipboard_copy_cmd)')\nSheet.addCommand('gzY', 'syscopy-cells', 'syscopyCells([cursorCol], onlySelectedRows, filetype=\"txt\")', 'yank (copy) contents of current column from selected rows to system clipboard (using options.clipboard_copy_cmd')\n\nSheet.addCommand('x', 'cut-row', 'copyRows([sheet.delete_row(cursorRowIndex)]); defer and cursorDown(1)', 'delete (cut) current row and move it to clipboard')\nSheet.addCommand('gx', 'cut-selected', 'copyRows(onlySelectedRows); deleteSelected()', 'delete (cut) selected rows and move them to clipboard')\nSheet.addCommand('zx', 'cut-cell', 'copyCells(cursorCol, [cursorRow]); cursorCol.setValues([cursorRow], None)', 'delete (cut) current cell and move it to clipboard')\nSheet.addCommand('gzx', 'cut-cells', 'copyCells(cursorCol, onlySelectedRows); cursorCol.setValues(onlySelectedRows, None)', 'delete (cut) contents of current column for selected rows and move them to clipboard')\n\n\nSheet.bindkey('KEY_DC', 'delete-cell'),\nSheet.bindkey('gKEY_DC', 'delete-cells'),\n\nvd.addMenuItems('''\n    Edit > Delete > current row > delete-row\n    Edit > Delete > current cell > delete-cell\n    Edit > Delete > selected rows > delete-selected\n    Edit > Delete > selected cells > delete-cells\n    Edit > Copy > current cell > copy-cell\n    Edit > Copy > current row > copy-row\n    Edit > Copy > selected cells > copy-cells\n    Edit > Copy > selected rows > copy-selected\n    Edit > Copy > to system clipboard > current cell > syscopy-cell\n    Edit > Copy > to system clipboard > current row > syscopy-row\n    Edit > Copy > to system clipboard > selected cells > syscopy-cells\n    Edit > Copy > to system clipboard > selected rows > syscopy-selected\n    Edit > Cut > current row > cut-row\n    Edit > Cut > selected cells > cut-selected\n    Edit > Cut > current cell > cut-cell\n    Edit > Paste > row after > paste-after\n    Edit > Paste > row before > paste-before\n    Edit > Paste > into selected cells > setcol-clipboard\n    Edit > Paste > into current cell > paste-cell\n    Edit > Paste > from system clipboard > cells at cursor > syspaste-cells\n    Edit > Paste > from system clipboard > selected cells > syspaste-cells-selected\n''')\n", "path": "visidata/clipboard.py"}], "after_files": [{"content": "from copy import copy, deepcopy\nimport shutil\nimport subprocess\nimport io\nimport sys\nimport tempfile\nimport functools\nimport os\n\nfrom visidata import VisiData, vd, asyncthread\nfrom visidata import Sheet, Path\n\nif sys.platform == 'win32':\n    syscopy_cmd_default = 'clip.exe'\n    syspaste_cmd_default = 'powershell -command Get-Clipboard'\nelif sys.platform == 'darwin':\n    syscopy_cmd_default = 'pbcopy w'\n    syspaste_cmd_default = 'pbpaste'\nelse:\n    if 'WAYLAND_DISPLAY' in os.environ:\n        syscopy_cmd_default = 'wl-copy'\n        syspaste_cmd_default = 'wl-paste'\n    else:\n        syscopy_cmd_default = 'xclip -selection clipboard -filter'  # xsel --clipboard --input\n        syspaste_cmd_default = 'xclip -selection clipboard -o'  # xsel --clipboard\n\nvd.option('clipboard_copy_cmd', syscopy_cmd_default, 'command to copy stdin to system clipboard', sheettype=None)\nvd.option('clipboard_paste_cmd', syspaste_cmd_default, 'command to send contents of system clipboard to stdout', sheettype=None)\n\n\n@Sheet.api\ndef copyRows(sheet, rows):\n    vd.memory.cliprows = rows\n    vd.memory.clipcols = list(sheet.visibleCols)\n    if not rows:\n        vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)\n    else:\n        vd.status('copied %d %s to clipboard' % (len(rows), sheet.rowtype))\n\n@Sheet.api\ndef copyCells(sheet, col, rows):\n    vd.memory.clipcells = [col.getTypedValue(r) for r in rows]\n    if not rows:\n        vd.warning('no %s selected; clipboard emptied' % sheet.rowtype)\n        return\n    vd.status('copied %d %s.%s to clipboard' % (len(rows), sheet.rowtype, col.name))\n\n\n@Sheet.api\ndef syscopyValue(sheet, val):\n    # pipe val to stdin of clipboard command\n\n    p = subprocess.run(\n        sheet.options.clipboard_copy_cmd.split(),\n        input=val,\n        encoding=sheet.options.encoding,\n        stdout=subprocess.DEVNULL)\n\n    vd.status('copied value to system clipboard')\n\n\n@Sheet.api\ndef syscopyCells(sheet, cols, rows, filetype=None):\n    filetype = filetype or vd.input(\"copy %d %s as filetype: \" % (len(rows), sheet.rowtype), value=sheet.options.save_filetype or 'tsv')\n    sheet.syscopyCells_async(cols, rows, filetype)\n\n\n@Sheet.api\n@asyncthread\ndef syscopyCells_async(sheet, cols, rows, filetype):\n    vs = copy(sheet)\n    vs.rows = rows or vd.fail('no %s selected' % sheet.rowtype)\n    vs.columns = cols\n\n    vd.status(f'copying {vs.nRows} {vs.rowtype} to system clipboard as {filetype}')\n\n    with io.StringIO() as buf:\n        vd.sync(vd.saveSheets(Path(sheet.name+'.'+filetype, fptext=buf), vs))\n        subprocess.run(\n            sheet.options.clipboard_copy_cmd.split(),\n            input=buf.getvalue(),\n            encoding=sheet.options.encoding,\n            stdout=subprocess.DEVNULL)\n\n\n@VisiData.api\ndef sysclipValue(vd):\n    cmd = vd.options.clipboard_paste_cmd\n    return subprocess.check_output(vd.options.clipboard_paste_cmd.split()).decode('utf-8')\n\n\n@VisiData.api\n@asyncthread\ndef pasteFromClipboard(vd, cols, rows):\n    text = vd.getLastArgs() or vd.sysclipValue().strip() or vd.fail('system clipboard is empty')\n\n    vd.addUndoSetValues(cols, rows)\n    lines = text.split('\\n')\n    if not lines:\n        vd.warning('nothing to paste')\n        return\n\n    vs = cols[0].sheet\n    newrows = [vs.newRow() for i in range(len(lines)-len(rows))]\n    if newrows:\n        rows.extend(newrows)\n        vs.addRows(newrows)\n\n    for line, r in zip(lines, rows):\n        for v, c in zip(line.split('\\t'), cols):\n            c.setValue(r, v)\n\n\n@Sheet.api\ndef delete_row(sheet, rowidx):\n    if not sheet.defer:\n        oldrow = sheet.rows.pop(rowidx)\n        vd.addUndo(sheet.rows.insert, rowidx, oldrow)\n        # clear the deleted row from selected rows\n        if sheet.isSelected(oldrow):\n            sheet.addUndoSelection()\n            sheet.unselectRow(oldrow)\n    else:\n        oldrow = sheet.rows[rowidx]\n        sheet.rowDeleted(oldrow)\n\n    sheet.setModified()\n    return oldrow\n\n@Sheet.api\ndef paste_after(sheet, rowidx):\n    if not vd.memory.cliprows:  #1793\n        vd.warning('nothing to paste')\n        return\n    to_paste = list(deepcopy(r) for r in reversed(vd.memory.cliprows))\n    sheet.addRows(to_paste, index=rowidx)\n\n\n\nSheet.addCommand('y', 'copy-row', 'copyRows([cursorRow])', 'yank (copy) current row to clipboard')\n\nSheet.addCommand('p', 'paste-after', 'paste_after(cursorRowIndex)', 'paste clipboard rows after current row')\nSheet.addCommand('P', 'paste-before', 'paste_after(cursorRowIndex-1)', 'paste clipboard rows before current row')\n\nSheet.addCommand('gy', 'copy-selected', 'copyRows(onlySelectedRows)', 'yank (copy) selected rows to clipboard')\n\nSheet.addCommand('zy', 'copy-cell', 'copyCells(cursorCol, [cursorRow]); vd.memo(\"clipval\", cursorCol, cursorRow)', 'yank (copy) current cell to clipboard')\nSheet.addCommand('zp', 'paste-cell', 'cursorCol.setValuesTyped([cursorRow], vd.memory.clipval)', 'set contents of current cell to last clipboard value')\n\nSheet.addCommand('d', 'delete-row', 'delete_row(cursorRowIndex); defer and cursorDown(1)', 'delete current row')\nSheet.addCommand('gd', 'delete-selected', 'deleteSelected()', 'delete selected rows')\nSheet.addCommand('zd', 'delete-cell', 'cursorCol.setValues([cursorRow], options.null_value)', 'delete current cell (set to None)')\nSheet.addCommand('gzd', 'delete-cells', 'cursorCol.setValues(onlySelectedRows, options.null_value)', 'delete contents of current column for selected rows (set to None)')\n\nSheet.bindkey('BUTTON2_PRESSED', 'go-mouse')\nSheet.addCommand('BUTTON2_RELEASED', 'syspaste-cells', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], rows[cursorRowIndex:])', 'paste from system clipboard to region starting at cursor')\nSheet.bindkey('BUTTON2_CLICKED', 'go-mouse')\nSheet.bindkey('zP', 'syspaste-cells')\nSheet.addCommand('gzP', 'syspaste-cells-selected', 'pasteFromClipboard(visibleCols[cursorVisibleColIndex:], someSelectedRows)', 'paste from system clipboard to selected cells')\n\nSheet.addCommand('gzy', 'copy-cells', 'copyCells(cursorCol, onlySelectedRows)', 'yank (copy) contents of current column for selected rows to clipboard')\nSheet.addCommand('gzp', 'setcol-clipboard', 'for r, v in zip(onlySelectedRows, itertools.cycle(vd.memory.clipcells or [None])): cursorCol.setValuesTyped([r], v)', 'set cells of current column for selected rows to last clipboard value')\n\nSheet.addCommand('Y', 'syscopy-row', 'syscopyCells(visibleCols, [cursorRow])', 'yank (copy) current row to system clipboard (using options.clipboard_copy_cmd)')\n\nSheet.addCommand('gY', 'syscopy-selected', 'syscopyCells(visibleCols, onlySelectedRows)', 'yank (copy) selected rows to system clipboard (using options.clipboard_copy_cmd)')\nSheet.addCommand('zY', 'syscopy-cell', 'syscopyValue(cursorDisplay)', 'yank (copy) current cell to system clipboard (using options.clipboard_copy_cmd)')\nSheet.addCommand('gzY', 'syscopy-cells', 'syscopyCells([cursorCol], onlySelectedRows, filetype=\"txt\")', 'yank (copy) contents of current column from selected rows to system clipboard (using options.clipboard_copy_cmd')\n\nSheet.addCommand('x', 'cut-row', 'copyRows([sheet.delete_row(cursorRowIndex)]); defer and cursorDown(1)', 'delete (cut) current row and move it to clipboard')\nSheet.addCommand('gx', 'cut-selected', 'copyRows(onlySelectedRows); deleteSelected()', 'delete (cut) selected rows and move them to clipboard')\nSheet.addCommand('zx', 'cut-cell', 'copyCells(cursorCol, [cursorRow]); cursorCol.setValues([cursorRow], None)', 'delete (cut) current cell and move it to clipboard')\nSheet.addCommand('gzx', 'cut-cells', 'copyCells(cursorCol, onlySelectedRows); cursorCol.setValues(onlySelectedRows, None)', 'delete (cut) contents of current column for selected rows and move them to clipboard')\n\n\nSheet.bindkey('KEY_DC', 'delete-cell'),\nSheet.bindkey('gKEY_DC', 'delete-cells'),\n\nvd.addMenuItems('''\n    Edit > Delete > current row > delete-row\n    Edit > Delete > current cell > delete-cell\n    Edit > Delete > selected rows > delete-selected\n    Edit > Delete > selected cells > delete-cells\n    Edit > Copy > current cell > copy-cell\n    Edit > Copy > current row > copy-row\n    Edit > Copy > selected cells > copy-cells\n    Edit > Copy > selected rows > copy-selected\n    Edit > Copy > to system clipboard > current cell > syscopy-cell\n    Edit > Copy > to system clipboard > current row > syscopy-row\n    Edit > Copy > to system clipboard > selected cells > syscopy-cells\n    Edit > Copy > to system clipboard > selected rows > syscopy-selected\n    Edit > Cut > current row > cut-row\n    Edit > Cut > selected cells > cut-selected\n    Edit > Cut > current cell > cut-cell\n    Edit > Paste > row after > paste-after\n    Edit > Paste > row before > paste-before\n    Edit > Paste > into selected cells > setcol-clipboard\n    Edit > Paste > into current cell > paste-cell\n    Edit > Paste > from system clipboard > cells at cursor > syspaste-cells\n    Edit > Paste > from system clipboard > selected cells > syspaste-cells-selected\n''')\n", "path": "visidata/clipboard.py"}]}