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
43 changes: 42 additions & 1 deletion packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function Prompt(props: PromptProps) {
let input: TextareaRenderable
let anchor: BoxRenderable
let autocomplete: AutocompleteRef
let clearTimer: ReturnType<typeof setTimeout> | undefined

const keybind = useKeybind()
const local = useLocal()
Expand Down Expand Up @@ -166,6 +167,7 @@ export function Prompt(props: PromptProps) {
mode: "normal" | "shell"
extmarkToPartIndex: Map<number, number>
interrupt: number
clearCount: number
placeholder: number
}>({
placeholder: randomIndex(list().length),
Expand All @@ -176,6 +178,7 @@ export function Prompt(props: PromptProps) {
mode: "normal",
extmarkToPartIndex: new Map(),
interrupt: 0,
clearCount: 0,
})

createEffect(
Expand Down Expand Up @@ -252,6 +255,31 @@ export function Prompt(props: PromptProps) {
})
}
},
},
{
title: "Clear input",
value: "prompt.clear_input",
keybind: "input_clear_prompt",
category: "Prompt",
hidden: true,
enabled: status().type === "idle" && !!store.prompt.input,
onSelect: () => {
if (!store.prompt.input) return
if (store.clearCount === 0) {
setStore("clearCount", 1)
clearTimer = setTimeout(() => {
setStore("clearCount", 0)
}, 2000)
return
}
clearTimeout(clearTimer)
clearTimer = undefined
input.clear()
input.extmarks.clear()
setStore("prompt", { input: "", parts: [] })
setStore("extmarkToPartIndex", new Map())
setStore("clearCount", 0)
},
},
{
title: "Interrupt session",
Expand Down Expand Up @@ -431,6 +459,7 @@ export function Prompt(props: PromptProps) {
}

onCleanup(() => {
clearTimeout(clearTimer)
props.ref?.(undefined)
})

Expand Down Expand Up @@ -1157,7 +1186,19 @@ export function Prompt(props: PromptProps) {
/>
</box>
<box width="100%" flexDirection="row" justifyContent="space-between">
<Show when={status().type !== "idle"} fallback={props.hint ?? <text />}>
<Show
when={status().type !== "idle"}
fallback={
store.clearCount > 0 ? (
<text fg={theme.primary}>
esc{" "}
<span style={{ fg: theme.primary }}>again to clear</span>
</text>
) : (
props.hint ?? <text />
)
}
>
<box
flexDirection="row"
gap={1}
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ export namespace Config {
variant_cycle: z.string().optional().default("ctrl+t").describe("Cycle model variants"),
variant_list: z.string().optional().default("none").describe("List model variants"),
input_clear: z.string().optional().default("ctrl+c").describe("Clear input field"),
input_clear_prompt: z.string().optional().default("escape").describe("Clear input (double-press when idle)"),
input_paste: z.string().optional().default("ctrl+v").describe("Paste from clipboard"),
input_submit: z.string().optional().default("return").describe("Submit input"),
input_newline: z
Expand Down
Loading