MCPcopy Create free account
hub / github.com/bombshell-dev/clack / render

Function render

packages/prompts/src/date.ts:98–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96 return undefined;
97 },
98 render() {
99 const hasGuide = (opts?.withGuide ?? settings.withGuide) !== false;
100 const titlePrefix = `${hasGuide ? `${styleText('gray', S_BAR)}\n` : ''}${symbol(this.state)} `;
101 const title = `${titlePrefix}${opts.message}\n`;
102
103 const state = this.state !== 'initial' ? this.state : 'active';
104
105 const userInput = renderDate(this, state);
106 const value = this.value instanceof Date ? this.formattedValue : '';
107
108 switch (this.state) {
109 case 'error': {
110 const errorText = this.error ? ` ${styleText('yellow', this.error)}` : '';
111 const bar = hasGuide ? `${styleText('yellow', S_BAR)} ` : '';
112 const barEnd = hasGuide ? styleText('yellow', S_BAR_END) : '';
113 return `${title.trim()}\n${bar}${userInput}\n${barEnd}${errorText}\n`;
114 }
115 case 'submit': {
116 const valueText = value ? ` ${styleText('dim', value)}` : '';
117 const bar = hasGuide ? styleText('gray', S_BAR) : '';
118 return `${title}${bar}${valueText}`;
119 }
120 case 'cancel': {
121 const valueText = value ? ` ${styleText(['strikethrough', 'dim'], value)}` : '';
122 const bar = hasGuide ? styleText('gray', S_BAR) : '';
123 return `${title}${bar}${valueText}${value.trim() ? `\n${bar}` : ''}`;
124 }
125 default: {
126 const bar = hasGuide ? `${styleText('cyan', S_BAR)} ` : '';
127 const barEnd = hasGuide ? styleText('cyan', S_BAR_END) : '';
128 const inlineBar = hasGuide ? `${styleText('cyan', S_BAR)} ` : '';
129 const inlineError = this.inlineError
130 ? `\n${inlineBar}${styleText('yellow', this.inlineError)}`
131 : '';
132 return `${title}${bar}${userInput}${inlineError}\n${barEnd}\n`;
133 }
134 }
135 },
136 }).prompt() as Promise<Date | symbol>;
137};
138

Callers

nothing calls this directly

Calls 2

symbolFunction · 0.85
renderDateFunction · 0.85

Tested by

no test coverage detected