Skip to content

Commit

Permalink
Added prompt function.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Feb 1, 2024
1 parent d547eed commit 2f1965d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Hussy.Net/Hussy.Net.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=collections/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generators/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=input/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=linq/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=logic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=modules/@EntryIndexedValue">True</s:Boolean>
Expand Down
25 changes: 25 additions & 0 deletions src/Hussy.Net/Input/Prompt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Hussy.Net;

/// <summary>
/// Defines static methods for common programming tasks.
/// </summary>
public static partial class Hussy
{
/// <summary>
/// Prompts the user with a message and reads the user's response, parsing it into the specified type.
/// </summary>
/// <typeparam name="T">The type to parse the user's response into.</typeparam>
/// <param name="message">The message to display to the user.</param>
/// <param name="formatProvider">The format provider to use for parsing the response. If null, the default format provider is used.</param>
/// <returns>The parsed user's response of type T.</returns>
public static T P<T>(string message, IFormatProvider? formatProvider = null)
where T : IParsable<T>
{
Console.Write(message);
var response = Console.ReadLine();
if (!T.TryParse(response, formatProvider, out var parsedResponse))
throw new FormatException("Unable to parse response.");

return parsedResponse;
}
}

0 comments on commit 2f1965d

Please sign in to comment.