Skip to content
Open
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
45 changes: 37 additions & 8 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function Prompt(props: PromptProps) {
let input: TextareaRenderable
let anchor: BoxRenderable
let autocomplete: AutocompleteRef
let clearInputTimer: ReturnType<typeof setTimeout> | undefined

const keybind = useKeybind()
const local = useLocal()
Expand Down Expand Up @@ -124,6 +125,7 @@ export function Prompt(props: PromptProps) {
extmarkToPartIndex: Map<number, number>
interrupt: number
placeholder: number
clearCount: number
}>({
placeholder: Math.floor(Math.random() * PLACEHOLDERS.length),
prompt: {
Expand All @@ -133,6 +135,7 @@ export function Prompt(props: PromptProps) {
mode: "normal",
extmarkToPartIndex: new Map(),
interrupt: 0,
clearCount: 0,
})

createEffect(
Expand Down Expand Up @@ -166,6 +169,18 @@ export function Prompt(props: PromptProps) {
}
})

function scheduleClearReset() {
if (clearInputTimer) clearTimeout(clearInputTimer)
clearInputTimer = setTimeout(() => {
setStore("clearCount", 0)
clearInputTimer = undefined
}, 2000)
}

onCleanup(() => {
if (clearInputTimer) clearTimeout(clearInputTimer)
})

command.register(() => {
return [
{
Expand Down Expand Up @@ -852,14 +867,21 @@ export function Prompt(props: PromptProps) {
// If no image, let the default paste behavior continue
}
if (keybind.match("input_clear", e) && store.prompt.input !== "") {
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
return
setStore("clearCount", store.clearCount + 1)
if (store.clearCount >= 2) {
if (clearInputTimer) clearTimeout(clearInputTimer)
clearInputTimer = undefined
input.clear()
input.extmarks.clear()
setStore("prompt", {
input: "",
parts: [],
})
setStore("extmarkToPartIndex", new Map())
setStore("clearCount", 0)
return
}
scheduleClearReset()
}
if (keybind.match("app_exit", e)) {
if (store.prompt.input === "") {
Expand Down Expand Up @@ -1012,6 +1034,13 @@ export function Prompt(props: PromptProps) {
</Show>
</box>
</Show>
<box marginLeft={"auto"} flexShrink={0} flexDirection="row">
<Show when={store.clearCount > 0}>
<text fg={theme.textMuted}>
<span style={{ fg: theme.text }}>{keybind.print("input_clear")}</span> again to clear
</text>
</Show>
</box>
</box>
</box>
</box>
Expand Down