温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/Terminal
点击访问原文链接

Bun Terminal class | API Reference | Bun

Bun Terminal class | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/Bun/TerminalM[Symbol.asyncDispose]MclosePclosedCoconstructorPcontrolFlagsPinputFlagsPlocalFlagsPoutputFlagsMrefMresizeMsetRawModeMunrefMwrite

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/TerminalM[Symbol.asyncDispose]MclosePclosedCoconstructorPcontrolFlagsPinputFlagsPlocalFlagsPoutputFlagsMrefMresizeMsetRawModeMunrefMwrite

class

Terminalclass 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`
readonly closed: boolean

Whether the terminal is closed.

controlFlags: number

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.

inputFlags: number

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.

localFlags: number

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.

outputFlags: number

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.

[Symbol.asyncDispose](): Promisevoid>;

Async dispose for use with await using.

close(): void;

Close the terminal.

ref(): void;

Reference the terminal to keep the event loop alive.

resize(cols: number,rows: number): void;

Resize the terminal.

@param cols

New number of columns

@param rows

New number of rows

setRawMode(enabled: boolean): void;

Set raw mode on the terminal. In raw mode, input is passed directly without processing.

@param enabled

Whether to enable raw mode

unref(): void;

Unreference the terminal to allow the event loop to exit.

write(data: string | BufferSource): number;

Write data to the terminal.

@param data

The data to write (string or BufferSource)

@returns

The number of bytes written

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked 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.