Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, t, dim, fg } from "@opentui/core"
import { BoxRenderable, TextareaRenderable, MouseEvent, MouseButton, PasteEvent, t, dim, fg } from "@opentui/core"
import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js"
import "opentui-spinner/solid"
import path from "path"
Expand Down Expand Up @@ -991,7 +991,15 @@ export function Prompt(props: PromptProps) {
input.cursorColor = theme.text
}, 0)
}}
onMouseDown={(r: MouseEvent) => r.target?.focus()}
onMouseDown={async (r: MouseEvent) => {
r.target?.focus()
if (r.button !== MouseButton.MIDDLE) return
if (props.disabled) return
r.preventDefault()
const text = await Clipboard.readPrimary()
if (!text || !input || input.isDestroyed) return
input.insertText(text)
}}
focusedBackgroundColor={theme.backgroundElement}
cursorColor={theme.text}
syntaxStyle={syntax()}
Expand Down
18 changes: 18 additions & 0 deletions packages/opencode/src/cli/cmd/tui/util/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ export namespace Clipboard {
}
}

export async function readPrimary(): Promise<string | undefined> {
const os = platform()
if (os === "linux") {
if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-paste")) {
const text = await $`wl-paste --primary --no-newline`.nothrow().text()
if (text) return text
}
if (Bun.which("xclip")) {
const text = await $`xclip -selection primary -o`.nothrow().text()
if (text) return text
}
if (Bun.which("xsel")) {
const text = await $`xsel --primary --output`.nothrow().text()
if (text) return text
}
}
}

const getCopyMethod = lazy(() => {
const os = platform()

Expand Down
Loading