Rephidock.ConsolePrompts
1.1.0
dotnet add package Rephidock.ConsolePrompts --version 1.1.0
NuGet\Install-Package Rephidock.ConsolePrompts -Version 1.1.0
<PackageReference Include="Rephidock.ConsolePrompts" Version="1.1.0" />
paket add Rephidock.ConsolePrompts --version 1.1.0
#r "nuget: Rephidock.ConsolePrompts, 1.1.0"
// Install Rephidock.ConsolePrompts as a Cake Addin
#addin nuget:?package=Rephidock.ConsolePrompts&version=1.1.0
// Install Rephidock.ConsolePrompts as a Cake Tool
#tool nuget:?package=Rephidock.ConsolePrompts&version=1.1.0
Console Prompts
A small .NET library to take user input in a console with some exception handling and fluent syntax.
Features
- User input queries with fluent syntax
- Input restrictions (e.g. numeric range, string length, path to an existing file)
- Invalid input handling
- Prompt styling
- Support for
IParsable
Usage
Use the Prompt
class to create a query with one of the For
methods. Add limits to the query with fluent syntax and Display
the query to the user.
int userAge = Prompt.For<int>("Your age").NoLessThan(1).Display();
const int drinkingAge = 21;
if (userAge >= drinkingAge)
{
Console.WriteLine("You are of drinking age!");
}
else
{
Console.WriteLine("Sorry, you can't have a drink.");
}
Styling
The way prompts are displayed can be changed with PromptStyler
class.
PromptStyler.PromptFormat = "[{1}] {0} = ";
PromptStyler.InvalidInputFormat = "I can't accept that: {0}";
PromptStyler.HintLevel = PromptHintLevel.Verbose;
Console.WriteLine("f(x) = 60 + 10x");
float x = Prompt
.For<float>("x")
.ForceFinite()
.OfRange(0, 1)
.AddHint("real", PromptHintLevel.Verbose)
.Display();
Console.WriteLine($"f(x) = 60 + 10 * {x} = {60 + 10 * x}");
See Demo Project on the source repository for some other examples.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Minor update 1.1.0 change log:
- Added NotEqualTo input limiter
- Added type hints and type name replacement (optional, off by default)
- Added exception message replacement (optional, on by default)
- Added PromptInputException
- Prompt: Added ParseAndValidate for use outside of console
- Documentation clarifications and fixes
- Internal changes and testing