Giter Club home page Giter Club logo

promptplus's Introduction

Welcome to PromptPlus

Build Publish License

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.

NuGet Downloads

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

NuGet Downloads

PromptPlus.CommandDotNet!!

Innovative middleware policy for CommandDotNet with PromptPlus.CommandDotNet:

  • 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.

Official pages :

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

Examples

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]

Snapshot

Input

MaskEdit

Top

KeyPress

Top

Selectors

Top

Confirm

Top

WaitProcess

Top

ProgressBar

Top

Slider Number

Top

List

Top

Browser

Top

PipeLine

Top

Banner

Top

Colors

Top

Commands

Top

Usage

PromptPlus.CommandDotNet

Top

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

PromptPlus.CommandDotNet

Top

//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}!");

Install

Top

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

Organization

Top

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.

Paging behavior

Top

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)

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 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.

Colors

Top

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

Symbols

Top

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

Top

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;

Load and Save Settings

Top

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

Apis

Top

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

Extensions

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}!");

Supported platforms

Top

  • Windows
    • Command Prompt, PowerShell, Windows Terminal
  • Linux (Ubuntu, etc)
    • Windows Terminal (WSL 2)
  • macOS
    • Terminal.app

Inspiration notes

License

This project is licensed under the MIT License

promptplus's People

Contributors

fracerqueira avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.