deno-clipboard
deno-clipboard copied to clipboard
Update; Add read parsing options
This PR resolves #3 and resolves #4.
Notes
It is technically a re-write (I wrote much of the code before discovering your repo, but found it when I encountered a Powershell issue). Instead of publishing a new Deno module, I have reviewed your code, and restructured the code in this PR to more closely align to the existing structure.
The PR focuses on addressing a few core issues:
- Updating the code to work with Deno's current API
- Adding read parsing options for newline control characters and trailing newlines
- Supporting both
xsel
andxclip
on Linux (in that order) - Adding support for Linux on WSL
An important note: the export format is changed, so the major version should be increased if published.
Previously, the methods could only be accessed on the clipboard
export:
import {clipboard} from 'https://deno.land/x/clipboard/mod.ts';
await clipboard.writeText('hello world');
await clipboard.readText();
Now, there is more flexibility for importing.
Like this:
import * as clipboard from 'https://deno.land/x/clipboard/mod.ts';
await clipboard.writeText('hello world');
await clipboard.readText();
Or like this:
import {readText, writeText} from 'https://deno.land/x/clipboard/mod.ts';
await writeText('hello world');
await readText();
Thanks for writing this module. Please review and let me know your thoughts. Cheers!
Doesn't work in wsl. It gives this error:
xsel: Can't open display: (null)
: Inappropriate ioctl for device
error: Uncaught Error: There was a problem writing to the clipboard
if (!success) throw new Error(errMsg.genericWrite);
@Nisgrak That means that your environment was not able to be detected as WSL.
Can you provide some information about your environment?
-
Is it WSL or WSL 2?
-
Which terminal are you using?
-
Which distribution have you installed from the Windows store?
-
Will you please copy and paste the output of the following three commands? They are currently what is being used to make the determination:
uname -r -v
which clip.exe
which powershell.exe
@jsejcksn
- WSL 2
- Fluent Terminal
- Ubuntu
@Nisgrak I’lll look into this more. Those executables with the .exe
extensions should be in your path. See https://docs.microsoft.com/en-us/windows/wsl/interop#run-windows-tools-from-linux
Have you modified your path or installed tools which might have modified your path?
uname -r -v which clip.exe which powershell.exe
@Nisgrak Will you try those commands using a first-party Microsoft terminal application like %windir%\system32\cmd.exe
or Windows Terminal?
I fix the problem with the .exe, windows didn't modify my PATH so I added the routes by hand.
I try again with the lib and now works! Looks like the problem was the routes in PATH...
Anyway, in cmd:
@Nisgrak That's great to hear. So everything is working now: the tests pass when you run deno test --allow-run
in the repo directory?
Yes! Pass the 8 test in WSL and Powershell like a charm 😄. Good job!
@rsp Thoughts?
Maybe you should add a warning or troubleshoot in the readme about that error, or some concrete error if in you kernel version contains "microsoft" and haven't access to .exes.
Maybe you should add a warning or troubleshoot in the readme about that error, or some concrete error if in you kernel version contains "microsoft" and haven't access to .exes.
@Nisgrak Added in https://github.com/rsp/deno-clipboard/pull/5/commits/4f7dfd2bac74a4cf2f2a69e2176b0e8bedb31231