Visual Studio Code, rebuilt in Rust
Rust
docs(terminal): point the docs at the libghostty-vt backend
rokartur60e2b67f414f
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.ymlindex ac94fa88100..d9b34fb1157 100644--- a/.github/workflows/linux.yml+++ b/.github/workflows/linux.yml@@ -40,7 +40,7 @@ jobs:with:toolchain: stable- name: Zig 0.17.1- # Builds libghostty-vt (native/crates/ghostty_vt/build.rs).+ # Builds libghostty-vt (libghostty-vt-sys's build.rs).run: |curl -fsSL -o "$RUNNER_TEMP/zig.tar.xz" https://ziglang.org/download/0.17.1/zig-x86_64-linux-0.17.1.tar.xzecho "3581863e3cbcfd0fce0efc682ce7e9e93da96668a977791d356a26d2a7e9b17a $RUNNER_TEMP/zig.tar.xz" | sha256sum -c -diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 8d648a9c346..566ecfbc4c7 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -154,7 +154,7 @@ All user data is under `~/.vsrustium` (`--user-data-dir` changes it), in upstrea## Terminal, webviews, updates-- Terminal. `app/src/terminal.rs::TerminalInstance` is one terminal: a pty and a screen. The screen model is the `alacritty_terminal` crate in the role of xterm.js. Shell integration, links and history are in `app/src/terminal`. The view is `app/src/workbench/terminal_view.rs`.+- Terminal. `app/src/terminal.rs::TerminalInstance` is one terminal: a pty and a screen. The screen model is libghostty-vt in the role of xterm.js, behind `ghostty_vt::Term`. Shell integration, links and history are in `app/src/terminal`. The view is `app/src/workbench/terminal_view.rs`.- Webviews. `app/src/webview.rs` holds the host page protocol and the resource serving that all platforms share (`app/src/webview.rs::Resources`). The native view, a `Native` per OS, is `app/src/webview/macos.rs` (WKWebView), `app/src/webview/linux.rs` (WebKitGTK) or `app/src/webview/windows.rs` (WebView2). A webview is a native child view placed over the GPUI window. GPUI does not draw it.- Updates. `app/src/update.rs` follows upstream's update service against the port's own feed (`port/notes.md`, "Update feed"). `port/tools/update-check` tests the whole path.@@ -198,4 +198,4 @@ The tools in `port/tools` each start with a header that states their use. The ma## In flight-Work on other branches that this file does not describe yet: GPUI moves from the Wu fork (`native/vendor/wu`) to gpui-fast (ledger M26). The terminal backend moves from `alacritty_terminal` to libghostty-vt. Views get drag and drop between containers. Other sessions fix the Windows (M24) and Linux (M23) test suites.+Work on other branches that this file does not describe yet: GPUI moves from the Wu fork (`native/vendor/wu`) to gpui-fast (ledger M26). Views get drag and drop between containers. Other sessions fix the Windows (M24) and Linux (M23) test suites.diff --git a/port/notes.md b/port/notes.mdindex 1b4e8a4189e..8a6fcc3c5bf 100644--- a/port/notes.md+++ b/port/notes.md@@ -630,7 +630,7 @@ Scope (milestone 13): diagnostics, hover, completion, go to definition and peek,## Milestone 15: integrated terminal- Backend: libghostty-vt 1.0.2 (MIT, tag `vt-1.0.2`, Ghostty's C API VT library) is the VT parser and screen model in place of xterm.js, behind `native/crates/ghostty_vt`, a safe `Term` with no `unsafe` of its own on the libghostty-rs bindings (`libghostty-vt` and `libghostty-vt-sys`, MIT OR Apache-2.0, https://github.com/uzaaft/libghostty-rs); the PTY is the port's own node-pty (`terminal/pty.rs`: openpty, setsid, TIOCSCTTY, PWD set to the cwd as `unixTerminal.ts` does; ConPTY on Windows). Wu's `terminal` crate is GPL-3.0 and is not used. It replaced `alacritty_terminal` 0.25 for the parser's throughput and for a maintained VT core with a stable C ABI; `Term` keeps alacritty's shapes (`Line` relative to the active area's top, negative into the scrollback, `Point`, `Cell`, `Flags`, `TermMode`) so the call sites read the same.-- libghostty-rs is a git dependency on the port's fork, https://github.com/rokartur/libghostty-rs branch `vsrustium` (rev 10df3e18), one commit over uzaaft's d3a306c, not crates.io 0.2.2: 0.2.2's `libghostty-vt-sys` builds Ghostty a887df42, 2333 commits before `vt-1.0.2`, and d3a306c builds `vt-1.0.2` (573c4a21). The fork's commit touches only `libghostty-vt-sys/build.rs`: (1) VS16 patch: Ghostty 1.0.2 drops U+FE0F after an emoji modifier base (U+270C, U+1F44D) outside mode 2027, as uucode gives those `emoji_modifier_base` rather than `extended_pictographic`, while xterm.js keeps it, so copied text keeps it (`ghostty_vt` `a_variation_selector_stays_with_its_emoji`, `prompt_input` `emoji_input`); the build stops when the patched line in `Terminal.zig` is not there exactly once, and Ghostty main still has the bug; (2) an MSVC cross build from a non-Windows host (`port/tools/windows-build`) builds the `*-windows-gnu` archive, as Zig 0.17 cannot compile the bundled simdutf and highway against cargo-xwin's MSVC SDK (Microsoft's link.exe rejects that archive's COMDATs, LNK1143, lld-link takes it); (3) the static Windows archive links ntdll. Drop the fork when upstream takes these: (2) and (3) fit an upstream PR, (1) belongs in Ghostty. The pin is the rev in Cargo.lock plus the Ghostty commit in the sys crate's `build.rs`, which clones Ghostty by commit (SHA-1, where the old build checked the release tarballs' SHA-256) and builds it with Zig 0.17 (`-Dcpu=baseline`); `zig build` checks the dependencies against `build.zig.zon`'s hashes. `native/.cargo/config.toml` sets `LIBGHOSTTY_VT_SYS_OPTIMIZE=ReleaseFast`: the sys build picks Zig Debug whenever cargo's `DEBUG` is true, which the release profile's `debug = "limited"` makes it, and Debug's page integrity checks made a 32 MB `cat` take minutes. On a macOS host Ghostty's `Config.zig` replaces any `-Dtarget` with its generic macOS 13.0 target, so the library's objects say `minos 13.0` (with the old build too) while `package-app` writes `LSMinimumSystemVersion` 12.0. The paint path reads the viewport through the render state (`Term::viewport_rows`): libghostty-rs's examples (`example/ghostling_rs`, `example/rust-vt-render`) read each cell's style through `CellIteration::style`, while `viewport_rows` reads a row's raw cells in one call and looks a style up once per style id in the row. macOS arm64 and Linux arm64/x64 build their own target; Windows builds `*-windows-msvc` from source on Windows (windows.yml). Zig is in the Linux image, linux.yml and windows.yml.+- libghostty-rs is a git dependency on the port's fork, https://github.com/rokartur/libghostty-rs branch `vsrustium` (rev 10df3e18), one commit over uzaaft's d3a306c, not crates.io 0.2.2: 0.2.2's `libghostty-vt-sys` builds Ghostty a887df42, 2333 commits before `vt-1.0.2`, and d3a306c builds `vt-1.0.2` (573c4a21). The fork's commit touches only `libghostty-vt-sys/build.rs`: (1) VS16 patch: Ghostty 1.0.2 drops U+FE0F after an emoji modifier base (U+270C, U+1F44D) outside mode 2027, as uucode gives those `emoji_modifier_base` rather than `extended_pictographic`, while xterm.js keeps it, so copied text keeps it (`ghostty_vt` `a_variation_selector_stays_with_its_emoji`, `prompt_input` `emoji_input`); the build stops when the patched line in `Terminal.zig` is not there exactly once, and Ghostty main still has the bug; (2) an MSVC cross build from a non-Windows host (`port/tools/windows-build`) builds the `*-windows-gnu` archive, as Zig 0.17 cannot compile the bundled simdutf and highway against cargo-xwin's MSVC SDK (Microsoft's link.exe rejects that archive's COMDATs, LNK1143, lld-link takes it); (3) the static Windows archive links ntdll. Drop the fork when upstream takes these: (2) and (3) fit an upstream PR, (1) belongs in Ghostty. The pin is the rev in Cargo.lock plus the Ghostty commit in the sys crate's `build.rs`, which clones Ghostty by commit (SHA-1, where the old build checked the release tarballs' SHA-256) and builds it with Zig 0.17 (`-Dcpu=baseline`); `zig build` checks the dependencies against `build.zig.zon`'s hashes. `native/.cargo/config.toml` sets `LIBGHOSTTY_VT_SYS_OPTIMIZE=ReleaseFast`: the sys build picks Zig Debug whenever cargo's `DEBUG` is true, which the release profile's `debug = "limited"` makes it, and Debug's page integrity checks made a 32 MB `cat` take minutes. On a macOS host Ghostty's `Config.zig` replaces any `-Dtarget` with its generic macOS 13.0 target, so the library's objects say `minos 13.0` (with the old build too) while `package-app` writes `LSMinimumSystemVersion` 12.0. The paint path reads the viewport through the render state (`Term::viewport_rows`): libghostty-rs's examples (`example/ghostling_rs`, `example/rust-vt-render`) read each cell's style through `CellIteration::style`, while `viewport_rows` reads a row's raw cells in one call and looks a style up once per style id in the row. macOS arm64 and Linux arm64/x64 build their own target; Windows builds `*-windows-msvc` from source on Windows (windows.yml). Zig is in the Linux image, linux.yml and `.github/actions/setup`.- What the port takes from libghostty-vt and what it keeps: the grid, scrollback, modes, cursor style, OSC 4/10/11/12 colors, title, bell, DA1/DA2/XTVERSION replies (set to xterm.js 6.1.0-beta.337's: `?1;2c`, `>0;276;0c`) come from libghostty-vt's callbacks; OSC 52, OSC 633/133/1337/7 stay with `terminal/shell_integration.rs` (it splits the stream before the parser), OSC 99 with `terminal/osc99.rs`, keys and mouse reports with `terminal/keys.rs` and `terminal/mouse.rs` (xterm.js's encodings, not libghostty-vt's key encoder). Selection follows alacritty 0.25's rules (`ghostty_vt/src/selection.rs`: simple, semantic, lines, block) with its anchors as libghostty-vt tracked references, so a selection moves with scrolled output as xterm.js's does. libghostty-rs's `selection::Gesture` is not used: it is Ghostty's click and drag model (its click counts, word boundaries and text formatting), while the port's selection tests pin xterm.js-shaped results.- Terminal throughput and typing (Mac Studio, release): `cat` of 32 MB of colored `ls -l` lines into a 120x40 terminal with 10000 lines of scrollback, 143 MB/s with alacritty_terminal, 700 MB/s with libghostty-vt; reading the 4800 visible cells after one echoed key, p95 8 us with alacritty, 120 us with libghostty-vt (each cell is a grid reference call); a key echoed and the workbench drawn (`terminal_typing_frame_time`), p95 4.0 to 4.4 ms before and 4.0 to 5.1 ms after, against the 16 ms gate. Moving to libghostty-rs, same Studio under load, one run each after a warm build: the in-process `Term::advance` of the same 32 MB, 484 MB/s on the port's own bindings and 487 MB/s on libghostty-rs; the 4800 visible cells, median 119 us (p95 128) cell by cell on the port's bindings, 291 us (p95 294) cell by cell on libghostty-rs, which `viewport_rows` brings to 122 us (p95 125); `terminal_typing_frame_time` p95 5.16 ms before and 4.40 ms after.- Keys follow xterm.js `Keyboard.ts` (`terminal/keys.rs`), mouse reports `CoreMouseService` DEFAULT and SGR (`terminal/mouse.rs`). `terminal/skip_shell.rs` is `DEFAULT_COMMANDS_TO_SKIP_SHELL` plus the terminalContrib lists of 1.147.0: a keybinding to one of them runs instead of reaching the shell.diff --git a/port/tools/linux/Dockerfile b/port/tools/linux/Dockerfileindex c15433ac4fb..3543b2bbe68 100644--- a/port/tools/linux/Dockerfile+++ b/port/tools/linux/Dockerfile@@ -31,7 +31,7 @@ RUN arch=$(uname -m) \&& tar xzf /tmp/cargo-gc.tgz -C /usr/local/cargo/bin ./cargo-gc \&& rm /tmp/cargo-gc.tgz-# Zig builds libghostty-vt (native/crates/ghostty_vt/build.rs).+# Zig builds libghostty-vt (libghostty-vt-sys's build.rs).RUN arch=$(uname -m) \&& case $arch in \aarch64) sum=a1546d5646eb184437918d6635ca6b762a0e889eac09cef720ee7a1ed3fe7795 ;; \