Show / Hide Table of Contents

Class ConsoleHelper

Contains static helper methods for .

Inheritance
System.Object
ConsoleHelper
Namespace: Towel
Assembly: Towel.dll
Syntax
public static class ConsoleHelper : object

Methods

| Improve this Doc View Source

AnimatedEllipsis(Func<Boolean>, Action, Int32)

Animates an elipsis in the console to indicate processing.

Declaration
public static void AnimatedEllipsis(Func<bool> condition, Action delay, int length = 3)
Parameters
Type Name Description
Func<System.Boolean> condition

The condition of the loop.

Action delay

The delay function.

System.Int32 length

The length of the ellipsis.

| Improve this Doc View Source

FlushInputBuffer(Boolean)

Flushes the console input buffer.

Declaration
public static void FlushInputBuffer(bool intercept = true)
Parameters
Type Name Description
System.Boolean intercept

Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.

| Improve this Doc View Source

GetInput<T>(Nullable<String>, Nullable<String>, Nullable<Func<String, (Boolean Success, T Value)>>, Nullable<Predicate<T>>)

Gets console input from the user.

Declaration
public static T GetInput<T>(string? prompt = null, string? invalidMessage = null, Func<string, (bool Success, T Value)>? tryParse = null, Predicate<T>? validation = null)
Parameters
Type Name Description
System.Nullable<System.String> prompt

The prompt message to display when requesting console input from the user.

System.Nullable<System.String> invalidMessage

The message to display if invalid input is detected.

System.Nullable<Func<System.String, System.ValueTuple<System.Boolean, T>>> tryParse

The method for converting into a T value.

System.Nullable<Predicate<T>> validation

The predicate for validating the value of the input.

Returns
Type Description
T

The validated value of the console input provided by the user.

Type Parameters
Name Description
T

The generic type of console input to get from the user.

| Improve this Doc View Source

HiddenReadLine(Char)

Similar to but with hidden input characters.

Declaration
public static string HiddenReadLine(char shownCharacter = '*')
Parameters
Type Name Description
System.Char shownCharacter

The display character to use for all input.

Returns
Type Description
System.String

The input provided by the user.

| Improve this Doc View Source

IntMenu(Nullable<String>, Nullable<String>, Nullable<String>, (String DisplayName, Action Action)[])

Prompts the user to select a menu option in the console before continuing.

Declaration
public static void IntMenu(string? title = null, string? prompt = null, string? invalidMessage = null, params (string DisplayName, Action Action)[] options)
Parameters
Type Name Description
System.Nullable<System.String> title

The title of the menu.

System.Nullable<System.String> prompt

The prompt message to display when requesting console input from the user.

System.Nullable<System.String> invalidMessage

The message to display if invalid input is detected.

System.ValueTuple<System.String, Action>[] options

The options of the menu.

| Improve this Doc View Source

IntMenu((String DisplayName, Action Action)[])

Prompts the user to select a menu option in the console before continuing.

Declaration
public static void IntMenu(params (string DisplayName, Action Action)[] options)
Parameters
Type Name Description
System.ValueTuple<System.String, Action>[] options

The options of the menu.

| Improve this Doc View Source

PressToContinue(ConsoleKey)

Prompts the user to press [enter] in the console before continuing.

Declaration
public static void PressToContinue(ConsoleKey key = null)
Parameters
Type Name Description
ConsoleKey key

The key to wait for the user to press before continuing.

| Improve this Doc View Source

ProgressBar(Action<Action<Double>>, Int32, Char, Char, Char, Char, Char, Boolean)

Displays a progress bar in the console.

Declaration
public static void ProgressBar(Action<Action<double>> action, int length = 17, char header = '[', char footer = ']', char done = '=', char remaining = '-', char errorDigit = '?', bool postClear = true)
Parameters
Type Name Description
Action<Action<System.Double>> action

The action to track the progress of.

System.Int32 length

The character length of the progress bar (must be >= 6).

System.Char header

The header character of the progress bar.

System.Char footer

The footer character of the progress bar.

System.Char done

The character for represening completed progress.

System.Char remaining

The character representing ongoing processing.

System.Char errorDigit

The characters to display in the numerical display when an invalid percentage is recieved.

System.Boolean postClear

Whether or not to clear the progress bar from the view when complete.

| Improve this Doc View Source

PromptPressToContinue(Nullable<String>, ConsoleKey)

Prompts the user to press [enter] in the console before continuing.

Declaration
public static void PromptPressToContinue(string? prompt = null, ConsoleKey key = null)
Parameters
Type Name Description
System.Nullable<System.String> prompt

The prompt to display to the user. Default: "Press [enter] to continue...".

ConsoleKey key

The key to wait for the user to press before continuing.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX