All Manuals > CAPI User Guide and Reference Manual > 21 CAPI Reference Entries

NextPrevUpTopContentsIndex

prompt-for-string

Function
Summary

Displays a text input pane and prompts the user for a string.

Package

capi

Signature

prompt-for-string message &key pane-args popup-args ok-check value-function text initial-value print-function history-symbol history-function continuation => result , okp

Description

The function prompt-for-string prompts the user for a string and returns that string in result and a flag okp indicating that the dialog was not cancelled. The initial string can either be supplied directly as a string using the text argument, or by passing initial-value and a print-function for that value. print-function defaults to princ-to-string. The value returned can be converted into a different value by passing a value-function , which by default is the identity function. This value-function gets passed the text that was entered into the pane, and should return both the value to return and a flag that should be non-nil if the value that was entered is not acceptable. If an ok-check is passed, then it should return non-nil if the value about to be returned is acceptable.

prompt-for-string creates an instance of text-input-pane or text-input-choice depending on the value of history-function . Arguments can be passed to the make-instance of this pane using pane-args . prompt-for-string then passes this pane to popup-confirmer. Arguments can be passed to the call to popup-confirmer using popup-args .

history-symbol , if non-nil, provides a symbol whose value is used to store an input history, when history-function is not supplied. The default value of history-symbol is nil.

history-function , if supplied, should be a function designator for a function with signature:

history-function &optional push-value

history-function is called with no argument to obtain the history which is used as the items of the text-input-choice, and with the latest input to update the history.

The default value of history-function is nil. In this case, if history-symbol is non-nil then a history function is constructed which stores its history in the value of that symbol.

If continuation is non-nil, then it must be a function with a lambda list that accepts two arguments. The continuation function is called with the values that would normally be returned by prompt-for-string. On Cocoa, passing continuation causes the dialog to be made as a window-modal sheet and prompt-for-string returns immediately, leaving the dialog on the screen. The with-dialog-results macro provides a convenient way to create a continuation function.

Example
(capi:prompt-for-string "Enter a string:")
(capi:prompt-for-string
 "Enter an integer:"
 :initial-value 10
 :value-function  #'(lambda (x)
                      (let ((integer
                            (ignore-errors
                            (read-from-string x))))
                      (values integer
                         (not (integerp integer))
                      ))))
See also

popup-confirmer
text-input-pane
Dialogs: Prompting for Input


CAPI User Guide and Reference Manual (Windows version) - 3 Aug 2017

NextPrevUpTopContentsIndex