diff --git a/apps/server/src/terminal/ghosttyStyle.ts b/apps/server/src/terminal/ghosttyStyle.ts index 9299bbf398..d560875d06 100644 --- a/apps/server/src/terminal/ghosttyStyle.ts +++ b/apps/server/src/terminal/ghosttyStyle.ts @@ -217,11 +217,12 @@ export const loadGhosttyTerminalStyle: Effect.Effect< ]; const configSources: Array = []; for (const dir of configDirs) { - const source = yield* readFirstExisting([ - path.join(dir, "config"), - path.join(dir, "config.ghostty"), - ]); - if (source !== undefined) configSources.push(source); + // Read both file names when they coexist so a stale empty `config` does + // not shadow a populated `config.ghostty` alongside it. + for (const candidate of [path.join(dir, "config"), path.join(dir, "config.ghostty")]) { + const source = yield* readFirstExisting([candidate]); + if (source !== undefined) configSources.push(source); + } } if (configSources.length === 0) return undefined; diff --git a/apps/web/src/components/ThreadTerminalDrawer.tsx b/apps/web/src/components/ThreadTerminalDrawer.tsx index 5495d5dc75..c711388352 100644 --- a/apps/web/src/components/ThreadTerminalDrawer.tsx +++ b/apps/web/src/components/ThreadTerminalDrawer.tsx @@ -85,7 +85,8 @@ function ensureGhosttyReady(): Promise { // ghostty-web registers built-in OSC8/URL link providers on open() whose activate() // calls window.open directly, bypassing the app's preview/editor flow. There is no -// public API to remove them, so clear the provider list before installing ours. +// public API to remove them, so clear the provider list before installing ours, +// which covers the same URL schemes and routes them through the app. function clearBuiltInLinkProviders(terminal: Terminal): void { const detector = (terminal as unknown as { linkDetector?: { providers?: unknown[] } }) .linkDetector; @@ -120,6 +121,22 @@ function writeTerminalBuffer(terminal: Terminal, buffer: string): void { } } +// ghostty-web snaps the viewport to the bottom on every write, unlike +// xterm.js which keeps a scrolled-back viewport anchored. Restore the anchor +// by advancing viewportY by however many lines the write pushed into +// scrollback (viewportY counts lines back from the bottom). +function writePreservingScrollback(terminal: Terminal, data: string): void { + const viewportY = terminal.getViewportY(); + if (viewportY <= 0) { + terminal.write(data); + return; + } + const scrollbackBefore = terminal.getScrollbackLength(); + terminal.write(data); + const scrollbackAdded = terminal.getScrollbackLength() - scrollbackBefore; + terminal.scrollToLine(Math.round(viewportY) + scrollbackAdded); +} + function fitTerminalSafely(fitAddon: FitAddon): boolean { try { fitAddon.fit(); @@ -768,7 +785,7 @@ export function TerminalViewport({ ); return; } - const fallbackToBrowser = () => { + const openExternally = () => { void localApi.shell.openExternal(match.text).catch((error: unknown) => { writeSystemMessage( latestTerminal, @@ -776,13 +793,19 @@ export function TerminalViewport({ ); }); }; + // Only http(s) renders in the preview panel; hand other + // schemes (mailto, ssh, tel, ...) straight to the OS. + if (!/^https?:\/\//i.test(match.text)) { + openExternally(); + return; + } void openTerminalLinkInPreview({ url: match.text, position: { x: event.clientX, y: event.clientY }, threadRef, openPreview, localApi, - fallbackToBrowser, + fallbackToBrowser: openExternally, }); return; } @@ -939,7 +962,7 @@ export function TerminalViewport({ // ghostty-web 0.4.0 crashes on zero-length writes (alloc(0) returns an // out-of-bounds pointer), so skip no-op updates such as status-only bumps. if (appended.length > 0) { - terminal.write(appended); + writePreservingScrollback(terminal, appended); } } else { writeTerminalBuffer(terminal, current.buffer); diff --git a/apps/web/src/terminal-links.test.ts b/apps/web/src/terminal-links.test.ts index 0f8e619624..4622329dda 100644 --- a/apps/web/src/terminal-links.test.ts +++ b/apps/web/src/terminal-links.test.ts @@ -37,6 +37,24 @@ describe("extractTerminalLinks", () => { ]); }); + it("finds non-http scheme urls", () => { + const line = "email mailto:dev@example.com or clone ssh://git@github.com/t3/t3code.git now"; + expect(extractTerminalLinks(line)).toEqual([ + { + kind: "url", + text: "mailto:dev@example.com", + start: 6, + end: 28, + }, + { + kind: "url", + text: "ssh://git@github.com/t3/t3code.git", + start: 38, + end: 72, + }, + ]); + }); + it("trims trailing punctuation from links", () => { const line = "(https://example.com/docs), ./src/main.ts:12."; expect(extractTerminalLinks(line)).toEqual([ diff --git a/apps/web/src/terminal-links.ts b/apps/web/src/terminal-links.ts index a4eeda4279..a048f25b86 100644 --- a/apps/web/src/terminal-links.ts +++ b/apps/web/src/terminal-links.ts @@ -36,7 +36,10 @@ export interface WrappedTerminalLinkLine { segments: ReadonlyArray; } -const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/g; +// Also matches the non-http schemes ghostty and other terminals linkify; +// authority-style schemes require // while opaque ones take a bare payload. +const URL_PATTERN = + /(?:https?|ftp|ssh|git|gemini|gopher):\/\/[^\s"'`<>]+|(?:mailto|tel|news|magnet):[^\s"'`<>:][^\s"'`<>]*/g; const FILE_PATH_PATTERN = /(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g; const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;