Skip to content

Commit 1d3b181

Browse files
committed
feat(prompt): show mode-specific input placeholders
1 parent c6ec2f4 commit 1d3b181

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/component/prompt

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, t, dim, fg } from "@opentui/core"
2-
import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, Show, Switch, Match } from "solid-js"
2+
import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, on, Show, Switch, Match } from "solid-js"
33
import "opentui-spinner/solid"
44
import { useLocal } from "@tui/context/local"
55
import { useTheme } from "@tui/context/theme"
@@ -54,6 +54,7 @@ export type PromptRef = {
5454
}
5555

5656
const PLACEHOLDERS = ["Fix a TODO in the codebase", "What is the tech stack of this project?", "Fix broken tests"]
57+
const SHELL_PLACEHOLDERS = ["ls -la", "git status", "pwd"]
5758

5859
export function Prompt(props: PromptProps) {
5960
let input: TextareaRenderable
@@ -134,6 +135,16 @@ export function Prompt(props: PromptProps) {
134135
interrupt: 0,
135136
})
136137

138+
createEffect(
139+
on(
140+
() => props.sessionID,
141+
() => {
142+
setStore("placeholder", Math.floor(Math.random() * PLACEHOLDERS.length))
143+
},
144+
{ defer: true },
145+
),
146+
)
147+
137148
// Initialize agent/model/variant from last user message when session changes
138149
let syncedSessionID: string | undefined
139150
createEffect(() => {
@@ -736,6 +747,15 @@ export function Prompt(props: PromptProps) {
736747
return !!current
737748
})
738749

750+
const placeholderText = createMemo(() => {
751+
if (props.sessionID) return undefined
752+
if (store.mode === "shell") {
753+
const example = SHELL_PLACEHOLDERS[store.placeholder % SHELL_PLACEHOLDERS.length]
754+
return `Run a command... "${example}"`
755+
}
756+
return `Ask anything... "${PLACEHOLDERS[store.placeholder % PLACEHOLDERS.length]}"`
757+
})
758+
739759
const spinnerDef = createMemo(() => {
740760
const color = local.agent.color(local.agent.current().name)
741761
return {
@@ -797,7 +817,7 @@ export function Prompt(props: PromptProps) {
797817
flexGrow={1}
798818
>
799819
<textarea
800-
placeholder={props.sessionID ? undefined : `Ask anything... "${PLACEHOLDERS[store.placeholder]}"`}
820+
placeholder={placeholderText()}
801821
textColor={keybind.leader ? theme.textMuted : theme.text}
802822
focusedTextColor={keybind.leader ? theme.textMuted : theme.text}
803823
minHeight={1}
@@ -850,6 +870,7 @@ export function Prompt(props: PromptProps) {
850870
}
851871
}
852872
if (e.name === "!" && input.visualCursor.offset === 0) {
873+
setStore("placeholder", Math.floor(Math.random() * SHELL_PLACEHOLDERS.length))
853874
setStore("mode", "shell")
854875
e.preventDefault()
855876
return

0 commit comments

Comments
 (0)