Skip to content

Latest commit

 

History

History
488 lines (278 loc) · 34.3 KB

File metadata and controls

488 lines (278 loc) · 34.3 KB

ConsolePlus

ConsolePlusExtends Class

Extension methods for ConsolePlus, providing additional functionality to the IConsole interface.

public static class ConsolePlusExtends

Inheritance System.Object → ConsolePlusExtends

Methods

ConsolePlusExtends.ActionBeforeExist(this IConsole, Action<IConsole,Exception,bool>) Method

Registers a callback action to be invoked before the console exits, allowing for custom cleanup or final output. The action receives the current console instance and a boolean indicating if Ctrl+C was pressed as parameters.

public static void ActionBeforeExist(this ConsolePlusLibrary.IConsole console, System.Action<ConsolePlusLibrary.IConsole,System.Exception?,bool> action);

Parameters

console IConsole

The console instance to operate on.

action System.Action<IConsole,System.Exception,System.Boolean>

The action to be invoked before the console exits.

ConsolePlusExtends.Banner(this IConsole, string, string, Nullable<Style>, DashOptions) Method

Draws a banner in the console with the specified text, font, dash options, and style. A banner is a decorative element that can be used to highlight important information or create visual separation in the console output. The method allows you to customize the appearance of the banner using different fonts, dash options, and styles. The font is specified by providing the path to a FIGlet font file, which defines how the characters in the banner will be rendered.

public static void Banner(this ConsolePlusLibrary.IConsole console, string? text, string pathfontFiglet, System.Nullable<ConsolePlusLibrary.Style> style=null, ConsolePlusLibrary.DashOptions dashOptions=ConsolePlusLibrary.DashOptions.None);

Parameters

console IConsole

The console instance to operate on.

text System.String

The text to display within the banner. If null, only the dashes are displayed.

pathfontFiglet System.String

The path to the FIGlet font file to use for rendering the banner text.

style System.Nullable<Style>

The style to apply to the banner. If null, the default style is used.

dashOptions DashOptions

The options for the banner, such as border style.

ConsolePlusExtends.Banner(this IConsole, string, Stream, Nullable<Style>, DashOptions) Method

Draws a banner in the console with the specified text, font stream, dash options, and style. A banner is a decorative element that can be used to highlight important information or create visual separation in the console output. The method allows you to customize the appearance of the banner using different fonts, dash options, and styles. The font is specified by providing a stream containing a FIGlet font file, which defines how the characters in the banner will be rendered.

public static void Banner(this ConsolePlusLibrary.IConsole console, string? text, System.IO.Stream streamFontFiglet, System.Nullable<ConsolePlusLibrary.Style> style=null, ConsolePlusLibrary.DashOptions dashOptions=ConsolePlusLibrary.DashOptions.None);

Parameters

console IConsole

The console instance to operate on.

text System.String

The text to display within the banner. If null, only the dashes are displayed.

streamFontFiglet System.IO.Stream

The stream containing the FIGlet font file to use for rendering the banner text.

style System.Nullable<Style>

The style to apply to the banner. If null, the default style is used.

dashOptions DashOptions

The options for the banner, such as border style.

ConsolePlusExtends.Banner(this IConsole, string, Nullable<Style>, DashOptions) Method

Draws a banner in the console with the specified text, dash options, and style. A banner is a decorative element that can be used to highlight important information or create visual separation in the console output. The method allows you to customize the appearance of the banner using different dash options and styles.

public static void Banner(this ConsolePlusLibrary.IConsole console, string? text, System.Nullable<ConsolePlusLibrary.Style> style=null, ConsolePlusLibrary.DashOptions dashOptions=ConsolePlusLibrary.DashOptions.None);

Parameters

console IConsole

The console instance to operate on.

text System.String

The text to display within the banner. If null, only the dashes are displayed.

style System.Nullable<Style>

The style to apply to the banner. If null, the default style is used.

dashOptions DashOptions

The options for the banner, such as border style.

ConsolePlusExtends.ClearLine(this IConsole, Nullable<int>, Nullable<Style>) Method

Clears the current line in the console, optionally allowing you to specify a different row and style for the cleared line. This can be useful for updating output in place or removing unwanted text from the console.

public static void ClearLine(this ConsolePlusLibrary.IConsole console, System.Nullable<int> row=null, System.Nullable<ConsolePlusLibrary.Style> style=null);

Parameters

console IConsole

The console instance to operate on.

row System.Nullable<System.Int32>

The row number of the line to clear. If null, the current line is cleared.

style System.Nullable<Style>

The style to apply to the cleared line. If null, the default style is used.

ConsolePlusExtends.Dash(this IConsole, string, DashOptions, Nullable<Style>, int, bool) Method

Draws a dashed line in the console with the specified text, dash options, and style.

public static void Dash(this ConsolePlusLibrary.IConsole console, string? text, ConsolePlusLibrary.DashOptions dashOptions=ConsolePlusLibrary.DashOptions.SingleBorder, System.Nullable<ConsolePlusLibrary.Style> style=null, int extralines=0, bool applycolorbackground=false);

Parameters

console IConsole

The console instance to operate on.

text System.String

The text to display within the dashed line. If null, only the dashes are displayed.

dashOptions DashOptions

The options for the dashed line, such as border style.

style System.Nullable<Style>

The style to apply to the dashed line. If null, the default style is used.

extralines System.Int32

The number of extra blank lines to append after the dashed line.

applycolorbackground System.Boolean

If true, applies the background color across the full line.

ConsolePlusExtends.OutputError(this IConsole) Method

Redirects the console output to the error stream, allowing you to capture and handle error messages separately from standard output. This can be particularly useful for logging errors or displaying error messages in a different format or color. The method returns an IDisposable that, when disposed, will restore the original console output stream.

