diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt.tsx index d8a656188..c531ea20e 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt.tsx @@ -14,7 +14,7 @@ import type { FilePart } from "@opencode-ai/sdk" import fuzzysort from "fuzzysort" import { useCommandDialog } from "./dialog-command" import { useKeybind } from "../context/keybind" -import clipboard from "clipboardy" +import { Clipboard } from "../../../../util/clipboard" export type PromptProps = { sessionID?: string @@ -71,9 +71,11 @@ export function Prompt(props: PromptProps) { {})) ?? text - console.log(data) - this.insertText(data) + const content = await Clipboard.read() + console.log(content) + if (!content) { + this.insertText(text) + } }} onInput={(value) => { let diff = value.length - store.input.length diff --git a/packages/opencode/src/cli/cmd/tui/context/keybind.tsx b/packages/opencode/src/cli/cmd/tui/context/keybind.tsx index 736ceadda..2ce56ab14 100644 --- a/packages/opencode/src/cli/cmd/tui/context/keybind.tsx +++ b/packages/opencode/src/cli/cmd/tui/context/keybind.tsx @@ -90,7 +90,8 @@ export function init() { print(key: keyof KeybindsConfig) { const first = keybinds()[key]?.at(0) if (!first) return "" - return Keybind.toString(first) + const result = Keybind.toString(first) + return result.replace("", Keybind.toString(keybinds().leader![0]!)) }, } return result diff --git a/packages/opencode/src/cli/cmd/tui/home.tsx b/packages/opencode/src/cli/cmd/tui/home.tsx index c90cc599d..e43df4fd9 100644 --- a/packages/opencode/src/cli/cmd/tui/home.tsx +++ b/packages/opencode/src/cli/cmd/tui/home.tsx @@ -2,6 +2,7 @@ import { Installation } from "../../../installation" import { useTheme } from "./context/theme" import { TextAttributes } from "@opentui/core" import { Prompt } from "./component/prompt" +import { For } from "solid-js" export function Home() { const { currentTheme } = useTheme() @@ -46,23 +47,33 @@ function HelpRow(props: { children: string; slash: string; theme: any }) { ) } +const LOGO_LEFT = [ +` `, +`█▀▀█ █▀▀█ █▀▀█ █▀▀▄`, +`█░░█ █░░█ █▀▀▀ █░░█`, +`▀▀▀▀ █▀▀▀ ▀▀▀▀ ▀ ▀`, +] + +const LOGO_RIGHT = [ +` ▄ `, +`█▀▀▀ █▀▀█ █▀▀█ █▀▀█`, +`█░░░ █░░█ █░░█ █▀▀▀`, +`▀▀▀▀ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀`, +] + function Logo(props: { theme: any }) { return ( - - {"█▀▀█ █▀▀█ █▀▀ █▀▀▄"} - - {" █▀▀ █▀▀█ █▀▀▄ █▀▀"} - - - - {`█░░█ █░░█ █▀▀ █░░█`} - {` █░░ █░░█ █░░█ █▀▀`} - - - {`▀▀▀▀ █▀▀▀ ▀▀▀ ▀ ▀`} - {` ▀▀▀ ▀▀▀▀ ▀▀▀ ▀▀▀`} - + + {(line, index) => ( + + {line} + + {LOGO_RIGHT[index()]} + + + )} + {Installation.VERSION} diff --git a/packages/opencode/src/cli/cmd/tui/util/format.ts b/packages/opencode/src/cli/cmd/tui/util/format.ts index e69de29bb..cf3ae42a9 100644 --- a/packages/opencode/src/cli/cmd/tui/util/format.ts +++ b/packages/opencode/src/cli/cmd/tui/util/format.ts @@ -0,0 +1,3 @@ +export namespace Clipboard { + export function copy() {} +} diff --git a/packages/opencode/src/util/clipboard.ts b/packages/opencode/src/util/clipboard.ts new file mode 100644 index 000000000..c8a8e0cf5 --- /dev/null +++ b/packages/opencode/src/util/clipboard.ts @@ -0,0 +1,49 @@ +import { $ } from "bun" +import { platform } from "os" +import clipboardy from "clipboardy" + +export namespace Clipboard { + export interface Content { + data: string + mime: string + } + + export async function read(): Promise { + const os = platform() + + if (os === "darwin") { + const imageBuffer = await $`osascript -e 'try' -e 'the clipboard as «class PNGf»' -e 'end try'`.nothrow().text() + if (imageBuffer) { + return { data: Buffer.from(imageBuffer).toString("base64url"), mime: "image/png" } + } + } + + if (os === "linux") { + const wayland = await $`wl-paste -t image/png`.nothrow().text() + if (wayland) { + return { data: Buffer.from(wayland).toString("base64url"), mime: "image/png" } + } + const x11 = await $`xclip -selection clipboard -t image/png -o`.nothrow().text() + if (x11) { + return { data: Buffer.from(x11).toString("base64url"), mime: "image/png" } + } + } + + if (os === "win32") { + const script = + "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }" + const base64 = await $`powershell -command "${script}"`.nothrow().text() + if (base64) { + const imageBuffer = Buffer.from(base64.trim(), "base64") + if (imageBuffer.length > 0) { + return { data: imageBuffer.toString("base64url"), mime: "image/png" } + } + } + } + + const text = await clipboardy.read().catch(() => {}) + if (text) { + return { data: text, mime: "text/plain" } + } + } +} diff --git a/packages/opencode/src/util/keybind.ts b/packages/opencode/src/util/keybind.ts index 471b1d9f5..ffdf8ad2f 100644 --- a/packages/opencode/src/util/keybind.ts +++ b/packages/opencode/src/util/keybind.ts @@ -24,7 +24,7 @@ export namespace Keybind { let result = parts.join("+") if (info.leader) { - result = `${result}` + result = `,${result}` } return result