Skip to content

Commit 9b20581

Browse files
committed
fix(tui): update clipboard and paste handling for opentui 0.1.88
1 parent e228fd7 commit 9b20581

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { BoxRenderable, TextareaRenderable, MouseEvent, MouseButton, PasteEvent, t, dim, fg } from "@opentui/core"
1+
import {
2+
BoxRenderable,
3+
TextareaRenderable,
4+
MouseEvent,
5+
MouseButton,
6+
PasteEvent,
7+
decodePasteBytes,
8+
t,
9+
dim,
10+
fg,
11+
} from "@opentui/core"
212
import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js"
313
import "opentui-spinner/solid"
414
import path from "path"
@@ -936,7 +946,7 @@ export function Prompt(props: PromptProps) {
936946
// Normalize line endings at the boundary
937947
// Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste
938948
// Replace CRLF first, then any remaining CR
939-
const normalizedText = event.text.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
949+
const normalizedText = decodePasteBytes(event.bytes).replace(/\r\n/g, "\n").replace(/\r/g, "\n")
940950
const pastedContent = normalizedText.trim()
941951
if (!pastedContent) {
942952
command.trigger("prompt.paste")

packages/opencode/src/cli/cmd/tui/util/clipboard.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { $ } from "bun"
21
import { platform, release } from "os"
32
import clipboardy from "clipboardy"
43
import { lazy } from "../../../../util/lazy.js"
@@ -93,20 +92,18 @@ export namespace Clipboard {
9392
}
9493

9594
export async function readPrimary(): Promise<string | undefined> {
96-
const os = platform()
97-
if (os === "linux") {
98-
if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-paste")) {
99-
const text = await $`wl-paste --primary --no-newline`.nothrow().text()
100-
if (text) return text
101-
}
102-
if (Bun.which("xclip")) {
103-
const text = await $`xclip -selection primary -o`.nothrow().text()
104-
if (text) return text
105-
}
106-
if (Bun.which("xsel")) {
107-
const text = await $`xsel --primary --output`.nothrow().text()
108-
if (text) return text
109-
}
95+
if (platform() !== "linux") return
96+
if (process.env["WAYLAND_DISPLAY"] && which("wl-paste")) {
97+
const result = await Process.text(["wl-paste", "--primary", "--no-newline"], { nothrow: true })
98+
if (result.text) return result.text
99+
}
100+
if (which("xclip")) {
101+
const result = await Process.text(["xclip", "-selection", "primary", "-o"], { nothrow: true })
102+
if (result.text) return result.text
103+
}
104+
if (which("xsel")) {
105+
const result = await Process.text(["xsel", "--primary", "--output"], { nothrow: true })
106+
if (result.text) return result.text
110107
}
111108
}
112109

0 commit comments

Comments
 (0)