Skip to content

Prompter

Iuga Alexandru edited this page Aug 31, 2018 · 5 revisions

Description

  • Displays a prompter and reads a command from the user.
  • Useful when writing a stateful CLI application in which the user can write commands to the console.

Features

  • Customizable prompter text
  • Customizable prompter glyph
  • Read commands repeatedly - Reads commands in a loop until the RequireStop method is called.
  • Read one command - Read a single command, parses and returns it.

Example

Read repeatedly

Note: For a complete example please see the demo project.

private static void RunDemo()
{
    Prompter prompter = new Prompter();
    prompter.NewCommand += HandleNewCommand;

    prompter.Display();
}

private static void HandleNewCommand(object sender, NewCommandEventArgs e)
{
    try
    {
        CliCommand command = e.Command;
        // Do something based on the command.
    }
    catch (Exception ex)
    {
        CustomConsole.WriteError(ex);
    }
}

Read one

private static void RunDemo()
{
    Prompter prompter = new Prompter();
    prompter.DisplayOnce();
    CliCommand command = prompter.LastCommand;
}
Clone this wiki locally