Interactive command-line toolkit for C# with powerful controls and commands.
Usage | Install | Organization | Api Controls | Extensions | Supported Platforms
PromptPlus was developed in c# with the netstandard2.1, .Net5 and .Net6 target frameworks.
All controls input/filter using GNU Readline Emacs keyboard shortcuts.
PromptPlus has separate pakage integrate command line parse CommandDotNet(4.3.0/6.0.0):
- Interative session with readline prompt, Sugestions and History.
- Now you can help to discover arguments (Sugestions) and history actions in interactive sessions.
- Wizard to find all the commands/options and arguments with prompt and then run.
- Now you can discover and learn the existing commands, options and arguments.
An open-source guide to help you write better command-line programs, taking traditional UNIX principles and updating them for the modern day.
Command Line Interface Guidelines
The project in the folder PromptPlusExample contains all the samples to controls and commands.
dotnet run --project PromptPlusExample
The project in the folder CommandDotNet.Example contains all the samples built into CommandDotNet
dotnet run --project CommandDotNet.Example [wizard]
public class Program
{
static int Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); ;
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
PromptPlus.ConsoleDefaultColor(ConsoleColor.White, ConsoleColor.Black);
PromptPlus.Clear();
return new AppRunner<Examples>()
.UseDefaultMiddleware()
.UsePrompter()
.UseNameCasing(Case.KebabCase)
.UsePromptPlusAnsiConsole()
.UsePromptPlusArgumentPrompter()
.UsePromptPlusWizard()
.UsePromptPlusRepl(colorizeSessionInitMessage: (msg) => msg.Yellow().Underline())
.Run(args);
}
}
//MaskEdit Generic
var mask = PromptPlus.MaskEdit(MaskedType.Generic, "Inventory Number")
.Mask(@"\XYZ 9{3}-L{3}-C[ABC]N{1}[XYZ]-A{3}")
.Run(_stopApp);
if (mask.IsAborted)
{
return;
}
if (string.IsNullOrEmpty(mask.Result.Value))
{
Console.WriteLine($"your input was empty!");
}
else
{
Console.WriteLine($"your input was {mask.Result.ObjectValue}!");
}
//AnyKey
var key = PromptPlus.KeyPress()
.Run(_stopApp);
if (key.IsAborted)
{
return;
}
Console.WriteLine($"Hello, key pressed");
//input
var name = PromptPlus.Input("What's your name?")
.Default("Peter Parker")
.Addvalidator(PromptPlusValidators.Required())
.Addvalidator(PromptPlusValidators.MinLength(3))
.Run(_stopApp);
if (name.IsAborted)
{
return;
}
Console.WriteLine($"Hello, {name.Result}!");
PromptPlus was developed in c# with the **netstandard2.1, .NET 5 AND .NET6 ** target frameworks.
Install-Package PromptPlus [-pre]
dotnet add package PromptPlus [--prerelease]
Note: [-pre]/[--prerelease] usage for pre-release versions
All controls have the same lines organization:
- Message and data entry (ever)
- Filter (depends on the control)
- Description (configurable/optional)
- Tooltips (configurable)
- Collection subset items (depends on the control, page size and size of console/terminal)
- Page information (depends on size colletion, page size and size of console/terminal)
- Error message (depends on the control and validators)
tooltips can be global (hotkey always active - default F1) and control specific. All controls have the properties to show hide tooltips.
When a control has a collection it can be paged with a limit of items per page. When the item per page limit is not entered, the number of items per page is set to the maximum allowed by the console/terminal size. If the console/terminal is resized, an adjustment will be made to a number of items per page and a message will be issued on the console (only when it is a terminal)
PromptPlus applies the language/culture only when running controls. The language/culture of the application is not affected. If language/culture is not informed, the application's language/culture will be used with fallback to en-US.
All messages are affected when changed language/culture. PromptPlus has languages embeded:
- en-US (Default)
- pt-BR
//sample
PromptPlus.DefaultCulture = new CultureInfo("en-US");
To use a non-embedded language/culture:
- Use the PromptPlusResources.resx file in folder PromptPlus/Resources
- Translate messages with same format to your language/culture
- Convert .resx files to binary .resources files (reference link here)
- Publish the compiled file (PromptPlus.{Language}.resources) in the same folder as the binaries.
PromptPlus is in accordance with informal standard NO COLOR. when there is the environment variable "no_color" the colors are disabled. PromptPlus has a configurable color(16 color) schema.
PromptPlus.ColorSchema.Answer = ConsoleColor.DarkRed;
PromptPlus.ColorSchema.Select = ConsoleColor.DarkCyan;
Prompt Plus also has commands for parts of text and underlining.
PromptPlus.WriteLine("This [cyan]is [red]a [white:blue]simples[/] line with [yellow!u]color[/]. End [/]line.");
PromptPlus.WriteLine("This is a simples ","line".White().OnBlue().Underline(), " with ", "color".Red());
PromptPlus has a configurable symbos with Unicode support (Multi-byte characters and Emoji๐๐) and Fallback.
//sample
PromptPlus.Symbols.Done = new Symbol("โ", "V ");
Note: new Symbol() return : Symbol = single space and Fallback = double space.
Hotkeys (global and control-specific) are configurable. Some hotkeys are internal and reserved.
//sample
PromptPlus.AbortAllPipesKeyPress = new HotKey(UserHotKey.F7, alt: true, ctrl: false, shift: false);
Note: the key parameter is case-insentive;
PromptPlus allows saving and loading a previous configuration of culture, behavior, hotkeys, colors and symbols.A file with the default configuration is available in the package in the Resources folder named PromptPlus.config.json . To load automatically the file must be placed in your project and published in the same folder as the binaries.
//sample save
PromptPlus.SaveConfigToFile(folderfile: "YourFolder");
//sample load
PromptPlus.LoadConfigFromFile(folderfile: "YourFolder");
Note: if the folderfile parameter is omitted, it will be saved/loaded from the default application folder
Controls/Commands | Details |
---|---|
Commands | Command set for PromptPlus console |
Color | Easy to add some color-text and underline |
ASCII-Banner | ASCII text banner |
Any-key | Simple any key press |
Key-Press | Simple specific key |
Confirm | Simple confirm with with tool tips and language detection |
AutoComplete | Input text with sugestions, validator, and tooltips |
Readline | Input text with GNU Readline Emacs keyboard shortcuts, sugestions and historic |
Input | Input text with input validator with tooltips |
Extensions points | Input text with history/suguestions using extensions points |
Password | Input password with input validator and show/hide(optional) input value |
MaskEdit-Generic | Input with masked input , tooltips and input validator |
MaskEdit-Date | Date input with language parameter, tooltips and input validator |
MaskEdit-Time | Time input with language parameter, tooltips and input validator |
MaskEdit-Date/Time | Date and time input with language parameter, tooltips and input validator |
MaskEdit-Number | Numeric input with language parameter, tooltips and input validator |
MaskEdit-Currency | Currency input with language parameter, tooltips and input validator |
Select | Generic select input IEnumerable/Enum with auto-paginator and tooltips and more |
MultiSelect | Generic multi select input IEnumerable/Enum with group, auto-paginator , tooltips and more |
List | Create Generic IEnumerable with auto-paginator, tooptip , input validator, message error by type/format and more |
ListMasked | Create generic IEnumerable with maskedit, auto-paginator, tooptip , input validator |
Browser | Browser files/folder with auto-paginator and tooltips |
Slider-Number | Numeric ranger with short/large step and tooltips |
Number-Up/Down | Numeric ranger with step and tooltips |
Slider-Switch | Generic choice with customization and tooltips |
Progress-Bar | Progress Bar with interation customization |
Wait-Process | Wait process with animation |
PipeLine | Pipeline sequence to all prompts with condition by pipe and status summary |
PromptPlus have a extension to import validator. No duplicate code!
private class MylCass
{
[Required(ErrorMessage = "{0} is required!")]
[MinLength(3, ErrorMessage = "Min. Length = 3.")]
[MaxLength(5, ErrorMessage = "Max. Length = 5.")]
[Display(Prompt ="My Input")]
public string MyInput { get; set; }
}
var inst = new MylCass();
var name = PromptPlus.Input("Input Value for MyInput")
.Addvalidators(inst.ImportValidators(x => x.MyInput))
.Run(_stopApp);
if (name.IsAborted)
{
return;
}
Console.WriteLine($"Your input: {name.Value}!");
- Windows
- Command Prompt, PowerShell, Windows Terminal
- Linux (Ubuntu, etc)
- Windows Terminal (WSL 2)
- macOS
- Terminal.app
- Color Text was inspired by the work of Colored-Console and Rick Strahl
- FIGlet was inspired by the work of FIGlet.Net.
- The base-control and some of its dependencies were inspired by the work of Sharprompt.
This project is licensed under the MIT License