ConsoleUserInteractionHelper 4.0.0
dotnet add package ConsoleUserInteractionHelper --version 4.0.0
NuGet\Install-Package ConsoleUserInteractionHelper -Version 4.0.0
<PackageReference Include="ConsoleUserInteractionHelper" Version="4.0.0" />
paket add ConsoleUserInteractionHelper --version 4.0.0
#r "nuget: ConsoleUserInteractionHelper, 4.0.0"
// Install ConsoleUserInteractionHelper as a Cake Addin #addin nuget:?package=ConsoleUserInteractionHelper&version=4.0.0 // Install ConsoleUserInteractionHelper as a Cake Tool #tool nuget:?package=ConsoleUserInteractionHelper&version=4.0.0
Package Description
ConsoleHelper is a versatile .NET library designed to simplify console-based user interactions. It provides a rich set of methods to handle various input scenarios, from simple string inputs to complex numeric constraints.
Key Features
- Robust Input Handling: Gracefully manage user inputs with built-in validation and error handling.
- Flexible Numeric Inputs: Easily obtain integer values with custom constraints.
- Secure String Input: Collect sensitive information without displaying it on the console.
- Progress Indication: Display spinner animations for long-running operations.
- Customizable Retry Logic: Control the number of retry attempts for each input operation.
Installation
Install ConsoleHelper via NuGet Package Manager:
Install-Package ConsoleUserInteractionHelper
Or via .NET CLI:
dotnet add package ConsoleUserInteractionHelper
Usage Examples
Here are some examples to demonstrate the versatility of ConsoleHelper:
using ConsoleUserInteractionHelper;
var helper = new ConsoleHelper();
// Get a non-empty string
string name = helper.GetNonEmptyStringFromUser();
// Get a positive integer with max 3 retry attempts
int age = helper.GetPositiveInt(maxRetries: 3);
// Use custom constraints for integer input
int evenNumber = helper.GetIntWithConstraints(
n => n % 2 == 0,
"Please enter an even number."
);
// Collect a password securely
string password = helper.GetSecretStringFromUser();
// Display a spinner during a long operation
Task longRunningTask = SomeLongRunningOperation();
helper.ShowSpinnerUntilTaskIsRunning(longRunningTask);
// Get a file path with specific extension
string filePath = helper.GetPathToExistingFileFromUser(".txt");
Extensibility
ConsoleHelper is designed with extensibility in mind. You can easily create custom input methods using the generic GetIntWithConstraints
method:
// Custom method to get a prime number
public int GetPrimeNumber(int? maxRetries = null)
{
return GetIntWithConstraints(
n => IsPrime(n),
"Please enter a prime number.",
maxRetries
);
}
private bool IsPrime(int number)
{
if (number < 2) return false;
for (int i = 2; i <= Math.Sqrt(number); i++)
{
if (number % i == 0) return false;
}
return true;
}
Contributing
We welcome contributions! Please see our Contributing Guidelines for more details.
License
ConsoleHelper is released under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Goblinfactory.Konsole (>= 6.2.2)
- ProgressReporting (>= 2.1.0)
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 |
---|---|---|
4.0.0 | 385 | 9/10/2024 |
3.4.1 | 244 | 8/30/2023 |
3.3.0 | 348 | 11/18/2021 |
3.2.3 | 324 | 11/7/2021 |
3.2.2 | 353 | 11/7/2021 |
3.2.1 | 309 | 11/4/2021 |
3.2.0 | 339 | 11/4/2021 |
3.1.0 | 323 | 11/3/2021 |
3.0.0 | 334 | 11/3/2021 |
2.2.0 | 383 | 2/20/2021 |
2.1.0 | 381 | 2/14/2021 |
2.0.0 | 999 | 10/8/2018 |
1.1.0 | 786 | 10/7/2018 |
1.0.0 | 771 | 10/7/2018 |
# ConsoleUserInteractionHelper
## Release Notes (v4.0.0)
This major update brings significant improvements and new features to enhance your console application development experience.
### What's New
- **Generic Integer Input Method**: Introduced `GetIntWithConstraints` for flexible integer input handling.
- **Optional Max Retries**: All input methods now support an optional maximum retry limit.
- **Improved Error Handling**: Enhanced error messages and consistency across all methods.
### Breaking Changes
- Signature changes to existing methods to incorporate the optional `maxRetries` parameter.