Rephidock.ConsolePrompts 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rephidock.ConsolePrompts --version 1.0.1                
NuGet\Install-Package Rephidock.ConsolePrompts -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rephidock.ConsolePrompts" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rephidock.ConsolePrompts --version 1.0.1                
#r "nuget: Rephidock.ConsolePrompts, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rephidock.ConsolePrompts as a Cake Addin
#addin nuget:?package=Rephidock.ConsolePrompts&version=1.0.1

// Install Rephidock.ConsolePrompts as a Cake Tool
#tool nuget:?package=Rephidock.ConsolePrompts&version=1.0.1                

Console Prompts

GitHub Licence Badge

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

image: example_prompt_age

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

image: example_styled_float

See Demo Project on the source repository for some other examples.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last updated
1.1.0 271 11/1/2023
1.0.1 114 10/20/2023
1.0.0 139 10/20/2023

- Added a bit more documentation
- (Breaking) Hid a lot of stuff that was not meant to be public (oopsy)
- (Breaking) Moved Prompt<T>.DefaultFormatProvider to Prompt.DefaultFormatProvider
- Internal changes