Introduction to Sharprompt
Sharprompt is an interactive command-line application framework designed with C# developers in mind. It provides a user-friendly way to create command-line interfaces that can prompt users for information, confirm actions, and handle input validation seamlessly.
Key Features
- Multi-Platform Support: Sharprompt runs smoothly across different operating systems, including Windows, Linux, and macOS.
- Diverse Prompt Options: It supports a wide variety of prompts such as
Input
,Password
,Select
, among others, allowing developers to interact with users organically. - Model-Based Prompts: Developers can leverage model-based prompts for intuitive data capture.
- Input Validation: Built-in capabilities ensure inputs meet specific criteria such as length or required fields.
- Enum Auto-Generation: It can automatically generate data sources with the Enum type, simplifying option lists.
- Customizable UI: Developers can personalize symbols and color schemes to match their application's style.
- Unicode Support: The framework includes support for multi-byte characters and emoji, enhancing global and expressive interactions.
Installation Guide
To integrate Sharprompt into a project, developers can use NuGet package manager with the following commands:
Install-Package Sharprompt
dotnet add package Sharprompt
Usage Overview
Simple Inputs
Sharprompt makes capturing user inputs straightforward. Here's an example capturing a user's name:
var name = Prompt.Input<string>("What's your name?");
Console.WriteLine($"Hello, {name}!");
Password Inputs
It easily captures sensitive information securely:
var secret = Prompt.Password("Type new password", validators: new[] { Validators.Required(), Validators.MinLength(8) });
Console.WriteLine("Password OK");
Confirmations
Perfect for getting user approval:
var answer = Prompt.Confirm("Are you ready?", defaultValue: true);
Console.WriteLine($"Your answer is {answer}");
Prompt Types Explained
Here are some of the primary prompts that Sharprompt offers:
- Input Prompt: Captures data of a specified type from the user and performs necessary type conversions.
- Confirm Prompt: Allows users to answer yes or no questions.
- Password Prompt: Seals confidential information input, masking it from onlookers.
- Select and MultiSelect Prompts: Provide single or multiple choice selections.
- List Prompt: Lets users generate a list of items dynamically.
Advanced Configurations
Sharprompt isn't just versatile; it's highly flexible:
- Custom Symbols: Tailor the look and feel by setting custom symbols.
- Color Schemes: Modify the color schema for a personalized user interface.
- Cancellation Support: Developers can handle cancellations gracefully by throwing exceptions.
Support for Enum Types
Sharprompt can generate options from Enums, offering a hassle-free way to present choices to users:
var value = Prompt.Select<MyEnum>("Select enum value");
Console.WriteLine($"You selected {value}");
Unicode and Fluent Interface
With advanced Unicode support, Sharprompt handles UTF-8 encoded characters smoothly, making it ideal for multilingual applications. Additionally, its fluent interface allows for concise and readable prompt configurations.
Supported Platforms
Sharprompt is compatible with:
- Windows: Integrates with Command Prompt, PowerShell, and Windows Terminal.
- Linux: Supports platforms like Ubuntu through Windows Terminal on WSL 2.
- macOS: Functions with Terminal.app.
License
The project is open-source, available under the MIT License, ensuring that developers can adapt and integrate it into their applications without concerns about licensing restrictions.
Overall, Sharprompt stands out as a robust framework for developers looking to enhance command-line interactions in their applications, offering a blend of simplicity, flexibility, and power.