-
-
Notifications
You must be signed in to change notification settings - Fork 5
Prompter
Iuga Alexandru edited this page Aug 31, 2018
·
5 revisions
- 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.
- 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.
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);
}
}
private static void RunDemo()
{
Prompter prompter = new Prompter();
prompter.DisplayOnce();
CliCommand command = prompter.LastCommand;
}