MiJenner.ConsoleUtils 0.14.0

dotnet add package MiJenner.ConsoleUtils --version 0.14.0
                    
NuGet\Install-Package MiJenner.ConsoleUtils -Version 0.14.0
                    
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="MiJenner.ConsoleUtils" Version="0.14.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiJenner.ConsoleUtils" Version="0.14.0" />
                    
Directory.Packages.props
<PackageReference Include="MiJenner.ConsoleUtils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MiJenner.ConsoleUtils --version 0.14.0
                    
#r "nuget: MiJenner.ConsoleUtils, 0.14.0"
                    
#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.
#:package MiJenner.ConsoleUtils@0.14.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MiJenner.ConsoleUtils&version=0.14.0
                    
Install as a Cake Addin
#tool nuget:?package=MiJenner.ConsoleUtils&version=0.14.0
                    
Install as a Cake Tool

MiJenner.ConsoleUtils

ConsoleUtils offer cross-platform utilities for easy interaction with a user.

There are methods for persistent reading of values of a certain data type from the console user. Pattern is Read<datatype>(). They prompt the user, and keep asking user for a value of a certain data type until she/he enters a correct data type. It offers methods for integers, doubles, decimals, boolean, dates, and enums.

There is a method for reading in multiple lines of text from the user StringReadMultipleLines().

There are methods for removing non-letters from strings: StringRemoveNonLettersENG(...) and StringRemoveNonLettersAll(...).

Finally there are methods for opening file explorer in current directory OpenExplorerFinder()

Method Signatures

Below is listed the signatures of the methods:

public static void OpenExplorerFinder()
public static void OpenExplorerFinderPath(string folderPath)
public static bool ReadBoolean(string prompt, string errorMessage, string trueValue = "j", string falseValue = "n")
public static DateTime ReadDate(string prompt, string errorMessage)
public static decimal ReadDecimal(string prompt, string errorMessage)
public static double ReadDouble(string prompt, string errorMessage)
public static int ReadInt(string prompt, string errorMessage)
static public string ReadLineWithEdit(string origText)
public static string ReadStringFromArray(string prompt, string errorMessage, string[] strings)
public static string ReadStringFromList(string prompt, string errorMessage, List<string> strings)
public static T ReadEnum<T>(string prompt, string errorMessage) where T : struct, Enum
public static TKey ReadDictKey<TKey, TValue>(string prompt, string errorMessage, Dictionary<TKey, TValue> dict, bool DisplayOptions = true, string OptionText = "Options: ")
public static string StringRemoveNonLettersENG(string input)
public static string StringRemoveNonLettersAll(string input)
public static string StringReadMultipleLines(string prompt, string instruction = "Type 3 empty lines to end")
public static bool TryReadDataType<T>(out T result)

Examples

First, remember to to add a using instruction:

using MiJenner;

Below are examples on how the library can be used:

ConsoleUtils.OpenExplorerFinder();
ConsoleUtils.OpenExplorerFinderPath("."); 
var a = ConsoleUtils.ReadInt("Please provide an integer", "No, please provide an integer");
var b = ConsoleUtils.ReadDouble("Please provide a floating point number", "No, please provide a floating point number");
var c = ConsoleUtils.ReadDate("Please provide a date", "No, please provide a date");
var d = ConsoleUtils.ReadBoolean("Please provide a boolean", "No, please provide a boolean", "t", "f");
var e = ConsoleUtils.ReadEnum<MyEnum>("Please provide an enum, MyEnum", "No, please provide an enum, MyEnum");

var choicesString = new Dictionary<string, string>
   {  {"Left", "Option 1" }, {"Right", "Option 2" }, {"Back", "Option 3" } };

var f = ConsoleUtils.ReadDictKey<string, string>("Type dict key (string)", "Nope", choicesString);

var choicesInt = new Dictionary<int, string>
   { {1, "Option 1" }, {2, "Option 2" }, {3, "Option 3" } };

var g = ConsoleUtils.ReadDictKey<int, string>("Type dict key (int)", "Nope", choicesInt);

string text = "Here is some text";
Console.WriteLine("Original text : " + text);
Console.Write("Edit the text : ");
text = ConsoleUtils.ReadLineWithEdit(text);
Console.WriteLine("After editing : " + text);

Nuget package

There is a nuget package available for easy usage.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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
0.14.0 207 9/18/2023
0.12.0 155 9/18/2023
0.11.0 169 9/12/2023
0.10.0 180 9/11/2023
0.9.0 188 9/9/2023

Added ReadDictKey() and TryReadDataType()