How to use node-pty - 10 common examples

To help you get started, we’ve selected a few node-pty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mAAdhaTTah / brookjs / packages / brookjs-cli / features / support / world.ts View on Github external
code: null
    };

    // Remove constants that indicate it's in CI.
    // This is because Ink will only emit the last frame in CI.
    const {
      CI,
      CONTINUOUS_INTEGRATION,
      TRAVIS,
      BUILD_NUMBER,
      RUN_ID,
      TRAVIS_PULL_REQUEST,
      ...env
    } = process.env as any;

    const spawned = (this.spawned = spawn(bin, command.split(' '), {
      name: 'xterm-color',
      cols: 80,
      rows: 30,
      encoding: 'utf-8',
      cwd: this.cwd,
      env
    }));

    spawned.on('data', data => {
      this.output.stdout += data;
    });

    spawned.on('exit', code => {
      this.output.closed = true;
      this.output.code = code;
    });
github ioquatix / script-runner / lib / script-runner-process.js View on Github external
spawn(args, cwd, env) {
		// Spawn the child process:
		console.log("spawn", args[0], args.slice(1), cwd, env);
		
		env['TERM'] = 'xterm-256color';
		
		this.pty = PTY.spawn(args[0], args.slice(1), {
			cols: this.view.terminal.cols,
			rows: this.view.terminal.rows,
			cwd: cwd,
			env: env,
			name: 'xterm-color',
		});
		
		this.startTime = new Date;
		
		// Update the status (*Shellwords.join doesn't exist yet):
		//this.view.log(args.join(' ') + ' (pgid ' + this.pty.pid + ')');
		
		if (this.view.process) {
			this.view.process.destroy();
		}
github rse / blessed-xterm / blessed-xterm.js View on Github external
/*  termine old PTY  */
        if (this.pty)
            this.terminate()

        /*  establish environment  */
        env = Object.assign({},
            process.env,
            typeof this.options.env === "object" ? this.options.env : {},
            typeof env === "object" ? env : {}
        )
        if (   env.TERM === undefined
            || !(typeof env.TERM === "string" && env.TERM.match(/^xterm(?:-.+)?$/)))
            env.TERM = "xterm"

        /*  create new PTY  */
        this.pty = Pty.fork(shell, args, {
            name:  "xterm",
            cols:  this.width  - this.iwidth,
            rows:  this.height - this.iheight,
            cwd:   cwd || this.options.cwd || process.cwd(),
            env:   env
        })

        /*  process data on PTY  */
        this.pty.on("data", (data) => {
            this.write(data)
            if (data instanceof Buffer)
                data = data.toString()
            if (data.match(/\x07/))
                this.emit("beep")
        })
github IonicaBizau / web-term / lib / index.js View on Github external
constructor (options) {
        this.terminal = null;
        WebTerm.sockets.push(options.socket);

        // Default shell
        options.shell = deffy(options.shell, process.env.SHELL || "bash");

        if (options.ptyOptions && options.ptyOptions.env && options.inheritEnv !== false) {
            options.ptyOptions.env = ul.merge(options.ptyOptions.env, process.env);
        }

        // Create the terminal
        this.terminal = pty.fork(options.shell, [], ul.merge({
            cols: options.cols
          , rows: options.rows
          , cwd: options.cwd || ul.home()
        }, options.ptyOptions));

        // Terminal -> Socket
        this.terminal.on("data", data => options.socket.emit("data", data));

        // Close terminal
        this.terminal.on("close", () => {
            options.socket.emit("kill");
            this.kill();
        });

        // Handle the start app
        if (typeof options.start === "string") {
github xtermjs / xterm.js / src / Terminal.integration.ts View on Github external
}
  return result;
}

// Skip tests on Windows since pty.open isn't supported
if (os.platform() !== 'win32') {
  const CONSOLE_LOG = console.log;

  // expect files need terminal at 80x25!
  const COLS = 80;
  const ROWS = 25;

  /** some helpers for pty interaction */
  // we need a pty in between to get the termios decorations
  // for the basic test cases a raw pty device is enough
  primitivePty = pty.native.open(COLS, ROWS);

  /** tests */
  describe('xterm output comparison', () => {
    let xterm;

    beforeEach(() => {
      xterm = new Terminal({ cols: COLS, rows: ROWS });
      xterm.refresh = () => {};
      xterm.viewport = {
        syncScrollArea: () => {}
      };
    });

    // omit stack trace for escape sequence files
    Error.stackTraceLimit = 0;
    const files = glob.sync('**/escape_sequence_files/*.in', { cwd: path.join(__dirname, '..')});
github Raathigesh / majestic / app / src / renderer / util / Process.ts View on Github external
runtimeArgs.push(...restOfScriptParams);
  }
  // To use our own commands in create-react, we need to tell the command that
  // we're in a CI environment, or it will always append --watch
  const env = process.env;
  env.CI = "true";

  if (platform() === "darwin") {
    env.PATH = `${env.PATH}:/usr/local/bin`;
  }

  let stdoutCallback = (data: any) => {};
  let onExitCallback = () => {};
  let onCloseCallback = () => {};

  const ptyProcess = pty.spawn(command, runtimeArgs, {
    name: "xterm-color",
    cols: 80,
    rows: 30,
    cwd: workspace.rootPath,
    env
  });

  ptyProcess.on("data", data => {
    let output = data;
    if (data.includes("Test results written to")) {
      output = data.substring(data.indexOf("Test results written to"));
    }
    stdoutCallback(output);
  });

  ptyProcess.on("exit", () => {
github clems4ever / mesos-term / src / app.js View on Github external
app.post('/terminals/:task_id', isUserAllowedToDebug, function(req, res) {
  const task_id = req.params.task_id;
  if(!task_id) {
    res.send('You must provide a valid task id.');
    return;
  }

  const term = pty.spawn('python3',
    [MESOS_TASK_EXEC_DIR + '/exec.py', task_id], {
    name: 'mesos-task-exec',
    cwd: process.env.PWD,
    env: process.env
  });

  console.log('User "%s" has opened a session in container "%s" (pid=%s)', req.user.cn, task_id, term.pid);
  terminals[term.pid] = term;
  logs[term.pid] = '';
  ownersByPid[term.pid] = ownersByTaskId[task_id];
  term.on('data', function(data) {
    logs[term.pid] += data;
  });
  res.send(term.pid.toString());
  res.end();
});
github microsoft / vscode / src / vs / workbench / contrib / terminal / node / terminalProcess.ts View on Github external
private setupPtyProcess(shellLaunchConfig: IShellLaunchConfig, options: pty.IPtyForkOptions): void {
		const args = shellLaunchConfig.args || [];
		this._logService.trace('IPty#spawn', shellLaunchConfig.executable, args, options);
		const ptyProcess = pty.spawn(shellLaunchConfig.executable!, args, options);
		this._ptyProcess = ptyProcess;
		this._processStartupComplete = new Promise(c => {
			this.onProcessReady(() => c());
		});
		ptyProcess.on('data', data => {
			this._onProcessData.fire(data);
			if (this._closeTimeout) {
				clearTimeout(this._closeTimeout);
				this._queueProcessExit();
			}
		});
		ptyProcess.on('exit', code => {
			this._exitCode = code;
			this._queueProcessExit();
		});
		this._setupTitlePolling(ptyProcess);
github kaiakz / walv / lib / xterm / lib / Terminal.integration.js View on Github external
for (var line = term.buffer.ybase; line < term.buffer.ybase + term.rows; line++) {
        lineText = '';
        for (var cell = 0; cell < term.cols; ++cell) {
            lineText += term.buffer.lines.get(line).loadCell(cell, new BufferLine_1.CellData()).getChars() || BufferLine_1.WHITESPACE_CELL_CHAR;
        }
        lineText = lineText.replace(/\s+$/, '');
        result += lineText;
        result += '\n';
    }
    return result;
}
if (os.platform() !== 'win32') {
    var consoleLog_1 = console.log;
    var cols_1 = 80;
    var rows_1 = 25;
    primitivePty = pty.native.open(cols_1, rows_1);
    describe('xterm output comparison', function () {
        this.timeout(10000);
        var xterm;
        beforeEach(function () {
            xterm = new TestTerminal({ cols: cols_1, rows: rows_1 });
            xterm.refresh = function () { };
            xterm.viewport = {
                syncScrollArea: function () { }
            };
        });
        Error.stackTraceLimit = 0;
        var files = glob.sync('**/escape_sequence_files/*.in', { cwd: path.join(__dirname, '..') });
        var skip = [
            10, 16, 17, 19, 32, 33, 34, 35, 36, 39,
            40, 42, 43, 44, 45, 46, 47, 48, 49, 50,
            51, 52, 54, 55, 56, 57, 58, 59, 60, 61,
github esrlabs / chipmunk / application / sandbox / terminal / process / src / process.shell.ts View on Github external
constructor(options: IShellOptions) {
        super();
        this._process = pty.spawn(options.shell, [], {
            name: 'xterm-256color',
            cols: 9999,
            rows: 999,
            cwd: process.env.HOME,
            env: process.env as any
        });
        this._process.on('data', this._onStdout.bind(this));
        this._process.on('exit', this._onExit.bind(this));
    }

node-pty

Fork pseudoterminals in Node.JS

MIT
Latest version published 1 year ago

Package Health Score

75 / 100
Full package analysis