A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.
Search the reference...
/
class
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 →Bun Terminal class | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.