scriptlike.interact

Handling of interaction with users via standard input.

Provides functions for simple and common interacitons with users in the form of question and answer.

License:
zlib/libpng

Authors:
Jesse Phillips

Synopsis:
import scriptlike.interact;

auto age = userInput!int("Please Enter you age");

if(userInput!bool("Do you want to continue?"))
{
    auto outputFolder = pathLocation("Where you do want to place the output?");
    auto color = menu!string("What color would you like to use?", ["Blue", "Green"]);
}

auto num = require!(int, "a > 0 && a <= 10")("Enter a number from 1 to 10");


T userInput(T = string)(string question = "");
The function provides a means to accessing a single value from the user. Each invocation outputs a provided statement/question and takes an entire line of input. The result is then converted to the requested type; default is a string.

auto name = userInput("What is your name");


Returns:
User response as type T.

Where type is bool:

true on "ok", "continue", and if the response starts with 'y' or 'Y'.

false on all other input, include no response (will not throw).

Throws:
if the user does not enter anything. when the string could not be converted to the desired type.

string pathLocation(string action);
Gets a valid path folder from the user. The string will not contain quotes, if you are using in a system call and the path contain spaces wrapping in quotes may be required.

auto confFile = pathLocation("Where is the configuration file?");


Throws:
NoInputException if the user does not provide a path.

T menu(T = ElementType!Range, Range)(string question, Range options) if ((is(T == ElementType!Range) || is(T == int)) && isForwardRange!Range);
Creates a menu from a Range of strings.

It will require that a number is selected within the number of options.

If the the return type is a string, the string in the options parameter will be returned.

Throws:
NoInputException if the user wants to quit.

T require(T, alias cond)(in string question, in string failure = null);
Requires that a value be provided and valid based on the delegate passed in. It must also check against null input.

auto num = require!(int, "a > 0 && a <= 10")("Enter a number from 1 to 10");


Throws:
NoInputException if the user does not provide any value. ConvError if the user does not provide any value.

class NoInputException: object.Exception;
Used when input was not provided.


Page generated by Ddoc. Copyright Jesse Phillips 2010