@@ -45,6 +45,10 @@ export type PromptProps = {
4545 ref ?: ( ref : PromptRef ) => void
4646 hint ?: JSX . Element
4747 showPlaceholder ?: boolean
48+ placeholders ?: {
49+ normal ?: string [ ]
50+ shell ?: string [ ]
51+ }
4852}
4953
5054export type PromptRef = {
@@ -57,13 +61,16 @@ export type PromptRef = {
5761 submit ( ) : void
5862}
5963
60- const PLACEHOLDERS = [ "Fix a TODO in the codebase" , "What is the tech stack of this project?" , "Fix broken tests" ]
61- const SHELL_PLACEHOLDERS = [ "ls -la" , "git status" , "pwd" ]
6264const money = new Intl . NumberFormat ( "en-US" , {
6365 style : "currency" ,
6466 currency : "USD" ,
6567} )
6668
69+ function randomIndex ( count : number ) {
70+ if ( count <= 0 ) return 0
71+ return Math . floor ( Math . random ( ) * count )
72+ }
73+
6774export function Prompt ( props : PromptProps ) {
6875 let input : TextareaRenderable
6976 let anchor : BoxRenderable
@@ -83,6 +90,8 @@ export function Prompt(props: PromptProps) {
8390 const renderer = useRenderer ( )
8491 const { theme, syntax } = useTheme ( )
8592 const kv = useKV ( )
93+ const list = createMemo ( ( ) => props . placeholders ?. normal ?? [ ] )
94+ const shell = createMemo ( ( ) => props . placeholders ?. shell ?? [ ] )
8695
8796 function promptModelWarning ( ) {
8897 toast . show ( {
@@ -152,7 +161,7 @@ export function Prompt(props: PromptProps) {
152161 interrupt : number
153162 placeholder : number
154163 } > ( {
155- placeholder : Math . floor ( Math . random ( ) * PLACEHOLDERS . length ) ,
164+ placeholder : randomIndex ( list ( ) . length ) ,
156165 prompt : {
157166 input : "" ,
158167 parts : [ ] ,
@@ -166,7 +175,7 @@ export function Prompt(props: PromptProps) {
166175 on (
167176 ( ) => props . sessionID ,
168177 ( ) => {
169- setStore ( "placeholder" , Math . floor ( Math . random ( ) * PLACEHOLDERS . length ) )
178+ setStore ( "placeholder" , randomIndex ( list ( ) . length ) )
170179 } ,
171180 { defer : true } ,
172181 ) ,
@@ -801,12 +810,14 @@ export function Prompt(props: PromptProps) {
801810 } )
802811
803812 const placeholderText = createMemo ( ( ) => {
804- if ( props . sessionID ) return undefined
813+ if ( props . showPlaceholder === false ) return undefined
805814 if ( store . mode === "shell" ) {
806- const example = SHELL_PLACEHOLDERS [ store . placeholder % SHELL_PLACEHOLDERS . length ]
815+ if ( ! shell ( ) . length ) return undefined
816+ const example = shell ( ) [ store . placeholder % shell ( ) . length ]
807817 return `Run a command... "${ example } "`
808818 }
809- return `Ask anything... "${ PLACEHOLDERS [ store . placeholder % PLACEHOLDERS . length ] } "`
819+ if ( ! list ( ) . length ) return undefined
820+ return `Ask anything... "${ list ( ) [ store . placeholder % list ( ) . length ] } "`
810821 } )
811822
812823 const spinnerDef = createMemo ( ( ) => {
@@ -922,7 +933,7 @@ export function Prompt(props: PromptProps) {
922933 }
923934 }
924935 if ( e . name === "!" && input . visualCursor . offset === 0 ) {
925- setStore ( "placeholder" , Math . floor ( Math . random ( ) * SHELL_PLACEHOLDERS . length ) )
936+ setStore ( "placeholder" , randomIndex ( shell ( ) . length ) )
926937 setStore ( "mode" , "shell" )
927938 e . preventDefault ( )
928939 return
@@ -1097,7 +1108,7 @@ export function Prompt(props: PromptProps) {
10971108 />
10981109 </ box >
10991110 < box flexDirection = "row" justifyContent = "space-between" >
1100- < Show when = { status ( ) . type !== "idle" } fallback = { < text /> } >
1111+ < Show when = { status ( ) . type !== "idle" } fallback = { props . hint ?? < text /> } >
11011112 < box
11021113 flexDirection = "row"
11031114 gap = { 1 }
0 commit comments