FRACerqueira / PromptPlus

Interactive command-line toolkit for .Net core with powerful controls and commands to create professional console applications.
https://fracerqueira.github.io/PromptPlus/
MIT License
50 stars 5 forks source link
autocomplete-suggestions chart cli command-line console console-table csharp datagridview dotnet grid-layout maskedit prompt readline table terminal

Welcome to PromptPlus

Build Publish License NuGet Downloads

Interactive command-line toolkit for .NET Core with powerful controls and commands to create professional console applications.

PromptPlus was developed in C# with the netstandard2.1, .NET 6 , .NET 7 and .NET 8 target frameworks.

Visit the official page for more documentation of PromptPlus

Table of Contents

What's new in the latest version

V4.2.0

Top

All features have IntelliSense. PromptPlus has more than 25 controls with many features like: filters, validators, history, suggestions, spinner(19 embedding type and plus custom yours!), colors and styles for control-elements :

All controls have the same organization (see in action: Controls Snapshot):

PromptPlus driver console Supports 4/8/24-bit colors in the terminal with auto-detection of the current terminal's capabilities.

Migrate Version

Top

Until version 3 the console engine was based on a model from another project. PromptPlus v4 has been completely rebuilt for a better experience, with significant improvements with new controls and more developer power. The console driver now supports better rendering, with the ability to detect terminal capabilities and allow for 24-bit color, text overflow strategies based on terminal size, and left and right margins for a nicer layout. The Controls have been revised to be more responsive, allow color styles in many of their elements, and adapt to the terminal size even with resizing.

For migrate V3.3 to V4.0 see this link.

Console Engine

Top

The console driver has the ability to detect terminal capabilities and allow for 24-bit color and text overflow strategies based on terminal size, and left and right margins for a nicer layout and automatic color conversion. The new engine detects support ansi commands and adjust output for this functionality respecting OS differences , terminal mode and Windows console mode. The Colors are automatically adjusted to the capacity of the terminal. This automatic adjustment may slightly modify the final color when converting to a lower bit resolution.

Sample Output detect (ConsoleFeaturesSamples)

Sample Output Overflow Capacity (ConsoleFeaturesSamples)

Sample color capacity (ConsoleFeaturesSamples)

Note: This layout and code were based (code copy and adaptation) on the excellent project: spectrum console, having the same color palette

Installing

Top

Install-Package PromptPlus [-pre]
dotnet add package PromptPlus [--prerelease]

Note: [-pre]/[--prerelease] usage for pre-release versions

Examples

Top

The folder Samples contains more 40 samples!.

dotnet run --project [name of sample]

Controls Snapshot

AddToList

Top | Samples

Top | Samples

AlternateScreen

Top | Samples

AutoComplete

Top | Samples

Banner

Top | Samples

Browser

Top | Samples

Top | Samples

Calendar

Top | Samples

ChartBar

Top | Samples

Confirm

Top | Samples

Console Features

Top | Samples

Input

Top | Samples

Top | Samples

Top | Samples

Top | Samples

Top | Samples

KeyPress

Top | Samples

MaskEdit

Top | Samples

Top | Samples

Top | Samples

Top | Samples

Top | Samples

Top | Samples

MultSelect

Top | Samples

ProgressBar

Top | Samples

Select

Top | Samples

SliderNumber

Top | Samples

Top | Samples

SliderSwitch

Top | Samples

Table

Top | Samples

Top | Samples

Top | Samples

TreeView

Top | Samples

Top | Samples

Wait Tasks

Top | Samples

Wait Timer

Top | Samples

Usage

Top

All controls use fluent interface; an object-oriented API whose design relies extensively on method chaining. Its goal is to increase code legibility. The term was coined in 2005 by Eric Evans and Martin Fowler.

//MaskEdit Generic
var mask = PromptPlus.MaskEdit("input", "MaskEdit Generic input")
    .Mask(@"\XYZ 9{3}-L{3}-C[ABC]N{1}[XYZ]-A{3}")
    .ShowTipInputType(FormatWeek.Short)
    .Run();

if (!mask.IsAborted)
{
    PromptPlus.WriteLine($"You input with mask is {mask.Value.Masked}");
    PromptPlus.WriteLine($"You input without mask is {mask.Value.Input}");
}

//AnyKey
var kp1 = PromptPlus
    .KeyPress()
    .Run();

if (!kp1.IsAborted)
{
    PromptPlus.WriteLine($"You Pressed {kp1.Value.Key}");
}

//input
var in1 = PromptPlus
    .Input("Input sample1")
    .Run();

if (!in1.IsAborted)
{
    PromptPlus.WriteLine($"You input is {in1.Value}");
}

Culture

Top

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 embedded:

To use a non-embedded language/culture:

Colors

Top

PromptPlus is in accordance with informal standard NO COLOR. when there is the environment variable "no_color" the colors are disabled.

Prompt Plus also has commands for coloring parts of the text.

Direct console

PromptPlus.WriteLine("[RGB(255,0,0) ON WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[RGB(255,0,0):WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[#ff0000 ON WHITE]Test [YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[RED ON WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[RED:WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");

Using Style

PromptPlus.WriteLine("Test", new Style(Color.White, Color.Red, Overflow.None));
PromptPlus.WriteLine("Test", new Style(new Color(255, 255, 255), Color.Red, Overflow.None));
PromptPlus.WriteLine("Test", new Style(Color.FromConsoleColor(ConsoleColor.White), Color.Red, Overflow.None));
PromptPlus.WriteLine("Test", new Style(Color.FromInt32(255), Color.Red, Overflow.None));

Over controls

PromptPlus
    .Input("Input [blue]sample2[/]", "with [yellow]description[/]")
    .Run();

Escaping format characters

To output a [ you use [[, and to output a ] you use ]].

PromptPlus.WriteLine("[[Test]]");

using (PromptPlus.EscapeColorTokens())
{
   PromptPlus.DoubleDash($"PromptPlus with context IgnoreColorTokens = true");
   //show text without color
   PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
}

Promptplus uses the same default colors and engine(softly modified) as the third party project: spectreconsole. For more details visit the official page or see the samples in folder Samples/ConsoleFeaturesSamples

Hotkeys

Top

Hotkeys (global and control-specific) are configurable. Some hotkeys are internal and reserved. For more details visit the official page

Keypress Extensions Emacs

Top

PromptPlus have a lot extensions to check Key-press with GNU Readline Emacs keyboard shortcuts. For more details visit the official page

Validators

PromptPlus have a lot extensions to commons validator and validator import(No duplicate code!) For more details visit the official page or see the samples in folder Samples

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();

PromptPlus
    .Input("Input sample2", "import validator from decorate")
    .Default(inst.Text)
    .AddValidators(PromptValidators.ImportValidators(inst,x => x!.Text!))
    .Run();

if (name.IsAborted)
{
   return;
}
PromptPlus.WriteLine($"Your input: {name.Value}!");

Supported platforms

Top

Code of Conduct

Top

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the Code of Conduct.

Contributing

See the Contributing guide for developer documentation.

Credits

Top

PromptPlus includes code(Copy) from other software released under the MIT license:

EastAsian width generated by package

API documentation generated by

License

Top

Copyright 2021 @ Fernando Cerqueira

PromptPlus is licensed under the MIT license. See LICENSE.