renderPlaceholder.ts
hooks/renderPlaceholder.ts
No strong subsystem tag
52
Lines
1280
Bytes
1
Exports
1
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 52 lines, 1 detected imports, and 1 detected exports.
Important relationships
Detected exports
renderPlaceholder
Keywords
placeholderrenderedplaceholderchalkinvertshowcursorfocusterminalfocushideplaceholdertextshowplaceholderplaceholderrendererprops
Detected imports
chalk
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
import chalk from 'chalk'
type PlaceholderRendererProps = {
placeholder?: string
value: string
showCursor?: boolean
focus?: boolean
terminalFocus: boolean
invert?: (text: string) => string
hidePlaceholderText?: boolean
}
export function renderPlaceholder({
placeholder,
value,
showCursor,
focus,
terminalFocus = true,
invert = chalk.inverse,
hidePlaceholderText = false,
}: PlaceholderRendererProps): {
renderedPlaceholder: string | undefined
showPlaceholder: boolean
} {
let renderedPlaceholder: string | undefined = undefined
if (placeholder) {
if (hidePlaceholderText) {
// Voice recording: show only the cursor, no placeholder text
renderedPlaceholder =
showCursor && focus && terminalFocus ? invert(' ') : ''
} else {
renderedPlaceholder = chalk.dim(placeholder)
// Show inverse cursor only when both input and terminal are focused
if (showCursor && focus && terminalFocus) {
renderedPlaceholder =
placeholder.length > 0
? invert(placeholder[0]!) + chalk.dim(placeholder.slice(1))
: invert(' ')
}
}
}
const showPlaceholder = value.length === 0 && Boolean(placeholder)
return {
renderedPlaceholder,
showPlaceholder,
}
}