Skip to content

Commit aa612b2

Browse files
authored
feat(tui): add 'c' shortcut to copy device code in OAuth flow (#7020)
1 parent a35c278 commit aa612b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/opencode/src/cli/cmd/tui/component/dialog-provider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { useTheme } from "../context/theme"
1010
import { TextAttributes } from "@opentui/core"
1111
import type { ProviderAuthAuthorization } from "@opencode-ai/sdk/v2"
1212
import { DialogModel } from "./dialog-model"
13+
import { useKeyboard } from "@opentui/solid"
14+
import { Clipboard } from "@tui/util/clipboard"
15+
import { useToast } from "../ui/toast"
1316

1417
const PROVIDER_PRIORITY: Record<string, number> = {
1518
opencode: 0,
@@ -104,6 +107,17 @@ function AutoMethod(props: AutoMethodProps) {
104107
const sdk = useSDK()
105108
const dialog = useDialog()
106109
const sync = useSync()
110+
const toast = useToast()
111+
112+
useKeyboard((evt) => {
113+
if (evt.name === "c" && !evt.ctrl && !evt.meta) {
114+
const code =
115+
props.authorization.instructions.match(/[A-Z0-9]{4}-[A-Z0-9]{4}/)?.[0] ?? props.authorization.instructions
116+
Clipboard.copy(code)
117+
.then(() => toast.show({ message: "Copied to clipboard", variant: "info" }))
118+
.catch(toast.error)
119+
}
120+
})
107121

108122
onMount(async () => {
109123
const result = await sdk.client.provider.oauth.callback({
@@ -132,6 +146,9 @@ function AutoMethod(props: AutoMethodProps) {
132146
<text fg={theme.textMuted}>{props.authorization.instructions}</text>
133147
</box>
134148
<text fg={theme.textMuted}>Waiting for authorization...</text>
149+
<text fg={theme.text}>
150+
c <span style={{ fg: theme.textMuted }}>copy</span>
151+
</text>
135152
</box>
136153
)
137154
}

0 commit comments

Comments
 (0)