Table of Contents

Class CL

Namespace
SunamoCl
Assembly
SunamoCl.dll

Console logger and user interaction utilities

public class CL
Inheritance
CL
Inherited Members
Extension Methods

Properties

BufferWidth

Gets the width of the buffer area

public static int BufferWidth { get; }

Property Value

int

CursorLeft

Gets the column position of the cursor within the buffer area

public static int CursorLeft { get; }

Property Value

int

CursorTop

Gets the row position of the cursor within the buffer area

public static int CursorTop { get; }

Property Value

int

ErrorWriter

Gets the standard error output stream.

public static TextWriter ErrorWriter { get; }

Property Value

TextWriter

ForegroundColor

Gets or sets the foreground color of the console

public static ConsoleColor ForegroundColor { get; set; }

Property Value

ConsoleColor

IsInClipboard

Gets or sets whether writing to clipboard is in progress.

public static bool IsInClipboard { get; set; }

Property Value

bool

Out

Gets the standard output stream

public static TextWriter Out { get; }

Property Value

TextWriter

PressEnterWhenDataWillBeInClipboard

Message displayed when waiting for data to be copied to clipboard

public static string PressEnterWhenDataWillBeInClipboard { get; set; }

Property Value

string

ShouldPerform

Whether to perform actions or skip them

public static bool ShouldPerform { get; set; }

Property Value

bool

ShouldWriteToConsole

Gets or sets whether to write output to console. When false, all write operations are suppressed

public static bool ShouldWriteToConsole { get; set; }

Property Value

bool

Source

Gets or sets the current console source character.

public static char Source { get; set; }

Property Value

char

WindowHeight

Gets the height of the console window area

public static int WindowHeight { get; }

Property Value

int

WindowWidth

Gets the width of the console window

public static int WindowWidth { get; }

Property Value

int

Methods

Appeal(string)

Writes an appeal message to the console in magenta color

public static void Appeal(string text)

Parameters

text string

Appeal message text to write

AppealEnter(string)

Displays an appeal message and waits for user to press Enter.

public static Task AppealEnter(string appeal)

Parameters

appeal string

Appeal text to display.

Returns

Task

AppealWithCountdown(string, int)

Displays an appeal message with a countdown timer

public static void AppealWithCountdown(string message, int seconds)

Parameters

message string

Message to display

seconds int

Number of seconds for the countdown

AskForEnter(string, bool, string?)

Constructs a formatted prompt string asking user to enter data

public static string AskForEnter(string prompt, bool shouldAppendAfterEnter, string? returnWhenIsNotNull)

Parameters

prompt string

Text to display as prompt (without ending dot or colon)

shouldAppendAfterEnter bool

Whether to append "Enter" prefix to the prompt

returnWhenIsNotNull string

If not null, returns this value instead of constructing prompt

Returns

string

Formatted prompt string with instructions

AskForEnterWrite(string, bool)

Writes a prompt asking user to press Enter

public static void AskForEnterWrite(string prompt, bool shouldAppendAfterEnter)

Parameters

prompt string

Text to display as prompt (without ending dot or colon)

shouldAppendAfterEnter bool

Whether to append "Enter" text after the prompt

AskForFolder(string, bool)

Prompts user for a folder path, using debug value if in debug mode

public static string AskForFolder(string folderDebug, bool isDebug)

Parameters

folderDebug string

Folder path to use in debug mode

isDebug bool

Whether application is running in debug mode

Returns

string

Selected folder path

AskForFolderMaskRec(string, string, bool?, bool)

Prompts user for folder, file mask and recursion settings

public static (string folder, string mask, bool? isRecursive) AskForFolderMaskRec(string folderDebug, string maskDebug, bool? isRecursiveDebug, bool isDebug)

Parameters

folderDebug string

Folder path to use in debug mode

maskDebug string

File mask to use in debug mode

isRecursiveDebug bool?

Whether to search recursively in debug mode

isDebug bool

Whether application is running in debug mode

Returns

(string folder, string mask, bool? isRecursive)

Tuple containing folder path, file mask and recursion flag

AskForFolderMaskRecFiles(string, string, bool, bool)

Prompts user for folder, mask and recursion settings, then returns matching files

public static List<string> AskForFolderMaskRecFiles(string folderDebug, string maskDebug, bool isRecursiveDebug, bool isDebug)

Parameters

folderDebug string

Folder path to use in debug mode

maskDebug string

