Skip to content

ListInput Control

Iuga Alexandru edited this page Jan 7, 2018 · 3 revisions

Description

Reads a list of values from the Console input. It stops when an empty string is encountered.

Features

  • Optional label - Display an optional text label at the top of the list.
  • Custom color for the label - The label can be written with specified foreground and background colors.
  • Customizable bullet - Provide a custom bullet text that is displayed in front of each item that the user is requested to write.
  • Customizable space amount after the bullet - Specify how many spaces to write between the bullet and the text that the user writes.
  • Customizable items indentation - Specify the amount of space left empty in front of the items.
  • Read any type of data - The control can be instantiated to rad any type of data, but will be the same for all the items. After the user writes a value, the control will attempt to automatically convert it to the required type.
  • Custom error message for type validation - When the value cannot be converted into the required type, a custom error message is displayed to the user.

In the future

  • Custom validation mechanism.

Examples

Static method (quick):

List<string> beverages = ListInput<string>.QuickRead("What are your prefered beverages?");

Result:

Instance (more power):

ListInput<string> beveragesInput = new ListInput<string>("What are your prefered beverages?");

beveragesInput.Bullet = "#";
beveragesInput.LabelForegroundColor = ConsoleColor.Cyan;
// etc...

List<string> beverages = beveragesInput.Read();

Result:

Clone this wiki locally