|
1 | 1 | 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" |
3 | 3 | import "opentui-spinner/solid" |
4 | 4 | import { useLocal } from "@tui/context/local" |
5 | 5 | import { useTheme } from "@tui/context/theme" |
@@ -54,6 +54,7 @@ export type PromptRef = { |
54 | 54 | } |
55 | 55 |
|
56 | 56 | 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"] |
57 | 58 |
|
58 | 59 | export function Prompt(props: PromptProps) { |
59 | 60 | let input: TextareaRenderable |
@@ -134,6 +135,16 @@ export function Prompt(props: PromptProps) { |
134 | 135 | interrupt: 0, |
135 | 136 | }) |
136 | 137 |
|
| 138 | + createEffect( |
| 139 | + on( |
| 140 | + () => props.sessionID, |
| 141 | + () => { |
| 142 | + setStore("placeholder", Math.floor(Math.random() * PLACEHOLDERS.length)) |
| 143 | + }, |
| 144 | + { defer: true }, |
| 145 | + ), |
| 146 | + ) |
| 147 | + |
137 | 148 | // Initialize agent/model/variant from last user message when session changes |
138 | 149 | let syncedSessionID: string | undefined |
139 | 150 | createEffect(() => { |
@@ -736,6 +747,15 @@ export function Prompt(props: PromptProps) { |
736 | 747 | return !!current |
737 | 748 | }) |
738 | 749 |
|
| 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 | + |
739 | 759 | const spinnerDef = createMemo(() => { |
740 | 760 | const color = local.agent.color(local.agent.current().name) |
741 | 761 | return { |
@@ -797,7 +817,7 @@ export function Prompt(props: PromptProps) { |
797 | 817 | flexGrow={1} |
798 | 818 | > |
799 | 819 | <textarea |
800 | | - placeholder={props.sessionID ? undefined : `Ask anything... "${PLACEHOLDERS[store.placeholder]}"`} |
| 820 | + placeholder={placeholderText()} |
801 | 821 | textColor={keybind.leader ? theme.textMuted : theme.text} |
802 | 822 | focusedTextColor={keybind.leader ? theme.textMuted : theme.text} |
803 | 823 | minHeight={1} |
@@ -850,6 +870,7 @@ export function Prompt(props: PromptProps) { |
850 | 870 | } |
851 | 871 | } |
852 | 872 | if (e.name === "!" && input.visualCursor.offset === 0) { |
| 873 | + setStore("placeholder", Math.floor(Math.random() * SHELL_PLACEHOLDERS.length)) |
853 | 874 | setStore("mode", "shell") |
854 | 875 | e.preventDefault() |
855 | 876 | return |
|
0 commit comments