File mask to use in debug mode

isRecursiveDebug bool

Whether to search recursively in debug mode

isDebug bool

Whether application is running in debug mode

Returns

List<string>

List of file paths matching the criteria

ChangeColorOfConsoleAndWrite(TypeOfMessageCl, string, params object[])

Changes console color based on message type, writes text, then resets color to white

public static void ChangeColorOfConsoleAndWrite(TypeOfMessageCl messageType, string text, params object[] args)

Parameters

messageType TypeOfMessageCl

Type of message determining the color

text string

Text to write, can contain format placeholders

args object[]

Format arguments for the text

Clear()

Clears the console screen

public static void Clear()

ClearBehindLeftCursor(int)

Clears console text behind the left cursor. If leftCursorAddSpaces is negative, characters are removed.

public static void ClearBehindLeftCursor(int leftCursorAddSpaces)

Parameters

leftCursorAddSpaces int

Number of spaces to add (or remove if negative) from cursor position.

ClearCurrentConsoleLine()

Clears the current console line by writing spaces

public static void ClearCurrentConsoleLine()

CmdTable(IEnumerable<List<string>>)

Displays data in a formatted table

public static void CmdTable(IEnumerable<List<string>> rows)

Parameters

rows IEnumerable<List<string>>

Rows of data to display

DoYouWantToContinue(string?)

Asks the user whether they want to continue.

public static DialogResult DoYouWantToContinue(string? message)

Parameters

message string

Message to display, or null for default.

Returns

DialogResult

EndRunTime(bool)

Displays termination message and waits for user to press Enter.

public static void EndRunTime(bool isAttemptingToRepairError = false)

Parameters

isAttemptingToRepairError bool

Error(string, params string[])

For TextWriter use ErrorWriter

public static void Error(string text, params string[] args)

Parameters

text string

Error message text, can contain format placeholders

args string[]

Format arguments for the text

Information(string, params string[])

Writes an informational message to console in white color

public static void Information(string text, params string[] args)

Parameters

text string

Text to write, can contain format placeholders

args string[]

Format arguments for the text

InvokeFuncTaskOrAction(object)

Invokes either a synchronous Action or asynchronous Func<Task> delegate.

public static Task InvokeFuncTaskOrAction(object funcOrAction)

Parameters

funcOrAction object

Either an Action or Func<Task> to invoke.

Returns

Task

LoadFromClipboardOrConsole(string)

Asks user to provide data either via clipboard or manual console input.

public static string LoadFromClipboardOrConsole(string text)

Parameters

text string

Description of the expected data.

Returns

string

LoadFromClipboardOrConsoleInFormat(string, TextFormatDataCl)

Loads data from clipboard or prompts user for input, validating against the specified format.

public static string LoadFromClipboardOrConsoleInFormat(string promptText, TextFormatDataCl textFormat)

Parameters

promptText string

Prompt text to display.

textFormat TextFormatDataCl

Required text format definition.

Returns

string

Log(string, params object[])

Logs a formatted message to console

public static void Log(string message, params object[] objects)

Parameters

message string

Message format string

objects object[]

Format parameters

NoData()

Displays a "no data" message to the user.

public static void NoData()

Pair(string, string)

Displays a label-value pair

public static void Pair(string label, string value)

Parameters

label string

Label text

value string

Value text

PerformAction(Dictionary<string, EventHandler>, object)

Lets user select an action and runs it. Only needed when the application has its own Mode.cs. Otherwise, autorun at release is handled by RunWithRunArgs. EventHandler is correct here because EventHandler never has a Task return type.

public static void PerformAction(Dictionary<string, EventHandler> actions, object sender)

Parameters

actions Dictionary<string, EventHandler>

Dictionary of named actions.

sender object

Sender object passed to the event handler.

PerformActionAfterRunCalling(object, Func<Dictionary<string, Func<Task<Dictionary<string, object>>>>>, bool)

Performs a specific action based on mode after initial run calling, iterating through action groups to find a match

public static Task PerformActionAfterRunCalling(object mode, Func<Dictionary<string, Func<Task<Dictionary<string, object>>>>> addGroupOfActionsFunc, bool isPrintAllActions)

Parameters

mode object

The mode identifier to match against available actions

addGroupOfActionsFunc Func<Dictionary<string, Func<Task<Dictionary<string, object>>>>>

Function that returns grouped actions as nested dictionaries

isPrintAllActions bool