public static System.IDisposable OutputError(this ConsolePlusLibrary.IConsole console);

Parameters

console IConsole

The console instance to operate on.

Returns

System.IDisposable
An IDisposable that restores the original console output stream when disposed.

ConsolePlusExtends.ReadInlineEmacs(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>) Method

Reads input from the console using Emacs-style key bindings, allowing for more efficient and familiar text editing capabilities. This method provides an enhanced input experience for users who are accustomed to Emacs key bindings, enabling them to navigate and edit their input more effectively. The method returns input entered by the user as a string after the Enter key is pressed.

public static string ReadInlineEmacs(this ConsolePlusLibrary.IConsole console, System.Func<char,bool>? acceptInput=null, ConsolePlusLibrary.CaseOptions caseOptions=ConsolePlusLibrary.CaseOptions.Any, int maxlength=int.MaxValue, System.Nullable<ConsolePlusLibrary.Style> style=null);

Parameters

console IConsole

The console instance to operate on.

acceptInput System.Func<System.Char,System.Boolean>

A function to determine whether a character is accepted as input.

caseOptions CaseOptions

Specifies the case options for the input.

maxlength System.Int32

Specifies the maximum length of the input.

style System.Nullable<Style>

The style to apply to the input.

Returns

System.String
The line of input entered by the user as a string.

ConsolePlusExtends.ReadInlineEmacsAsync(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>, CancellationToken) Method

Reads input from the console using Emacs-style key bindings, allowing for more efficient and familiar text editing capabilities. This method provides an enhanced input experience for users who are accustomed to Emacs key bindings, enabling them to navigate and edit their input more effectively. The method returns the input entered by the user as a string after the Enter key is pressed.

public static System.Threading.Tasks.Task<string?> ReadInlineEmacsAsync(this ConsolePlusLibrary.IConsole console, System.Func<char,bool>? acceptInput=null, ConsolePlusLibrary.CaseOptions caseOptions=ConsolePlusLibrary.CaseOptions.Any, int maxlength=int.MaxValue, System.Nullable<ConsolePlusLibrary.Style> style=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

console IConsole

The console instance to operate on.

acceptInput System.Func<System.Char,System.Boolean>

A function to determine whether a character is accepted as input.

caseOptions CaseOptions

Specifies the case options for the input.

maxlength System.Int32

Specifies the maximum length of the input.

style System.Nullable<Style>

The style to apply to the input.

cancellationToken System.Threading.CancellationToken

A token to monitor for cancellation requests.

Returns

System.Threading.Tasks.Task<System.String>
The line of input entered by the user as a string.

ConsolePlusExtends.ReadLineEmacs(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>) Method

Reads a line of input from the console using Emacs-style key bindings, allowing for more efficient and familiar text editing capabilities. This method provides an enhanced input experience for users who are accustomed to Emacs key bindings, enabling them to navigate and edit their input more effectively. The method returns the line of input entered by the user as a string after the Enter key is pressed.

public static string ReadLineEmacs(this ConsolePlusLibrary.IConsole console, System.Func<char,bool>? acceptInput=null, ConsolePlusLibrary.CaseOptions caseOptions=ConsolePlusLibrary.CaseOptions.Any, int maxlength=int.MaxValue, System.Nullable<ConsolePlusLibrary.Style> style=null);

Parameters

console IConsole

The console instance to operate on.

acceptInput System.Func<System.Char,System.Boolean>

A function to determine whether a character is accepted as input.

caseOptions CaseOptions

Specifies the case options for the input.

maxlength System.Int32

Specifies the maximum length of the input.

style System.Nullable<Style>

The style to apply to the input.

Returns

System.String
The line of input entered by the user as a string.

Remarks

the new line is not included in the result, but it is included in the console output. If you want to read a line of input without including the new line in the console output, you can use the ReadInlineEmacs(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>) method instead.

ConsolePlusExtends.ReadLineEmacsAsync(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>, CancellationToken) Method

Reads a line of input from the console using Emacs-style key bindings, allowing for more efficient and familiar text editing capabilities. This method provides an enhanced input experience for users who are accustomed to Emacs key bindings, enabling them to navigate and edit their input more effectively. The method returns the line of input entered by the user as a string after the Enter key is pressed.

public static System.Threading.Tasks.Task<string?> ReadLineEmacsAsync(this ConsolePlusLibrary.IConsole console, System.Func<char,bool>? acceptInput=null, ConsolePlusLibrary.CaseOptions caseOptions=ConsolePlusLibrary.CaseOptions.Any, int maxlength=int.MaxValue, System.Nullable<ConsolePlusLibrary.Style> style=null, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

Parameters

console IConsole

The console instance to operate on.

acceptInput System.Func<System.Char,System.Boolean>

A function to determine whether a character is accepted as input.

caseOptions CaseOptions

Specifies the case options for the input.

maxlength System.Int32

Specifies the maximum length of the input.

style System.Nullable<Style>

The style to apply to the input.

cancellationToken System.Threading.CancellationToken

A token to monitor for cancellation requests.

Returns

System.Threading.Tasks.Task<System.String>
The line of input entered by the user as a string.

Remarks

the new line is not included in the result, but it is included in the console output. If you want to read a line of input without including the new line in the console output, you can use the ReadInlineEmacsAsync(this IConsole, Func<char,bool>, CaseOptions, int, Nullable<Style>, CancellationToken) method instead.

ConsolePlusExtends.WriteLines(this IConsole, int) Method

Writes a specified number of empty lines to the console, allowing for better readability and separation of output.

public static void WriteLines(this ConsolePlusLibrary.IConsole console, int steps=1);

Parameters

console IConsole

The console instance to operate on.

steps System.Int32

The number of empty lines to write.