# get-pty-output

> Execute an external command with a PTY, from Node

Latest version **0.8.2** (published 2022-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-pty-output
pnpm add get-pty-output
yarn add get-pty-output
bun add get-pty-output
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.2 |
| Published | 2022-01-02 |
| First published | 2021-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 10 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Maintainers | cyriac_br |
| Keywords | node, pty |

## Links

- npm: https://www.npmjs.com/package/get-pty-output
- Repository: https://github.com/CyriacBr/get-pty-output
- Homepage: https://github.com/CyriacBr/get-pty-output#readme
- Issues: https://github.com/CyriacBr/get-pty-output/issues
- npm.io page: https://npm.io/package/get-pty-output

## Dependencies (10)

- [@node-rs/helper](https://npm.io/package/@node-rs/helper.md) ^1.2.1
- [get-pty-output-darwin-x64](https://npm.io/package/get-pty-output-darwin-x64.md) 0.8.2
- [get-pty-output-freebsd-x64](https://npm.io/package/get-pty-output-freebsd-x64.md) 0.8.2
- [get-pty-output-darwin-arm64](https://npm.io/package/get-pty-output-darwin-arm64.md) 0.8.2
- [get-pty-output-linux-x64-gnu](https://npm.io/package/get-pty-output-linux-x64-gnu.md) 0.8.2
- [get-pty-output-linux-x64-musl](https://npm.io/package/get-pty-output-linux-x64-musl.md) 0.8.2
- [get-pty-output-win32-x64-msvc](https://npm.io/package/get-pty-output-win32-x64-msvc.md) 0.8.2
- [get-pty-output-linux-arm64-gnu](https://npm.io/package/get-pty-output-linux-arm64-gnu.md) 0.8.2
- [get-pty-output-linux-arm64-musl](https://npm.io/package/get-pty-output-linux-arm64-musl.md) 0.8.2
- [get-pty-output-linux-arm-gnueabihf](https://npm.io/package/get-pty-output-linux-arm-gnueabihf.md) 0.8.2

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.8.2 (latest) — 2022-01-02
- 0.8.1 — 2021-12-31
- 0.8.0 — 2021-12-31
- 0.7.0 — 2021-12-17
- 0.6.2 — 2021-12-13
- 0.6.1 — 2021-12-13
- 0.6.0 — 2021-12-13
- 0.5.0 — 2021-12-11

## README

# `get-pty-output`

![https://github.com/CyriacBr/get-pty-output/actions](https://github.com/CyriacBr/get-pty-output/workflows/CI/badge.svg)

> An alternative to `child_process.exec` with PTY support

Node doesn't natively support creating pseudo-terminals. When running an external command
with `child_process.spawn` or `exec`, ansi colors are lost because most of CLIs disable colors when they aren't run inside a TTY environment.
You can make your child inherit the parent `stdio`, thus allowing colors, but this results in the inability to properly capture outputs.

Some packages like `node-pty` aim to solve this problem, but they rely on `node-gyp`, and doesn't support newer Node versions.
This package leverage Rust's `portable-pty`(unix) and `conpty`(windows) crates with [n-api-rs](https://github.com/napi-rs/napi-rs) for bindings, allowing way better
cross-platform support and easier installation.

## Install

```
yarn add get-pty-output
```

## Usage

```ts
import { exec, execSync } from 'get-pty-output'

const res = await exec('node -e console.log(100)')
res.output // in color! ✨
```

### Options

```ts
exec(cmd, {
  cwd: 'path-to-desired-wd',
  /**
   * Close the pty after a timeout.
   */
  timeout: 10,
  /**
   * Close the pty after a timeout since the command became idle.
   * A command is considered idle when it has stopped writing on stdout.
   * Only works on UNIX platforms for now.
   */
  idleTimeout: 5,
  /**
   * Remove cursor transformations from the output.
   * Defaults to true. You may disable this if you notice your output is weirdly truncated.
   * If the command you're executing transforms the terminal cursor (spinners, progress bars, etc),
   * you likely want to keep this to true
   */
  purify: true
})
```
Output is truncated when a timeout happens. `res.truncated; // true`

## Publishing

- Remove all optional deps
- Bump version if needed
- Run `prepare-release`
- Push or manually start CI workflow
- Download CI artifacts and put them under ./npm in their respective directory
- Run `npm publish`

## Credits & Thanks

- [n-api-rs](https://github.com/napi-rs/napi-rs)
- [portable-pty](https://docs.rs/portable-pty/latest/portable_pty/)
- [conpty](https://github.com/zhiburt/conpty)

---
_Source: https://npm.io/package/get-pty-output · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
