Constructs a new prompter with the given file source from where the input is to be read from.
Destructor
Appends the given prompt
Performs the prompting by querying each attached prompt for an answer which is then associated with the given prompt
Creating two single-valued prompts and then extracting the answers to them out
Pipe pipe = pipe(); // Create a prompter with some prompts Prompter p = new Prompter(pipe.readEnd()); p.addPrompt(Prompt("What is your name?")); p.addPrompt(Prompt("How old are you")); // Fill up pipe with data for read end File writeEnd = pipe.writeEnd(); writeEnd.writeln("Tristan Brice Velloza Kildaire"); writeEnd.writeln(1); writeEnd.flush(); // Perform the prompt and get the // answers back out Prompt[] ans = p.prompt(); writeln(ans); string nameVal; assert(ans[0].getValue(nameVal)); assert(nameVal == "Tristan Brice Velloza Kildaire"); string ageVal; assert(ans[1].getValue(ageVal)); assert(to!(int)(ageVal) == 1); // TODO: Allow union conversion later
Creating a single-value prompt which CANNOT be empty and then also a multi-valued prompt
Pipe pipe = pipe(); // Create a prompter with some prompts Prompter p = new Prompter(pipe.readEnd()); p.addPrompt(Prompt("What is your name?", false, false)); p.addPrompt(Prompt("Enter the names of your friends", true)); // Fill up pipe with data for read end File writeEnd = pipe.writeEnd(); writeEnd.writeln(""); // Purposefully do empty (for name) writeEnd.writeln("Tristan Brice Velloza Kildaire"); // Now actually fill it in (for name) writeEnd.writeln("Thomas"); writeEnd.writeln("Risima"); writeEnd.writeln(""); writeEnd.flush(); // Perform the prompt and get the // answers back out Prompt[] ans = p.prompt(); writeln(ans); string nameVal; assert(ans[0].getValue(nameVal)); assert(nameVal == "Tristan Brice Velloza Kildaire"); string[] friends; assert(ans[1].getValues(friends)); assert(friends == ["Thomas", "Risima"]);
A prompting mechanism which can be filled up with questions and a file-based source to read answers in from and associate with their original respective questions