跳到正文

Terminal

嵌入保留式 Ghostty 终端表面,并报告进程生命周期事件。

#导入

从 quickgui 导入 Terminal。

use quickgui::*;

#用法

let terminal = Terminal::spawn(
    TerminalOptions {
        program: Some("/bin/zsh".into()),
        arguments: vec!["-l".into()],
        working_directory: Some(directory.into()),
        ..TerminalOptions::default()
    },
    cx.window_invalidator(),
)?;
terminal.element(cx)

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

Terminal

查看源码
pub fn spawn( options: TerminalOptions, invalidator: WindowInvalidator, ) -> Result<Self, TerminalError>

Start a PTY and terminal-emulation worker. Process-launch failures are published through [`TerminalSnapshot::status`] so a declarative terminal remains mounted and informative.

snapshotpub fn snapshot(&self) -> Arc<TerminalSnapshot>—

Read the latest complete terminal frame without locking the emulator or PTY.

pub fn snapshot(&self) -> Arc<TerminalSnapshot>
查看源码
writepub fn write(&self, bytes: impl AsRef<[u8]>) -> bool—

Write raw bytes to the PTY. Prefer normal keyboard events or [`Self::paste`] for user input.

pub fn write(&self, bytes: impl AsRef<[u8]>) -> bool
查看源码
pastepub fn paste(&self, value: impl Into<String>) -> bool—

Encode text using libghostty's bracketed-paste and control-byte rules, then write it.

pub fn paste(&self, value: impl Into<String>) -> bool
查看源码
scroll_rowspub fn scroll_rows(&self, rows: isize) -> bool—

Scroll libghostty's retained viewport by terminal rows. Negative values move into history.

pub fn scroll_rows(&self, rows: isize) -> bool
查看源码
resizepub fn resize(&self, cols: u16, rows: u16, cell_width_px: u32, cell_height_px: u32) -> bool—

Resize both the PTY and libghostty viewport, coalescing identical measurements.

pub fn resize(&self, cols: u16, rows: u16, cell_width_px: u32, cell_height_px: u32) -> bool
查看源码

Terminal::element

查看源码
pub fn element<V: 'static>( &self, id: impl Into<ElementId>, style: TerminalStyle, cx: &mut ViewContext<'_, V>, ) -> Element

Build the complete retained terminal surface, including focus, keyboard, paste, scroll, and exact bounds-to-PTY resize behavior.