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

Example how to use it in an Electron app #55

Closed
stoffeastrom opened this issue Mar 20, 2017 · 9 comments
Closed

Example how to use it in an Electron app #55

stoffeastrom opened this issue Mar 20, 2017 · 9 comments
Labels
enhancement help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@stoffeastrom
Copy link

When I try to fork or spawn in an Electron app I get

Error: Could not call remote function 'fork'. Check that the function signature is correct. Underlying error: Path must be a string. Received [Function: callIntoRenderer]
@Tyriar
Copy link
Member

Tyriar commented Mar 20, 2017

Looks like you're passing in the wrong arguments somehow? I'd need to see the specific call.

On explaining how to use, I try to do this on the README by suggesting a project I also maintain xterm.js:

Writing a terminal emulator (eg. via xterm.js)

Which contains a usage example as a demo https://github.com/sourcelair/xterm.js, could probably also do something here to show how to make a simple Electron terminal app using node-pty and xterm.js.

@Tyriar Tyriar added enhancement help wanted Issues identified as good community contribution opportunities labels Mar 20, 2017
@stoffeastrom
Copy link
Author

This is what I'm trying

const pty = remote.require('node-pty');
pty.spawn('C:/Program Files/Git/bin/bash.exe', [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.cwd,
  env: process.env
});

I have it working with spawning a childProcess and bind it to xterm.js Terminal. However I can't get colors to work since It needs to masquerade as a pty/tty which led me to this project :)

@Tyriar
Copy link
Member

Tyriar commented Mar 21, 2017

You can check out exactly how I do it in VS Code here https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/terminal/electron-browser/terminalProcess.js

Note that terminalProcess.js is being launched as its own process in order to work around the following Electron bug electron/electron#38, terminalProcess.js is launched like this https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts#L38

Nothing looks particularly bad with your current setup, maybe something is going wrong in the way you're transferring the data between node-pty and xterm.js? I expect something like this:

xterm.on('data', (data) => {
  pty.write(data);
});
pty.on('data', function (data) {
  xterm.write(data);
});

@stoffeastrom
Copy link
Author

Cool, I will have a look!

@stoffeastrom
Copy link
Author

Holy moly! it just worked 🚀

@stoffeastrom
Copy link
Author

I saw that you used the form

import cp = require('child_process');

So I changed my so suddenly I got typescript help and I had ofc an error

process.cwd vs process.cwd() hence the error message.

Thank for this great library!

@Tyriar
Copy link
Member

Tyriar commented Mar 21, 2017

Great! 😄

@Tyriar Tyriar closed this as completed Mar 21, 2017
@Tyriar Tyriar reopened this Mar 21, 2017
Tyriar added a commit that referenced this issue Mar 24, 2017
@Tyriar
Copy link
Member

Tyriar commented Mar 24, 2017

@stoffeastrom while making an electron example I ran into exactly what you hit with process.cwd so I added an exception to give a better error 😛 4ad2860

@Tyriar
Copy link
Member

Tyriar commented Mar 24, 2017

@stoffeastrom thanks for the suggestion, added the example to https://github.com/Tyriar/node-pty/tree/master/examples/electron

@Tyriar Tyriar modified the milestones: 0.7.0, 0.6.4 Apr 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

2 participants