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
59 changes: 32 additions & 27 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type PromptRef = {
reset(): void
blur(): void
focus(): void
submit(): void
}

export function Prompt(props: PromptProps) {
Expand Down Expand Up @@ -357,33 +358,6 @@ export function Prompt(props: PromptProps) {
)
}

props.ref?.({
get focused() {
return input.focused
},
focus() {
input.focus()
},
blur() {
input.blur()
},
set(prompt) {
input.setText(prompt.input, { history: false })
setStore("prompt", prompt)
restoreExtmarksFromParts(prompt.parts)
input.gotoBufferEnd()
},
reset() {
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
},
})

async function submit() {
if (props.disabled) return
if (autocomplete.visible) return
Expand Down Expand Up @@ -495,6 +469,37 @@ export function Prompt(props: PromptProps) {
}, 50)
input.clear()
}

props.ref?.({
get focused() {
return input.focused
},
focus() {
input.focus()
},
blur() {
input.blur()
},
set(prompt) {
input.setText(prompt.input, { history: false })
setStore("prompt", prompt)
restoreExtmarksFromParts(prompt.parts)
input.gotoBufferEnd()
},
reset() {
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
},
submit() {
submit()
},
})

const exit = useExit()

async function pasteImage(file: { filename?: string; content: string; mime: string }) {
Expand Down
4 changes: 4 additions & 0 deletions packages/opencode/src/cli/cmd/tui/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export function Home() {
if (once) return
if (args.prompt) {
prompt.set({ input: args.prompt, parts: [] })
// Auto-submit the prompt after a short delay to ensure it's properly set
setTimeout(() => {
prompt.submit()
}, 100)
once = true
}
})
Expand Down