@@ -78,6 +78,29 @@ export class PromptAPI {
78
78
/**
79
79
* Prompts the user with a modal containing a list of buttons.
80
80
* Returns the value of the button that was clicked, or undefined if the modal was closed.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // Prompt the user with a true/false question.
85
+ *
86
+ * const ret = await engine.prompt.button({
87
+ * title: 'The set of natural numbers with zero and the addition operation is a monoid.',
88
+ * buttons: [
89
+ * {
90
+ * label: 'True',
91
+ * value: true,
92
+ * },
93
+ * {
94
+ * label: 'False',
95
+ * value: false,
96
+ * },
97
+ * {
98
+ * label: 'Cancel',
99
+ * value: undefined,
100
+ * }
101
+ * ]
102
+ * });
103
+ * ```
81
104
*/
82
105
public button < T > ( options : ButtonPromptOptions < T > ) : Promise < T | undefined > {
83
106
return new Promise < T | undefined > ( ( resolve , reject ) => {
@@ -105,6 +128,16 @@ export class PromptAPI {
105
128
/**
106
129
* Prompts the user with a confirm/cancel dialog.
107
130
* Returns true if the user confirms, false if the user cancels or otherwise closes the modal.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * // Ask the user if they want to confirm an action.
135
+ *
136
+ * const ret = await engine.prompt.confirm({
137
+ * title: 'Confirm File Deletion',
138
+ * content: 'Are you sure you want to delete this file? This action cannot be undone.',
139
+ * });
140
+ * ```
108
141
*/
109
142
public async confirm ( options : ConfirmPromptOptions ) : Promise < boolean > {
110
143
return (
@@ -129,6 +162,15 @@ export class PromptAPI {
129
162
/**
130
163
* Prompts the user with a yes/no dialog.
131
164
* Returns true if the user selects yes, false if the user selects no, and undefined if the user otherwise closes the modal.
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * // Ask the user if they like Obsidian.
169
+ *
170
+ * const ret = await engine.prompt.yesNo({
171
+ * title: 'Is this a test?',
172
+ * content: 'Are you sure this is a test? Are you sure that your choice is really meaningless?',
173
+ * });
132
174
*/
133
175
public async yesNo ( options : YesNoPromptOptions ) : Promise < boolean | undefined > {
134
176
return await this . button < boolean > ( {
@@ -151,6 +193,23 @@ export class PromptAPI {
151
193
/**
152
194
* Prompts the user with a fuzzy finder suggester dialog.
153
195
* Returns the value of the selected option, or undefined if the user closes the modal.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // Query a list of files and prompt the user to select one.
200
+ *
201
+ * const files = engine.query.files((file) => {
202
+ * return {
203
+ * label: file.name,
204
+ * value: file.pat,
205
+ * };
206
+ * });
207
+ *
208
+ * const ret = await engine.prompt.suggester({
209
+ * placeholder: 'Select a file',
210
+ * options: files,
211
+ * });
212
+ * ```
154
213
*/
155
214
public suggester < T > ( options : SuggesterPromptOptions < T > ) : Promise < T | undefined > {
156
215
return new Promise < T | undefined > ( ( resolve , reject ) => {
@@ -165,6 +224,15 @@ export class PromptAPI {
165
224
/**
166
225
* Prompts the user with a text input dialog.
167
226
* Returns the value of the input field, or undefined if the user closes the modal.
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * // Prompt the user to input their name.
231
+ *
232
+ * const ret = await engine.prompt.text({
233
+ * title: 'Please enter your name',
234
+ * content: 'Please enter your name in the field below.',
235
+ * });
168
236
*/
169
237
public text ( options : InputPromptOptions ) : Promise < string | undefined > {
170
238
return new Promise < string | undefined > ( ( resolve , reject ) => {
@@ -193,6 +261,17 @@ export class PromptAPI {
193
261
/**
194
262
* Prompts the user with a textarea input dialog.
195
263
* Returns the value of the input field, or undefined if the user closes the modal.
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * // Prompt the user to input a multi-line message.
268
+ *
269
+ * const ret = await engine.prompt.textarea({
270
+ * title: 'Please enter your message',
271
+ * content: 'Please enter your message in the field below.',
272
+ * placeholder: 'Your message here...',
273
+ * });
274
+ * ```
196
275
*/
197
276
public textarea ( options : InputPromptOptions ) : Promise < string | undefined > {
198
277
return new Promise < string | undefined > ( ( resolve , reject ) => {
@@ -221,6 +300,16 @@ export class PromptAPI {
221
300
/**
222
301
* Prompts the user with a number input dialog.
223
302
* Returns the value of the input field, or undefined if the user closes the modal.
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * // Prompt the user to input their age.
307
+ *
308
+ * const ret = await engine.prompt.text({
309
+ * title: 'Please enter your age',
310
+ * content: 'Please enter your age in years in the field below.',
311
+ * });
312
+ * ```
224
313
*/
225
314
public number ( options : InputPromptOptions ) : Promise < number | undefined > {
226
315
return new Promise < number | undefined > ( ( resolve , reject ) => {
0 commit comments