source dump of claude code
at main 51 lines 1.3 kB view raw
1import chalk from 'chalk' 2 3type PlaceholderRendererProps = { 4 placeholder?: string 5 value: string 6 showCursor?: boolean 7 focus?: boolean 8 terminalFocus: boolean 9 invert?: (text: string) => string 10 hidePlaceholderText?: boolean 11} 12 13export function renderPlaceholder({ 14 placeholder, 15 value, 16 showCursor, 17 focus, 18 terminalFocus = true, 19 invert = chalk.inverse, 20 hidePlaceholderText = false, 21}: PlaceholderRendererProps): { 22 renderedPlaceholder: string | undefined 23 showPlaceholder: boolean 24} { 25 let renderedPlaceholder: string | undefined = undefined 26 27 if (placeholder) { 28 if (hidePlaceholderText) { 29 // Voice recording: show only the cursor, no placeholder text 30 renderedPlaceholder = 31 showCursor && focus && terminalFocus ? invert(' ') : '' 32 } else { 33 renderedPlaceholder = chalk.dim(placeholder) 34 35 // Show inverse cursor only when both input and terminal are focused 36 if (showCursor && focus && terminalFocus) { 37 renderedPlaceholder = 38 placeholder.length > 0 39 ? invert(placeholder[0]!) + chalk.dim(placeholder.slice(1)) 40 : invert(' ') 41 } 42 } 43 } 44 45 const showPlaceholder = value.length === 0 && Boolean(placeholder) 46 47 return { 48 renderedPlaceholder, 49 showPlaceholder, 50 } 51}