@@ -2,14 +2,57 @@ import { styleText } from 'node:util';
22import { settings , TextPrompt } from '@clack/core' ;
33import { type CommonOptions , S_BAR , S_BAR_END , symbol } from './common.js' ;
44
5+ /**
6+ * Options for the {@link text} prompt
7+ */
58export interface TextOptions extends CommonOptions {
9+ /**
10+ * The prompt message or question shown to the user above the input.
11+ */
612 message : string ;
13+
14+ /**
15+ * A visual hint shown when the field has no content.
16+ */
717 placeholder ?: string ;
18+
19+ /**
20+ * A fallback value returned when the user provides nothing (empty input).
21+ */
822 defaultValue ?: string ;
23+
24+ /**
25+ * The starting value shown when the prompt first renders.
26+ * Users can edit this value before submitting.
27+ */
928 initialValue ?: string ;
29+
30+ /**
31+ * A function that validates user input. Return a `string` or `Error` to show as a
32+ * validation error, or `undefined` to accept the result.
33+ */
1034 validate ?: ( value : string | undefined ) => string | Error | undefined ;
1135}
1236
37+ /**
38+ * The text prompt accepts a single line of text.
39+ *
40+ * @see https://bomb.sh/docs/clack/packages/prompts/#text-input
41+ *
42+ * @example
43+ * ```ts
44+ * import { text } from '@clack/prompts';
45+ *
46+ * const name = await text({
47+ * message: 'What is your name?',
48+ * placeholder: 'John Doe',
49+ * validate: (value) => {
50+ * if (!value || value.length < 2) return 'Name must be at least 2 characters';
51+ * return undefined;
52+ * },
53+ * });
54+ * ```
55+ */
1356export const text = ( opts : TextOptions ) => {
1457 return new TextPrompt ( {
1558 validate : opts . validate ,
0 commit comments