{"id":28191447,"url":"https://github.com/sursaone/bun-pty","last_synced_at":"2026-03-06T16:03:19.224Z","repository":{"id":293223352,"uuid":"983233881","full_name":"sursaone/bun-pty","owner":"sursaone","description":"Fork pseudoterminals in Bun","archived":false,"fork":false,"pushed_at":"2026-01-10T16:45:54.000Z","size":19978,"stargazers_count":35,"open_issues_count":0,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-01-11T04:57:30.470Z","etag":null,"topics":["bun","bun-pty","bunjs","node-pty","pty","terminal","terminal-emulators","types"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sursaone.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-14T04:49:38.000Z","updated_at":"2026-01-10T16:45:57.000Z","dependencies_parsed_at":"2025-07-01T05:14:24.965Z","dependency_job_id":null,"html_url":"https://github.com/sursaone/bun-pty","commit_stats":null,"previous_names":["sursaone/bun-pty"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/sursaone/bun-pty","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sursaone%2Fbun-pty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sursaone%2Fbun-pty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sursaone%2Fbun-pty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sursaone%2Fbun-pty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sursaone","download_url":"https://codeload.github.com/sursaone/bun-pty/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sursaone%2Fbun-pty/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30184885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T14:42:24.748Z","status":"ssl_error","status_checked_at":"2026-03-06T14:42:14.925Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","bun-pty","bunjs","node-pty","pty","terminal","terminal-emulators","types"],"created_at":"2025-05-16T11:10:02.864Z","updated_at":"2026-03-06T16:03:19.218Z","avatar_url":"https://github.com/sursaone.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bun-pty\n\n[![NPM Version](https://img.shields.io/npm/v/bun-pty.svg)](https://www.npmjs.com/package/bun-pty)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Bun Compatible](https://img.shields.io/badge/Bun-%E2%89%A51.0.0-black)](https://bun.sh)\n\nA cross-platform pseudo-terminal (PTY) implementation for Bun, powered by Rust's portable-pty library and Bun's FFI capabilities.\n\n## 🚀 Features\n\n- **Cross-platform** - Works on macOS, Linux, and Windows\n- **Simple API** - Clean Promise-based API similar to node-pty\n- **Type-safe** - Complete TypeScript definitions included\n- **Efficient** - Rust backend with proper error handling and multithreading\n- **Zero dependencies** - No external JavaScript dependencies required\n- **Modern** - Built specifically for Bun using its FFI capabilities\n\n## 📦 Installation\n\n```bash\nbun add bun-pty\n```\n\n## ⚙️ Requirements\n\n- **Bun** 1.0.0 or higher\n- **Rust** is only needed if you're building from source (the npm package includes pre-built binaries)\n\n## 📋 Platform Support\n\n| Platform | Status | Notes |\n|----------|--------|-------|\n| macOS    | ✅     | Fully supported |\n| Linux    | ✅     | Fully supported |\n| Windows  | ✅     | Fully supported |\n\n## 🚦 Usage\n\n### Basic Example\n\n```typescript\nimport { spawn } from \"bun-pty\";\n\n// Create a new terminal\nconst terminal = spawn(\"bash\", [], {\n  name: \"xterm-256color\",\n  cols: 80,\n  rows: 24\n});\n\n// Handle data from the terminal\nterminal.onData((data) =\u003e {\n  console.log(\"Received:\", data);\n});\n\n// Handle terminal exit\nterminal.onExit(({ exitCode, signal }) =\u003e {\n  console.log(`Process exited with code ${exitCode} and signal ${signal}`);\n});\n\n// Write to the terminal\nterminal.write(\"echo Hello from Bun PTY\\n\");\n\n// Resize the terminal\nterminal.resize(100, 40);\n\n// Kill the process when done\nsetTimeout(() =\u003e {\n  terminal.kill();\n}, 5000);\n```\n\n### TypeScript Usage\n\nThe library includes complete TypeScript definitions. Here's how to use it with full type safety:\n\n```typescript\nimport { spawn } from \"bun-pty\";\nimport type { IPty, IExitEvent, IPtyForkOptions } from \"bun-pty\";\n\n// Create typed options\nconst options: IPtyForkOptions = {\n  name: \"xterm-256color\",\n  cols: 100,\n  rows: 30,\n  cwd: process.cwd()\n};\n\n// Create a terminal with proper typing\nconst terminal: IPty = spawn(\"bash\", [], options);\n\n// Typed event handlers\nconst dataHandler = terminal.onData((data: string) =\u003e {\n  process.stdout.write(data);\n});\n\nconst exitHandler = terminal.onExit((event: IExitEvent) =\u003e {\n  console.log(`Process exited with code: ${event.exitCode}`);\n});\n\n// Clean up when done\ndataHandler.dispose();\nexitHandler.dispose();\n```\n\n### Interactive Shell Example\n\n```typescript\nimport { spawn } from \"bun-pty\";\nimport { createInterface } from \"node:readline\";\n\n// Create a PTY running bash\nconst pty = spawn(\"bash\", [], {\n  name: \"xterm-256color\",\n  cwd: process.cwd()\n});\n\n// Forward PTY output to stdout\npty.onData((data) =\u003e {\n  process.stdout.write(data);\n});\n\n// Send user input to the PTY\nprocess.stdin.on(\"data\", (data) =\u003e {\n  pty.write(data.toString());\n});\n\n// Handle PTY exit\npty.onExit(() =\u003e {\n  console.log(\"Terminal session ended\");\n  process.exit(0);\n});\n\n// Handle SIGINT (Ctrl+C)\nprocess.on(\"SIGINT\", () =\u003e {\n  pty.kill();\n});\n```\n\n## 📖 API Reference\n\n### `spawn(file: string, args: string[], options: IPtyForkOptions): IPty`\n\nCreates and spawns a new pseudoterminal.\n\n- `file`: The executable to launch\n- `args`: Arguments to pass to the executable\n- `options`: Configuration options\n  - `name`: Terminal name (e.g., \"xterm-256color\")\n  - `cols`: Number of columns (default: 80)\n  - `rows`: Number of rows (default: 24)\n  - `cwd`: Working directory (default: process.cwd())\n  - `env`: Environment variables\n\nReturns an `IPty` instance.\n\n### `IPty` Interface\n\n```typescript\ninterface IPty {\n  // Properties\n  readonly pid: number;        // Process ID\n  readonly cols: number;       // Current columns\n  readonly rows: number;       // Current rows\n  readonly process: string;    // Process name\n  \n  // Events\n  onData: (listener: (data: string) =\u003e void) =\u003e IDisposable;\n  onExit: (listener: (event: IExitEvent) =\u003e void) =\u003e IDisposable;\n  \n  // Methods\n  write(data: string): void;   // Write data to terminal\n  resize(cols: number, rows: number): void;  // Resize terminal\n  kill(signal?: string): void;  // Kill the process\n}\n```\n\n### Event Types\n\n```typescript\ninterface IExitEvent {\n  exitCode: number;\n  signal?: number | string;\n}\n\ninterface IDisposable {\n  dispose(): void;\n}\n```\n\n## 🧪 Testing\n\nbun-pty uses [Bun's built-in test runner](https://bun.com/docs/test) for fast, Jest-compatible testing.\n\n```bash\n# Run all tests\nbun test\n\n# Run unit tests only\nbun run test:unit\n\n# Run integration tests (requires Rust library)\nbun run test:integration\n\n# View test coverage\nbun run test:coverage\n```\n\n## 🔧 Building from Source\n\nIf you want to build the package from source:\n\n```bash\n# Clone the repository\ngit clone https://github.com/sursaone/bun-pty.git\ncd bun-pty\n\n# Install dependencies\nbun install\n\n# Build Rust library and TypeScript\nbun run build\n\n# Run tests\nbun test\n```\n\n## ❓ Troubleshooting\n\n### Prebuilt Binaries\n\nThe npm package includes prebuilt binaries for macOS, Linux, and Windows. If you encounter issues with the prebuilt binaries, you can build from source:\n\n```bash\n# In your project directory\nbun add bun-pty\ncd node_modules/bun-pty\nbun run build\n```\n\n### Common Issues\n\n- **Error: Unable to load shared library**: Make sure you have the necessary system libraries installed.\n- **Process spawn fails**: Check if you have the required permissions and paths.\n\n## 📚 Documentation\n\n- [CHANGELOG.md](./CHANGELOG.md) - Version history and changes\n\n## 📄 License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## 🙏 Credits\n\n- Built specifically for [Bun](https://bun.sh/)\n- Uses [portable-pty](https://github.com/wez/wezterm/tree/main/pty) from WezTerm for cross-platform PTY support\n- Inspired by [node-pty](https://github.com/microsoft/node-pty) for the API design\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsursaone%2Fbun-pty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsursaone%2Fbun-pty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsursaone%2Fbun-pty/lists"}