Simple Input
Final doesn’t provide a way to directly prompt for input from the Prompt area, but it has a simple API for raising a modal dialog to either ask for a confirmation, or request a few fields of information. We provide a quick example of the latter here, and cover the topic in more detail in the Input/UI Dialogs topic.
No introduction would be complete with some Monty Python. The following example is in examples/dialog/ask-demo.fnl.
: ask-demo
( "What is your name?" "What is your quest?" )
Dialog.ask^ if
"Nice to meet you, %s. Off you go — \"%s\" is a fine quest.\n" fmt $
else
"Then we shan't proceed. Nobody expects the Spanish Inquisition.\n" $
then
;
The code provides the requested field labels using the convenient Paren operators for building a List. It then asks Dialog to post the dialog via the ask method, which returns one of two types of result shape:
truethen a List of the replies, in order of requestfalseand no List
You test for the response type using an if statement, and if true can then pass the List directly to a fmt statement and print it out. If false, you can print a default reply, as above.
Dialog is covered in more detail in Input/UI Dialogs, Paren operators in Compound Builders and fmt in Output Formatting.
Let’s now move on, and dig a little deeper into Final…