Skip to content

Commit dd6f9e4

Browse files
shmuel hizmiclaude
andcommitted
Add paste support to wmux terminal
Listen for paste events on the renderer's keyInput and forward the pasted bytes to the PTY as base64 input. Paste is suppressed when prefix mode or search overlay is active. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ee59593 commit dd6f9e4

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/wmux-client-terminal/src/components/WmuxTerminal.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jsxImportSource @opentui/react */
22
import { useState, useEffect, useRef, useCallback, type ReactNode } from "react";
3-
import { useKeyboard, useTerminalDimensions } from "@opentui/react";
3+
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
44
import { fromBase64, toBase64 } from "../utils/base64";
55
import { getOrCreateBuffer, type StyledLine, type StyledSegment } from "../utils/ansi";
66
import { usePrefixContext } from "./FocusContext";
@@ -44,6 +44,7 @@ export const WmuxTerminal = (props: WmuxTerminalProps): ReactNode => {
4444
const { id, output, status } = props;
4545
const sendInput = props.onInput.mutate;
4646
const sendResize = props.onResize.mutate;
47+
const renderer = useRenderer();
4748
const { prefixRef, searchOpenRef, hasSelectionRef, activeTabId } = usePrefixContext();
4849

4950
const [lines, setLines] = useState<readonly StyledLine[]>([]);
@@ -71,6 +72,18 @@ export const WmuxTerminal = (props: WmuxTerminalProps): ReactNode => {
7172
}
7273
});
7374

75+
// Forward paste events to PTY
76+
useEffect(() => {
77+
const onPaste = (event: { readonly bytes: Uint8Array }) => {
78+
if (!isActiveTerminal) return;
79+
if (prefixRef.current || searchOpenRef.current) return;
80+
sendInput(toBase64(event.bytes));
81+
};
82+
const keyInput = renderer.keyInput as unknown as { on(e: string, fn: (event: { readonly bytes: Uint8Array }) => void): void; off(e: string, fn: (event: { readonly bytes: Uint8Array }) => void): void };
83+
keyInput.on("paste", onPaste);
84+
return () => { keyInput.off("paste", onPaste); };
85+
}, [renderer, isActiveTerminal, prefixRef, searchOpenRef, sendInput]);
86+
7487
const handleOutput = useCallback((b64: string) => {
7588
const bytes = fromBase64(b64);
7689
const text = new TextDecoder().decode(bytes);

0 commit comments

Comments
 (0)