Copy selections and links through OpenTUI's clipboard service
A drag over the conversation or the terminal pane copies on release, OSC 52 first and then the desktop clipboard, with a short Copied toast. The menu and PR copies go the same way, replacing copyText.
This commit is contained in:
1 parent
a9a4b47566
commit
aa865e24eb
6 files changed
+57
-38
No files matched your search
+5
-5
@@ -47,7 +47,7 @@ import { SettingsView } from "./SettingsView.tsx";
|
||||
import { useWorkspace } from "./useWorkspace.ts";
|
||||
import { usePullRequests } from "./usePullRequests.ts";
|
||||
import { rendererClipboard, type Clipboard } from "./clipboard.ts";
|
||||
import { copyText, desktopNotify, ring } from "./terminalOut.ts";
|
||||
import { desktopNotify, ring } from "./terminalOut.ts";
|
||||
import { colors, statusColor } from "./theme.ts";
|
||||
import { BAR, NO_BORDER } from "./edges.ts";
|
||||
import { ThreadList } from "./ThreadList.tsx";
|
||||
@@ -356,8 +356,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const copySelection = useEvent((selection: Selection) => {
|
||||
const text = selection.getSelectedText();
|
||||
if (!text.trim()) return;
|
||||
copyText(renderer, text);
|
||||
say(`Copied ${text.length === 1 ? "1 character" : `${text.length} characters`}`);
|
||||
void clipboard.copy(text).then((copied) => (copied ? say("Copied") : say("Could not reach the clipboard.", true)));
|
||||
});
|
||||
useEffect(() => {
|
||||
renderer.on("selection", copySelection);
|
||||
@@ -505,7 +504,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const runtimeMode = models.runtimeMode;
|
||||
const threadMenu = useThreadMenu({
|
||||
session,
|
||||
renderer,
|
||||
clipboard,
|
||||
snapshot: shell.snapshot,
|
||||
config: providerConfig,
|
||||
timestampFormat: config.timestampFormat,
|
||||
@@ -725,6 +724,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
const pullRequests = usePullRequests({
|
||||
session,
|
||||
renderer,
|
||||
clipboard,
|
||||
threadShell,
|
||||
project: draft ? draftProject : project,
|
||||
projects: shell.snapshot?.projects ?? [],
|
||||
@@ -1027,7 +1027,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
|
||||
openTurnDiff: useEvent((checkpointTurnCount: number) => turns.openTurnDiff(checkpointTurnCount)),
|
||||
};
|
||||
const copy = (label: string, text: string) => {
|
||||
copyText(renderer, text);
|
||||
void clipboard.copy(text);
|
||||
say(`Copied ${label}`);
|
||||
};
|
||||
/** Long output stays on the server until it's asked for. */
|
||||
|
||||
+1
-25
@@ -1,5 +1,4 @@
|
||||
/** Escape sequences t3tui writes past the renderer: the bell, desktop notifications, the clipboard. */
|
||||
import type { CliRenderer } from "@opentui/core";
|
||||
/** Escape sequences t3tui writes past the renderer: the bell and desktop notifications. */
|
||||
|
||||
/** Inside tmux, escape sequences other than the bell need passthrough to reach the outer terminal. */
|
||||
function passthrough(sequence: string): string {
|
||||
@@ -25,26 +24,3 @@ export function desktopNotify(title: string, body: string): void {
|
||||
: `\x1b]9;${clean(title)}: ${clean(body)}\x07`;
|
||||
process.stdout.write(passthrough(sequence));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies text: through the terminal (OSC 52, which also works over SSH), and on a local
|
||||
* desktop through its clipboard tool too, for terminals that ignore OSC 52.
|
||||
*/
|
||||
export function copyText(renderer: CliRenderer, text: string): void {
|
||||
try {
|
||||
renderer.copyToClipboardOSC52(text);
|
||||
} catch {
|
||||
// OpenTUI refuses when it isn't drawing (suspended, or a test renderer); the tool may still copy.
|
||||
}
|
||||
if (process.env.SSH_CONNECTION) return;
|
||||
const tool =
|
||||
process.platform === "darwin" ? ["pbcopy"] : process.env.WAYLAND_DISPLAY ? ["wl-copy"] : process.env.DISPLAY ? ["xclip", "-selection", "clipboard"] : null;
|
||||
if (!tool || !Bun.which(tool[0]!)) return;
|
||||
try {
|
||||
const child = Bun.spawn(tool, { stdin: "pipe", stdout: "ignore", stderr: "ignore" });
|
||||
child.stdin.write(text);
|
||||
void child.stdin.end();
|
||||
} catch {
|
||||
// OSC 52 already went out; the tool is a fallback.
|
||||
}
|
||||
}
|
||||
@@ -39,13 +39,14 @@ import {
|
||||
} from "../model/pullRequests.ts";
|
||||
import type { Confirmation } from "./ConfirmBar.tsx";
|
||||
import { editInEditor } from "./editor.ts";
|
||||
import { copyText } from "./terminalOut.ts";
|
||||
import type { Clipboard } from "./clipboard.ts";
|
||||
import { firstLine } from "./text.ts";
|
||||
import type { PullRequestViewState } from "./PullRequestView.tsx";
|
||||
|
||||
export interface PullRequestDeps {
|
||||
readonly session: T3Session;
|
||||
readonly renderer: CliRenderer;
|
||||
readonly clipboard: Clipboard;
|
||||
readonly threadShell: OrchestrationV2ThreadShell | undefined;
|
||||
readonly project: OrchestrationProjectShell | undefined;
|
||||
readonly projects: readonly OrchestrationProjectShell[];
|
||||
@@ -162,7 +163,7 @@ export function usePullRequests(deps: PullRequestDeps) {
|
||||
if (!url) return;
|
||||
// Over SSH or without a desktop there may be no browser to open: copy the link instead.
|
||||
const fallBack = (reason: string) => {
|
||||
copyText(deps.renderer, url);
|
||||
void deps.clipboard.copy(url);
|
||||
deps.say(`Could not open the browser (${reason}); link copied: ${url}`, true);
|
||||
};
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { CliRenderer } from "@opentui/core";
|
||||
import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
|
||||
import type { ContextMenuItem, OrchestrationV2ShellSnapshot, OrchestrationV2ThreadShell, ServerConfig, ThreadId } from "@t3tools/contracts";
|
||||
|
||||
@@ -8,14 +7,14 @@ import type { Binding } from "../model/keymap.ts";
|
||||
import type { Picker, PickerItem } from "../model/palette.ts";
|
||||
import { parseSnooze, pickSnooze, threadHasRuntime, threadMenu, topPinOrderKey, type ThreadActionMenuId } from "../model/threadMenu.ts";
|
||||
import type { Confirmation } from "./ConfirmBar.tsx";
|
||||
import { copyText } from "./terminalOut.ts";
|
||||
import type { Clipboard } from "./clipboard.ts";
|
||||
|
||||
type SnoozePresets = ReturnType<typeof threadMenu>["snoozePresets"];
|
||||
|
||||
/** The web sidebar's thread menu as a picker: separators become groups, submenus open their own picker. */
|
||||
export function useThreadMenu(deps: {
|
||||
readonly session: T3Session;
|
||||
readonly renderer: CliRenderer;
|
||||
readonly clipboard: Clipboard;
|
||||
readonly snapshot: OrchestrationV2ShellSnapshot | null;
|
||||
readonly config: ServerConfig | null;
|
||||
readonly timestampFormat: T3tuiConfig["timestampFormat"];
|
||||
@@ -34,10 +33,10 @@ export function useThreadMenu(deps: {
|
||||
readonly keepUnread: (id: ThreadId) => void;
|
||||
readonly startDraftOn: (target: OrchestrationV2ThreadShell) => void;
|
||||
}) {
|
||||
const { session, renderer, config, run, say } = deps;
|
||||
const { session, clipboard, config, run, say } = deps;
|
||||
|
||||
const copy = (text: string, message: string) => {
|
||||
copyText(renderer, text);
|
||||
void clipboard.copy(text);
|
||||
say(message);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user