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

Cross platform clipboard support #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,6 +15,7 @@ _templates
_static



# gitignore / Node.gitignore #
##############################
lib-cov
Expand All @@ -35,6 +36,7 @@ build
.grunt
sample/__issue.js
package-lock.json
yarn.lock

node_modules

Expand Down
22 changes: 22 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "test.file",
"runtimeArgs": [
"--inspect-brk",
"--trace-warnings",
"${relativeFile}",
],
"port": 9229,
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
39 changes: 7 additions & 32 deletions lib/extClipboard.js
Expand Up @@ -29,7 +29,7 @@


const Promise = require( 'seventh' ) ;
const string = require( 'string-kit' ) ;
const clipboardy = require('clipboardy');

require( './patches.js' ) ;
const execAsync = require( 'child_process' ).execAsync ;
Expand All @@ -45,37 +45,12 @@ const XCLIP_SELECTION_ARG = {
} ;


exports.getClipboard = () => {
return new Promise.resolve(clipboardy.readSync())
}

if ( process.platform === 'linux' ) {
exports.getClipboard = async ( source ) => {
var arg = XCLIP_SELECTION_ARG[ source[ 0 ] ] || 'clipboard' ;
return await execFileAsync( 'xclip' , [ '-o' , '-selection' , arg ] ) ;
} ;

exports.setClipboard = async ( str , source ) => {
var promise = new Promise() ;
var arg = XCLIP_SELECTION_ARG[ source[ 0 ] ] || 'clipboard' ;
var xclip = spawn( 'xclip' , [ '-i' , '-selection' , arg ] ) ;

xclip.on( 'error' , error => {
//console.error( 'xclip error:' , error ) ;
promise.reject( error ) ;
} ) ;

xclip.on( 'exit' , code => {
//console.log( 'xclip exited with code:' , code ) ;
if ( code !== 0 ) { promise.reject( code ) ; }
else { promise.resolve() ; }
} ) ;

// Send the string to push to the clipboard
xclip.stdin.end( str ) ;
exports.setClipboard = (data) => {
return new Promise.resolve(clipboardy.writeSync(data))
}

return promise ;
} ;
}
else {
exports.getClipboard = () => Promise.reject( new Error( 'No clipboard manipulation program found' ) ) ;
exports.setClipboard = () => Promise.reject( new Error( 'No clipboard manipulation program found' ) ) ;
}

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@cronvel/get-pixels": "^3.4.0",
"chroma-js": "^2.1.0",
"clipboardy": "^2.3.0",
"lazyness": "^1.2.0",
"ndarray": "^1.0.19",
"nextgen-events": "^1.3.0",
Expand Down