Whether to print all available actions to console

Returns

Task

PressAnyKeyToContinue()

Waits for user to press any key to continue

public static void PressAnyKeyToContinue()

PressEnterAfterInsertDataToClipboard(string)

Prompts user to press Enter after inserting data to clipboard.

public static Task PressEnterAfterInsertDataToClipboard(string what)

Parameters

what string

Description of data to insert.

Returns

Task

PressEnterToContinue2()

Waits for user to press Enter to continue

public static void PressEnterToContinue2()

PressEnterToContinue3()

Waits for user to press Q key to exit, blocking the main thread

public static void PressEnterToContinue3()

ReadLine()

Reads the next line of characters from the standard input stream

public static string? ReadLine()

Returns

string

The next line of characters, or null if no more lines are available

ResetColor()

Sets the foreground and background console colors to their defaults

public static void ResetColor()

SelectFile(string)

Returns the full path of the selected file, or null when the operation is cancelled.

public static string? SelectFile(string folder)

Parameters

folder string

Folder to list files from.

Returns

string

SelectFromVariants(Dictionary<string, Action>, string)

Displays a list of actions for user to select from

public static void SelectFromVariants(Dictionary<string, Action> actions, string appealMessage)

Parameters

actions Dictionary<string, Action>

Dictionary of action names and their implementations

appealMessage string

Message to display to the user

SelectFromVariants(List<string>, string)

Displays variants for user selection. Returns index of selected action, or int.MinValue when cancelled.

public static int SelectFromVariants(List<string> variants, string prompt)

Parameters

variants List<string>

List of options to choose from.

prompt string

Prompt text (without ending colon).

Returns

int

SelectFromVariantsString(List<string>, string)

Displays a list of variants for user selection and returns the selected variant as string

public static string SelectFromVariantsString(List<string> variants, string prompt)

Parameters

variants List<string>

List of string variants to choose from

prompt string

Text to display as selection prompt

Returns

string

The string value of the selected variant

SetColorOfConsole(TypeOfMessageCl)

Sets console foreground color based on message type

public static void SetColorOfConsole(TypeOfMessageCl messageType)

Parameters

messageType TypeOfMessageCl

Type of message determining the color

StartRunTime(string)

Displays a startup header with the given text wrapped in star characters.

public static string StartRunTime(string text)

Parameters

text string

Header text to display.

Returns

string

Success(string, params string[])

In every task - end

public static void Success(string text, params string[] args)

Parameters

text string

Success message text, can contain format placeholders

args string[]

Format arguments for the text

Timer()

Starts a countdown timer

public static void Timer()

UserCanType(string, bool, params string[])

Prompts user to type text with control over prompt formatting.

public static string UserCanType(string prompt, bool shouldAppendAfterEnter, params string[] acceptableTyping)

Parameters

prompt string

Text to display as prompt (without ending dot or colon).

shouldAppendAfterEnter bool

Whether to append "Enter" text to the prompt.

acceptableTyping string[]

Acceptable values user can enter.

Returns

string

User input string.

UserCanType(string, params string[])

Prompts user to type text, accepting only specific values or allowing empty input

public static string UserCanType(string prompt, params string[] acceptableTyping)

Parameters

prompt string

Text to display as prompt (without ending dot or colon)

acceptableTyping string[]

Acceptable values user can enter

Returns

string

User input string

UserMustType(string, string)

Prompts user to type text. Returns empty string on failure. Cannot load multi-line input. Returns the exact user input ("", -1, etc.) - the calling application must handle validation.

public static string UserMustType(string prompt, string prefix = "")

Parameters

prompt string

Text to display as prompt (without ending colon).

prefix string

Optional prefix text to prepend before the prompt.

Returns

string

UserMustTypeInFormat(string, TextFormatDataCl)

Prompts user to type text and validates it against required format, repeating until valid input is provided.

public static string UserMustTypeInFormat(string promptText, TextFormatDataCl textFormat)

Parameters

promptText string

Text to display as prompt.

textFormat TextFormatDataCl

Required format for the text.

Returns

string

User input that matches the required format.

UserMustTypeMultiLine(string, params string[])

Prompts user to enter multiple lines of text, stopping when a specific line is entered

public static string UserMustTypeMultiLine(string prompt, params string[] breakEnteringAfterEntered)

Parameters

prompt string

Text to display as prompt

breakEnteringAfterEntered string[]

