Skip to content

Commit

Permalink
wrapper time
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Jun 7, 2024
1 parent f2255b0 commit 546eae7
Show file tree
Hide file tree
Showing 8 changed files with 1,794 additions and 239 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Running:

- `npm install`
- `npm run build` / `npm run build:debug`
- `npm run build`
- `npm run test`

The code mainly targets Node on Linux.
Expand Down
54 changes: 0 additions & 54 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,6 @@ export interface Size {
cols: number
rows: number
}
/**
* A very thin wrapper around PTYs and processes. The caller is responsible for calling `.close()`
* when all streams have been closed. We hold onto both ends of the PTY (controller and user) to
* prevent reads from erroring out with EIO.
*
* This is the recommended usage:
*
* ```
* const { Pty } = require('@replit/ruspty');
* const fs = require('fs');
*
* const pty = new Pty({
* command: 'sh',
* args: [],
* envs: ENV,
* dir: CWD,
* size: { rows: 24, cols: 80 },
* onExit: (...result) => {
* // TODO: Handle process exit.
* },
* });
*
* const read = new fs.createReadStream('', {
* fd: pty.fd(),
* autoClose: false,
* });
* const write = new fs.createWriteStream('', {
* fd: pty.fd(),
* autoClose: false,
* });
*
* read.on('data', (chunk) => {
* // TODO: Handle data.
* });
* read.on('error', (err) => {
* if (err.code && err.code.indexOf('EIO') !== -1) {
* // This is expected to happen when the process exits.
* return;
* }
* // TODO: Handle the error.
* });
* read.on('end', () => {
* // handle cleanup here
* pty.close();
* });
* write.on('error', (err) => {
* if (err.code && err.code.indexOf('EIO') !== -1) {
* // This is expected to happen when the process exits.
* return;
* }
* // TODO: Handle the error.
* });
* ```
*/
export class Pty {
/** The pid of the forked process. */
pid: number
Expand Down
Loading

0 comments on commit 546eae7

Please sign in to comment.