Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): programs can copy to the clipboard from the terminal (OSC 52) #22470

ClosedSunkenInTime(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/22470/headopened View on GitHub

Showing 6 changed files with 169 additions and 0 deletions (loading 3).

x
0 of 6 viewed, 6 left
13 additions and 0 deletionsapps/web/src/components/ThreadTerminalDrawer.tsxModified
View file
@@ -142,6 +142,18 @@
terminal.write(`\r\n[terminal] ${message}\r\n`);
​
+function copyTerminalProgramText(text: string): void {
+ void writeTextToClipboard(text, "terminal output").catch((error: unknown) => {
+ toastManager.add(
+ stackedThreadToast({
+ type: "error",
+ title: "Failed to copy terminal output",
+ description: error instanceof Error ? error.message : "An error occurred.",
+ }),
+ );
+ });
+}
+​
export function writeTerminalOutputUpdate(
terminal: Pick<GhosttyTerminalSurface, "resetAndWrite" | "write">,
update: TerminalOutputUpdate,
@@ -649,6 +661,7 @@
beforeKey: (event) => handleBeforeKey(event),
onLinkActivate: (text, event) => handleLinkActivate(text, event),
canActivateLink: (text) => canActivateTerminalLink(text),
+ onClipboardWrite: copyTerminalProgramText,
// The surface listens from construction, so a right-click can land
// while `create` is still awaiting WASM — before the handler below it
// exists.