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

Function opt

packages/prompts/src/group-multi-select.ts:100–198  ·  view source on GitHub ↗
(
		option: Option<Value> & { group: string | boolean },
		state:
			| 'inactive'
			| 'active'
			| 'selected'
			| 'active-selected'
			| 'group-active'
			| 'group-active-selected'
			| 'submitted'
			| 'cancelled',
		options: (Option<Value> & { group: string | boolean })[] = []
	)

Source from the content-addressed store, hash-verified

98export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) => {
99 const { selectableGroups = true, groupSpacing = 0 } = opts;
100 const opt = (
101 option: Option<Value> & { group: string | boolean },
102 state:
103 | 'inactive'
104 | 'active'
105 | 'selected'
106 | 'active-selected'
107 | 'group-active'
108 | 'group-active-selected'
109 | 'submitted'
110 | 'cancelled',
111 options: (Option<Value> & { group: string | boolean })[] = []
112 ) => {
113 const label = option.label ?? String(option.value);
114 const isItem = typeof option.group === 'string';
115 const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
116 const isLast = isItem && next && next.group === true;
117 let prefix = '';
118 let prefixEnd = '';
119 if (isItem) {
120 if (selectableGroups) {
121 prefix = isLast ? `${S_BAR_END} ` : `${S_BAR} `;
122 prefixEnd = isLast ? ` ` : `${S_BAR} `;
123 } else {
124 prefix = ' ';
125 }
126 }
127 let spacingPrefix = '';
128 if (groupSpacing > 0 && !isItem) {
129 spacingPrefix = '\n'.repeat(groupSpacing);
130 }
131
132 if (state === 'active') {
133 return wrapTextWithPrefix(
134 opts.output,
135 `${label}${option.hint ? ` ${styleText('dim', `(${option.hint})`)}` : ''}`,
136 `${spacingPrefix}${styleText('dim', prefix)} `,
137 `${spacingPrefix}${styleText('dim', prefix)}${styleText('cyan', S_CHECKBOX_ACTIVE)} `,
138 `${spacingPrefix}${styleText('dim', prefixEnd)} `
139 );
140 }
141 if (state === 'group-active') {
142 return wrapTextWithPrefix(
143 opts.output,
144 label,
145 `${spacingPrefix}${prefix} `,
146 `${spacingPrefix}${prefix}${styleText('cyan', S_CHECKBOX_ACTIVE)} `,
147 `${spacingPrefix}${prefixEnd} `,
148 (str) => styleText('dim', str)
149 );
150 }
151 if (state === 'group-active-selected') {
152 return wrapTextWithPrefix(
153 opts.output,
154 label,
155 `${spacingPrefix}${prefix} `,
156 `${spacingPrefix}${prefix}${styleText('green', S_CHECKBOX_SELECTED)} `,
157 `${spacingPrefix}${prefixEnd} `,

Callers 2

styleOptionFunction · 0.70
renderFunction · 0.70

Calls 1

wrapTextWithPrefixFunction · 0.90

Tested by

no test coverage detected