deno-clipboard icon indicating copy to clipboard operation
deno-clipboard copied to clipboard

Update; Add read parsing options

Open jsejcksn opened this issue 4 years ago • 11 comments

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 and xclip 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!

jsejcksn avatar Jun 11 '20 18:06 jsejcksn

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 avatar Jun 28 '20 13:06 Nisgrak

@Nisgrak That means that your environment was not able to be detected as WSL.

Can you provide some information about your environment?

  1. Is it WSL or WSL 2?

  2. Which terminal are you using?

  3. Which distribution have you installed from the Windows store?

  4. 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 avatar Jun 28 '20 14:06 jsejcksn

@jsejcksn

  1. WSL 2
  2. Fluent Terminal
  3. Ubuntu

image

Nisgrak avatar Jun 28 '20 14:06 Nisgrak

@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?

jsejcksn avatar Jun 28 '20 14:06 jsejcksn

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?

jsejcksn avatar Jun 29 '20 04:06 jsejcksn

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: image

Nisgrak avatar Jun 29 '20 07:06 Nisgrak

@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?

jsejcksn avatar Jun 29 '20 07:06 jsejcksn

Yes! Pass the 8 test in WSL and Powershell like a charm 😄. Good job!

Nisgrak avatar Jun 29 '20 07:06 Nisgrak

@rsp Thoughts?

jsejcksn avatar Jun 29 '20 08:06 jsejcksn

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 avatar Jun 29 '20 13:06 Nisgrak

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

jsejcksn avatar Jun 29 '20 20:06 jsejcksn