Giter VIP home page Giter VIP logo

child_pty's Introduction

Build Status

child_pty

child_pty is a module for creating and interacting with pseudo terminals. It tries to be as minimal as possible and borrows most of its functionality from child_process.

child_pty was written as a replacement for pty.js.

API

It's mostly the same API child_process with the following differences:

  • Only child_pty.spawn() is supported

  • The options argument of child_pty.spawn() has the following changes:

    • new field: options.columns: columns of the instanciated PTY.
    • new field: options.rows: rows of the instanciated PTY.
    • options.detached and options.stdio are ignored.
  • ChildProcess in child_pty vs ChildProcess in child_process:

    • #stderr is not available. Use #stdout instead.

    • There's #stdout.resize(size) to resize the underlying PTY. The size attribute should have the following fields:

      • size.columns: columns of the instanciated PTY.
      • size.rows: rows of the instanciated PTY.
    • There's a #term object with the following properties:

      • #master_fd master file descriptor int
      • #slave_fd master file descriptor int
      • #ttyname`: name of the underlying TTY as reported by ttyname()(eg:/dev/ttys016``).
    • child processes won't get an EOF once you close stdin. You have to call ChildProcess#kill() explicitly.

Examples

This example opens a PTY with /bin/sh, resizes the terminal, executes ls -l, and exits the shell.

var child_pty = require('child_pty');
var child = child_pty.spawn('/bin/sh', []);
child.stdout.on('resize', function() {
	console.log('New columns: ' + this.columns);
	console.log('New rows:    ' + this.rows);
}).pipe(process.stdout);
child.stdout.resize({ columns: 80, rows: 48 });
child.stdin.write('ls -l\n');
child.stdin.write('exit\n');

Changelog

  • v0.1 - initial release
  • v0.2 - fix job control for shells
  • v0.3 - API changes to fit child_process
  • v0.4 - remove deprecated APIs
  • v0.5 - MacOS support

child_pty's People

Contributors

gottox avatar rauchg avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.