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
CursorLeft
Gets the column position of the cursor within the buffer area
public static int CursorLeft { get; }
Property Value
CursorTop
Gets the row position of the cursor within the buffer area
public static int CursorTop { get; }
Property Value
ErrorWriter
Gets the standard error output stream.
public static TextWriter ErrorWriter { get; }
Property Value
ForegroundColor
Gets or sets the foreground color of the console
public static ConsoleColor ForegroundColor { get; set; }
Property Value
IsInClipboard
Gets or sets whether writing to clipboard is in progress.
public static bool IsInClipboard { get; set; }
Property Value
Out
Gets the standard output stream
public static TextWriter Out { get; }
Property Value
PressEnterWhenDataWillBeInClipboard
Message displayed when waiting for data to be copied to clipboard
public static string PressEnterWhenDataWillBeInClipboard { get; set; }
Property Value
ShouldPerform
Whether to perform actions or skip them
public static bool ShouldPerform { get; set; }
Property Value
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
Source
Gets or sets the current console source character.
public static char Source { get; set; }
Property Value
WindowHeight
Gets the height of the console window area
public static int WindowHeight { get; }
Property Value
WindowWidth
Gets the width of the console window
public static int WindowWidth { get; }
Property Value
Methods
Appeal(string)
Writes an appeal message to the console in magenta color
public static void Appeal(string text)
Parameters
textstringAppeal message text to write
AppealEnter(string)
Displays an appeal message and waits for user to press Enter.
public static Task AppealEnter(string appeal)
Parameters
appealstringAppeal text to display.
Returns
AppealWithCountdown(string, int)
Displays an appeal message with a countdown timer
public static void AppealWithCountdown(string message, int seconds)
Parameters
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
promptstringText to display as prompt (without ending dot or colon)
shouldAppendAfterEnterboolWhether to append "Enter" prefix to the prompt
returnWhenIsNotNullstringIf 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
promptstringText to display as prompt (without ending dot or colon)
shouldAppendAfterEnterboolWhether 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
folderDebugstringFolder path to use in debug mode
isDebugboolWhether 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
folderDebugstringFolder path to use in debug mode
maskDebugstringFile mask to use in debug mode
isRecursiveDebugbool?Whether to search recursively in debug mode
isDebugboolWhether 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
folderDebugstringFolder path to use in debug mode
maskDebugstringFile mask to use in debug mode
isRecursiveDebugboolWhether to search recursively in debug mode
isDebugboolWhether application is running in debug mode
Returns
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
messageTypeTypeOfMessageClType of message determining the color
textstringText to write, can contain format placeholders
argsobject[]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
leftCursorAddSpacesintNumber 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
rowsIEnumerable<List<string>>Rows of data to display
DoYouWantToContinue(string?)
Asks the user whether they want to continue.
public static DialogResult DoYouWantToContinue(string? message)
Parameters
messagestringMessage to display, or null for default.
Returns
EndRunTime(bool)
Displays termination message and waits for user to press Enter.
public static void EndRunTime(bool isAttemptingToRepairError = false)
Parameters
isAttemptingToRepairErrorbool
Error(string, params string[])
For TextWriter use ErrorWriter
public static void Error(string text, params string[] args)
Parameters
textstringError message text, can contain format placeholders
argsstring[]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
textstringText to write, can contain format placeholders
argsstring[]Format arguments for the text
InvokeFuncTaskOrAction(object)
Invokes either a synchronous Action or asynchronous Func<Task> delegate.
public static Task InvokeFuncTaskOrAction(object funcOrAction)
Parameters
funcOrActionobjectEither an Action or Func<Task> to invoke.
Returns
LoadFromClipboardOrConsole(string)
Asks user to provide data either via clipboard or manual console input.
public static string LoadFromClipboardOrConsole(string text)
Parameters
textstringDescription of the expected data.
Returns
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
promptTextstringPrompt text to display.
textFormatTextFormatDataClRequired text format definition.
Returns
Log(string, params object[])
Logs a formatted message to console
public static void Log(string message, params object[] objects)
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
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
actionsDictionary<string, EventHandler>Dictionary of named actions.
senderobjectSender 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
modeobjectThe mode identifier to match against available actions
addGroupOfActionsFuncFunc<Dictionary<string, Func<Task<Dictionary<string, object>>>>>Function that returns grouped actions as nested dictionaries
isPrintAllActionsboolWhether to print all available actions to console
Returns
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
whatstringDescription of data to insert.
Returns
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
folderstringFolder to list files from.
Returns
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
actionsDictionary<string, Action>Dictionary of action names and their implementations
appealMessagestringMessage 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
variantsList<string>List of options to choose from.
promptstringPrompt text (without ending colon).
Returns
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
variantsList<string>List of string variants to choose from
promptstringText 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
messageTypeTypeOfMessageClType 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
textstringHeader text to display.
Returns
Success(string, params string[])
In every task - end
public static void Success(string text, params string[] args)
Parameters
textstringSuccess message text, can contain format placeholders
argsstring[]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
promptstringText to display as prompt (without ending dot or colon).
shouldAppendAfterEnterboolWhether to append "Enter" text to the prompt.
acceptableTypingstring[]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
promptstringText to display as prompt (without ending dot or colon)
acceptableTypingstring[]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
promptstringText to display as prompt (without ending colon).
prefixstringOptional prefix text to prepend before the prompt.
Returns
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
promptTextstringText to display as prompt.
textFormatTextFormatDataClRequired 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
promptstringText to display as prompt
breakEnteringAfterEnteredstring[]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
maxint
Returns
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
Returns
UserMustTypeNumber(string, int, int)
Return int.MinValue when user force stop operation
public static int UserMustTypeNumber(string prompt, int max, int min)
Parameters
Returns
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
textstringPrompt text to display.
Returns
- bool?
Warning(string, params string[])
In every task - Start
public static void Warning(string text, params string[] args)
Parameters
textstringWarning message text, can contain format placeholders
argsstring[]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
argsstring[]Command line arguments.
isTakingSecondIfMoreThanTwoParamsboolWhether 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
charactercharCharacter to write
Write(string)
Writes a string to console without a newline
public static void Write(string value)
Parameters
valuestringText 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
formatstringFormat string
firstArgumentstringFirst format parameter
secondArgumentobjectSecond 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
messageTypeTypeOfMessageClType of message determining the color
textstringText to write, can contain format placeholders
argsstring[]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
exceptionExceptionException to write.
WriteLine(int)
Writes a number to console as a line
public static void WriteLine(int number)
Parameters
numberintNumber to write
WriteLine(string)
Writes a line of text to console
public static void WriteLine(string text)
Parameters
textstringText to write
WriteLine(string, params object[])
Writes a formatted line to console
public static void WriteLine(string message, params object[] objects)
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
WriteLineObject(object)
Writes an object as string to console. Uses ToString() which may have lower performance.
public static void WriteLineObject(object value)
Parameters
valueobjectObject 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
colorConsoleColorColor to use for the text
valuestringText 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
listItemsIEnumerable<string>Items to write
headerstringOptional header to display before the list
argumentsWriteListArgsOptional 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
sourceobjectTimer source object
eElapsedEventArgsEvent arguments