← 全部工具

microsoft/node-pty

热度 60 更新于 开发与构建

Fork pseudoterminals in Node.JS

githubauto-collected

安装

暂未验证可直接使用的安装命令,请查看项目官方文档或 Release。

node-pty

forkpty(3) bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.

This is useful for:

  • Writing a terminal emulator (eg. via xterm.js).
  • Getting certain programs to think you're a terminal, such as when you need a program to send you control sequences.

node-pty supports Linux, macOS and Windows. Windows support is possible by utilizing the Windows conpty API on Windows 1809+.

Note: Support for the winpty library has been removed. Windows 10 version 1809 (build 18309) or later is now required.

API

The full API for node-pty is contained within the TypeScript declaration file, use the branch/tag picker in GitHub (w) to navigate to the correct version of the API.

Example Usage

import * as os from 'node:os';
import * as pty from 'node-pty';

const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

const ptyProcess = pty.spawn(shell, [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: process.env
});

ptyProcess.onData((data) = { process.stdout.write(data); });

ptyProcess.write('ls\r'); ptyProcess.resize(100, 40); ptyProcess.write('ls\r');


## Real-world Uses

`node-pty` powers many different terminal emulators, including:

- [Microsoft Visual Studio Code](https://code.visualstudio.com)
- [Hyper](https://hyper.is/)
- [Upterm](https://github.com/railsware/upterm)
- [Script Runner](https://github.com/ioquatix/script-runner) for Atom.
- [Theia](https://github.com/theia-ide/theia)
- [FreeMAN](https://github.com/matthew-matvei/freeman) file manager
- [terminus](https://atom.io/packages/terminus) - An Atom plugin for providing terminals inside your Atom workspace.
  • Termination - Also an Atom plugin that provides terminals inside your Atom workspace.
  • atom-xterm - Also an Atom plugin that provides terminals inside your Atom workspace.
  • electerm Terminal/SSH/SFTP client(Linux, macOS, Windows).
  • Extraterm
  • Wetty Browser based Terminal over HTTP and HTTPS
  • nomad
  • DockerStacks Local LAMP/LEMP stack using Docker
  • TeleType: cli tool that allows you to share your terminal online conveniently. Show off mad cli-fu, help a colleague, teach, or troubleshoot.
  • mesos-term: A web terminal for Apache Mesos. It allows to execute commands within containers.
  • Commas: A hackable terminal and command runner.
  • ENiGMA½ BBS Software: A modern BBS software with a nostalgic flair!
  • Tinkerun: A new way of running Tinker.
  • Tess: Hackable, simple and rapid terminal for the new era of technology 👍
  • NxShell: An easy to use new terminal for Windows/Linux/MacOS platform.
  • OpenSumi: A framework helps you quickly build Cloud or Desktop IDE products.
  • Enjoy Git: A modern Git client featuring an intuitive user interface, built with Electron, Vue 3, and TypeScript.
  • Logos: A Modern, Lightweight Code Editor, built with Electron, Vue 3, and TypeScript.

Do you use node-pty in your application as well? Please open a Pull Request to include it here. We would love to have it in our list.

Building