Lines that will stop input when entered

Returns

string

All entered lines combined as a single trimmed string

UserMustTypeNumber(int)

Return int.MinValue when user force stop operation

public static int UserMustTypeNumber(int max)

Parameters

max int

Returns

int

UserMustTypeNumber(string, int)

Prompts user to type a number within range. Returns int.MinValue when user cancels.

public static int UserMustTypeNumber(string prompt, int max)

Parameters

prompt string

Text to display as prompt (without ending colon).

max int

Maximum allowed value.

Returns

int

UserMustTypeNumber(string, int, int)

Return int.MinValue when user force stop operation

public static int UserMustTypeNumber(string prompt, int max, int min)

Parameters

prompt string
max int
min int

Returns

int

UserMustTypeYesNo(string)

Prompts user for Yes/No input. Returns true for Y/1, false for N, null on ESC.

public static bool? UserMustTypeYesNo(string text)

Parameters

text string

Prompt text to display.

Returns

bool?

Warning(string, params string[])

In every task - Start

public static void Warning(string text, params string[] args)

Parameters

text string

Warning message text, can contain format placeholders

args string[]

Format arguments for the text

WorkingDirectoryFromArgs(string[], bool)

Determines the working directory from command-line arguments. Returns empty string if path does not exist.

public static string WorkingDirectoryFromArgs(string[] args, bool isTakingSecondIfMoreThanTwoParams)

Parameters

args string[]

Command line arguments.

isTakingSecondIfMoreThanTwoParams bool

Whether to use the second argument as working directory when more than two parameters are provided.

Returns

string

Working directory path with trailing slash.

Exceptions

Exception

Thrown when no mode argument is provided.

Write(char)

Writes a single character to console without a newline

public static void Write(char character)

Parameters

character char

Character to write

Write(string)

Writes a string to console without a newline

public static void Write(string value)

Parameters

value string

Text to write

Write(string, string, object)

Writes formatted output to console using format string and two parameters

public static void Write(string format, string firstArgument, object secondArgument)

Parameters

format string

Format string

firstArgument string

First format parameter

secondArgument object

Second format parameter

WriteColor(TypeOfMessageCl, string, params string[])

Writes colored text to console based on message type

public static void WriteColor(TypeOfMessageCl messageType, string text, params string[] args)

Parameters

messageType TypeOfMessageCl

Type of message determining the color

text string

Text to write, can contain format placeholders

args string[]

Format arguments for the text

WriteLine()

Writes a blank line to console

public static void WriteLine()

WriteLine(Exception)

Writes an exception message to console.

public static void WriteLine(Exception exception)

Parameters

exception Exception

Exception to write.

WriteLine(int)

Writes a number to console as a line

public static void WriteLine(int number)

Parameters

number int

Number to write

WriteLine(string)

Writes a line of text to console

public static void WriteLine(string text)

Parameters

text string

Text to write

WriteLine(string, params object[])

Writes a formatted line to console

public static void WriteLine(string message, params object[] objects)

Parameters

message string

Message format string

objects object[]

Format parameters

WriteLineFormat(string, params object[])

Writes a blank line followed by a formatted line to console

public static void WriteLineFormat(string text, params object[] parameters)

Parameters

text string

Format string

parameters object[]

Format parameters

WriteLineObject(object)

Writes an object as string to console. Uses ToString() which may have lower performance.

public static void WriteLineObject(object value)

Parameters

value object

Object to write.

WriteLineWithColor(ConsoleColor, string)

Writes a line to console in a specific color, then resets to default color

public static void WriteLineWithColor(ConsoleColor color, string value)

Parameters

color ConsoleColor

Color to use for the text

value string

Text to write

WriteList(IEnumerable<string>, string?, WriteListArgs?)

Writes a list of items to console with optional header and formatting

public static void WriteList(IEnumerable<string> listItems, string? header = null, WriteListArgs? arguments = null)

Parameters

listItems IEnumerable<string>

Items to write

header string

Optional header to display before the list

arguments WriteListArgs

Optional formatting arguments for the list

WriteTimeLeft()

Writes the current time left value at a fixed position on the console

public static void WriteTimeLeft()

WriteTimeLeft(object?, ElapsedEventArgs)

Event handler that updates the countdown display on each timer tick

public static void WriteTimeLeft(object? source, ElapsedEventArgs e)

Parameters

source object

Timer source object

e ElapsedEventArgs

Event arguments