MCPcopy Index your code
hub / github.com/bombshell-dev/clack / render

Function render

packages/prompts/src/group-multi-select.ts:224–317  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

222 )}`;
223 },
224 render() {
225 const hasGuide = opts.withGuide ?? settings.withGuide;
226 const title = `${hasGuide ? `${styleText('gray', S_BAR)}\n` : ''}${symbol(this.state)} ${opts.message}\n`;
227 const value = this.value ?? [];
228
229 const styleOption = (
230 option: Option<Value> & { group: string | boolean },
231 active: boolean
232 ) => {
233 const options = this.options;
234 const selected =
235 value.includes(option.value) ||
236 (option.group === true && this.isGroupSelected(`${option.value}`));
237 const groupActive =
238 !active &&
239 typeof option.group === 'string' &&
240 this.options[this.cursor].value === option.group;
241 if (groupActive) {
242 return opt(option, selected ? 'group-active-selected' : 'group-active', options);
243 }
244 if (active && selected) {
245 return opt(option, 'active-selected', options);
246 }
247 if (selected) {
248 return opt(option, 'selected', options);
249 }
250 return opt(option, active ? 'active' : 'inactive', options);
251 };
252
253 switch (this.state) {
254 case 'submit': {
255 const selectedOptions = this.options
256 .filter(({ value: optionValue }) => value.includes(optionValue))
257 .map((option) => opt(option, 'submitted'));
258 const optionsText =
259 selectedOptions.length === 0 ? '' : ` ${selectedOptions.join(styleText('dim', ', '))}`;
260 return `${title}${hasGuide ? styleText('gray', S_BAR) : ''}${optionsText}`;
261 }
262 case 'cancel': {
263 const label = this.options
264 .filter(({ value: optionValue }) => value.includes(optionValue))
265 .map((option) => opt(option, 'cancelled'))
266 .join(styleText('dim', ', '));
267 return `${title}${hasGuide ? `${styleText('gray', S_BAR)} ` : ''}${
268 label.trim() ? `${label}${hasGuide ? `\n${styleText('gray', S_BAR)}` : ''}` : ''
269 }`;
270 }
271 case 'error': {
272 const guidePrefix = hasGuide ? `${styleText('yellow', S_BAR)} ` : '';
273 const footer = this.error
274 .split('\n')
275 .map((ln, i) =>
276 i === 0
277 ? `${hasGuide ? `${styleText('yellow', S_BAR_END)} ` : ''}${styleText('yellow', ln)}`
278 : ` ${ln}`
279 )
280 .join('\n');
281 // Calculate rowPadding: title lines + footer lines (error message + trailing newline)

Callers

nothing calls this directly

Calls 4

symbolFunction · 0.85
limitOptionsFunction · 0.85
formatInstructionFooterFunction · 0.85
optFunction · 0.70

Tested by

no test coverage detected