scriptlike.interact

Handling of interaction with users via standard input.

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

Members

Classes

NoInputException
class NoInputException

Used when input was not provided.

Functions

menu
T menu(string question, Range options)

Creates a menu from a Range of strings.

pathLocation
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.

pause
void pause(string prompt = defaultPausePrompt)

Pauses and prompts the user to press Enter (or "Return" on OSX).

require
T require(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.

userInput
T userInput(string question = "")
void userInput(string question, ref T result)

The userInput 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.

Meta

Authors

Jesse Phillips

Synopsis:

1 import scriptlike.interact;
2 
3 auto age = userInput!int("Please Enter your age");
4 
5 if(userInput!bool("Do you want to continue?"))
6 {
7    auto outputFolder = pathLocation("Where you do want to place the output?");
8    auto color = menu!string("What color would you like to use?", ["Blue", "Green"]);
9 }
10 
11 auto num = require!(int, "a > 0 && a <= 10")("Enter a number from 1 to 10");