Options for creating a pseudo-terminal (PTY).
Search the reference...
/
constructor
Number of columns for the terminal.
Callback invoked when data is received from the terminal.
Callback invoked when the terminal is ready to receive more data.
Callback invoked when the PTY stream closes (EOF or read error). Note: exitCode is a PTY lifecycle status (0=clean EOF, 1=error), NOT the subprocess exit code. Use Subprocess.exited or onExit callback for actual process exit information.
Terminal name (e.g., "xterm-256color").
Number of rows for the terminal.
A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.
await using terminal = new Bun.Terminal({
cols: 80,
rows: 24,
data(term, data) {
console.log("Received:", new TextDecoder().decode(data));
},
});
// Spawn a shell connected to the PTY
const proc = Bun.spawn(["bash"], { terminal });
// Write to the terminal
terminal.write("echo hello\n");
// Wait for process to exit
await proc.exited;
// Terminal is closed automatically by `await using`
Whether the terminal is closed.
Terminal control flags (c_cflag from termios). Controls hardware characteristics like CSIZE, PARENB, etc. Returns 0 if terminal is closed. Setting returns true on success, false on failure.
Terminal input flags (c_iflag from termios). Controls input processing behavior like ICRNL, IXON, etc. Returns 0 if terminal is closed. Setting returns true on success, false on failure.
Terminal local flags (c_lflag from termios). Controls local processing like ICANON, ECHO, ISIG, etc. Returns 0 if terminal is closed. Setting returns true on success, false on failure.
Terminal output flags (c_oflag from termios). Controls output processing behavior like OPOST, ONLCR, etc. Returns 0 if terminal is closed. Setting returns true on success, false on failure.
Async dispose for use with await using.
Close the terminal.
Reference the terminal to keep the event loop alive.
Resize the terminal.
New number of columns
New number of rows
Set raw mode on the terminal. In raw mode, input is passed directly without processing.
Whether to enable raw mode
Unreference the terminal to allow the event loop to exit.
Write data to the terminal.
The data to write (string or BufferSource)
The number of bytes written
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →Terminal.constructor constructor | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- API documentation for constructor bun.Terminal.constructor | Bun