Class Core
- Namespace
- ConsoleAppVisuals
- Assembly
- ConsoleAppVisuals.dll
The Core class is a collection of low-level methods responsible of all the interactions between the library and the console (e.g. changing colors, writing text, etc.).
public static class Core
- Inheritance
-
Core
- Inherited Members
Remarks
For more information, consider visiting the documentation available here.
Fields
NEGATIVE_ANCHOR
Defines the negative anchor to put inside a string to be recognized as negative.
The following line will put " negative " in negative on the screen and not print the "/neg" anchors.
string str = "This is a /neg negative /neg string";
public const string NEGATIVE_ANCHOR = "/neg"
Field Value
Properties
ColorPanel
Gets the current color panel used in the console.
public static (ConsoleColor, ConsoleColor) ColorPanel { get; }
Property Value
InitialColorPanel
Gets the initial color panel of the console.
public static (ConsoleColor, ConsoleColor) InitialColorPanel { get; }
Property Value
Methods
ApplyNegative(bool)
Switches the font and background colors of the console in order to apply a negative to highlight the text.
[Visual]
public static void ApplyNegative(bool negative = false)
Parameters
negative
boolIf true, the text is highlighted.
Remarks
For more information, consider visiting the documentation available here.
BannerToString((string, string, string))
Converts a banner tuple into a string.
[Visual]
public static string BannerToString(this (string, string, string) banner)
Parameters
Returns
- string
Converts the banner to a string.
Remarks
For more information, consider visiting the documentation available here.
ClearMultiplePositionedLines(Placement, int, params string[])
Clears a multiple lines in the console given a certain starting line.
[Visual]
public static void ClearMultiplePositionedLines(Placement placement, int line, params string[] text)
Parameters
placement
PlacementThe placement of the paragraph.
line
intThe height of the paragraph.
text
string[]The lines of the paragraph.
Remarks
For more information, consider visiting the documentation available here.
GetRandomColor()
Gets a random color from a list of predefined colors (the default ones).
public static ConsoleColor GetRandomColor()
Returns
- ConsoleColor
A random color.
Remarks
For more information, consider visiting the documentation available here.
GetRangeAndRemoveNegativeAnchors(string)
Gets the range of a negative sequence in a string and remove the negative anchors.
public static (string, (int, int)?) GetRangeAndRemoveNegativeAnchors(this string str)
Parameters
str
stringThe string to check.
Returns
- (string, (int, int)?)
The string without the negative anchors and the range of the negative sequence.
Remarks
For more information, consider visiting the documentation available here.
InsertString(string, string, TextAlignment)
Inserts a specified string into another string, at a specified position.
public static string InsertString(this string inserted, string toInsert, TextAlignment align = TextAlignment.Center)
Parameters
inserted
stringThe string that receives the other.
toInsert
stringThe string to insert.
align
TextAlignmentThe alignment of the string to insert.
Returns
- string
The final string after computing.
Remarks
For more information, consider visiting the documentation available here.
IsScreenUpdated()
Checks if the screen has been updated (colors or dimensions have changed)
[Visual]
public static bool IsScreenUpdated()
Returns
- bool
True if the screen has been updated, false otherwise.
Remarks
For more information, consider visiting the documentation available here.
LoadSavedColorPanel()
Loads the saved color panel (consider saving it beforehand)
[Visual]
public static void LoadSavedColorPanel()
Remarks
For more information, consider visiting the documentation available here.
LoadTerminalColorPanel()
Loads the terminal color panel.
[Visual]
public static void LoadTerminalColorPanel()
Remarks
For more information, consider visiting the documentation available here.
ResizeString(string, int, TextAlignment, bool)
Builds a new string with a specific size and a specific placement.
public static string ResizeString(this string str, int size, TextAlignment align = TextAlignment.Center, bool truncate = true)
Parameters
str
stringThe string to build.
size
intThe size of the string.
align
TextAlignmentThe alignment of the string.
truncate
boolIf true, the string is truncated if it is too long.
Returns
- string
The built string.
Remarks
For more information, consider visiting the documentation available here.
RestoreColorPanel()
Restores the default colors of the console with the initial color panel.
[Visual]
public static void RestoreColorPanel()
Remarks
For more information, consider visiting the documentation available here.
SaveColorPanel()
Saves the current color panel in a variable.
[Visual]
public static void SaveColorPanel()
Remarks
For more information, consider visiting the documentation available here.
SetBackgroundColor(ConsoleColor)
Changes the background color of the console.
[Visual]
public static void SetBackgroundColor(ConsoleColor color)
Parameters
color
ConsoleColorThe new background color.
Remarks
For more information, consider visiting the documentation available here.
SetConsoleColors()
Set the console colors to the Core variables associated. It does not change the actual colors of the console.
[Visual]
public static void SetConsoleColors()
Remarks
For more information, consider visiting the documentation available here.
SetConsoleDimensions()
Set the dimensions of the console to the Core variables associated. It does not change the actual dimensions of the console.
[Visual]
public static void SetConsoleDimensions()
Remarks
For more information, consider visiting the documentation available here.
SetForegroundColor(ConsoleColor)
Changes the foreground color of the console.
[Visual]
public static void SetForegroundColor(ConsoleColor color)
Parameters
color
ConsoleColorThe new color.
Remarks
For more information, consider visiting the documentation available here.
ToPlacement(TextAlignment)
Converts a TextAlignment into a Placement.
public static Placement ToPlacement(this TextAlignment align)
Parameters
align
TextAlignmentThe alignment to convert.
Returns
- Placement
The converted alignment.
Remarks
For more information, consider visiting the documentation available here.
Exceptions
- ArgumentException
Thrown when the alignment is not valid.
ToTextAlignment(Placement)
Converts a Placement into a TextAlignment.
public static TextAlignment ToTextAlignment(this Placement placement)
Parameters
placement
PlacementThe placement to convert.
Returns
- TextAlignment
The converted placement.
Remarks
For more information, consider visiting the documentation available here.
Exceptions
- ArgumentException
Thrown when the placement is not valid.
WriteContinuousString(string, int?, bool, int, int, int?, TextAlignment, Placement)
Writes a string continuously in the console. The string is written letter by letter on the console.
[Visual]
public static void WriteContinuousString(string str, int? line, bool negative = false, int printTime = 2000, int additionalTime = 1000, int? length = null, TextAlignment align = TextAlignment.Center, Placement placement = Placement.TopCenter)
Parameters
str
stringThe string to write.
line
int?The line where the string is written in the console. If null, will be written where the cursor is.
negative
boolIf true, the text is highlighted.
printTime
intThe total time to write the string in ms.
additionalTime
intThe additional time to wait after the string is written in ms.
length
int?The length of the string. If null, the length is the window width.
align
TextAlignmentThe alignment of the string.
placement
PlacementThe placement of the string.
Remarks
For more information, consider visiting the documentation available here.
WriteDebugMessage(Placement, params string[])
[Debugging purposes] It overwrites any text in the console at a specified placement to display a debug message.
[Visual]
public static void WriteDebugMessage(Placement placement = Placement.TopRight, params string[] lines)
Parameters
Remarks
For more information, consider visiting the documentation available here.
WriteMultiplePositionedLines(bool, TextAlignment, Placement, bool, int?, params string[])
Writes multiple lines in the console given a certain placement and line.
[Visual]
public static void WriteMultiplePositionedLines(bool equalizeLengths = true, TextAlignment align = TextAlignment.Center, Placement placement = Placement.TopCenter, bool negative = false, int? line = null, params string[] text)
Parameters
equalizeLengths
boolWhether or not the lines of the paragraph should be equalized to the same length.
align
TextAlignmentThe alignment of the paragraph.
placement
PlacementThe placement of the paragraph.
negative
boolIf true, the paragraph is printed in the negative colors.
line
int?The height of the paragraph.
text
string[]The lines of the paragraph.
Remarks
For more information, consider visiting the documentation available here.
WritePositionedString(string, Placement, bool, int?, bool)
Writes a string in the console given a certain placement and line.
[Visual]
public static void WritePositionedString(string str, Placement placement = Placement.TopCenter, bool negative = false, int? line = null, bool writeLine = false)
Parameters
str
stringThe string to write.
placement
PlacementThe placement of the string in the console.
negative
boolIf true, the text is highlighted.
line
int?The line where the string is written in the console. If null, will be written where the cursor is.
writeLine
boolIf true, the string is written with a line break.
Remarks
For more information, consider visiting the documentation available here.
WritePositionedStyledText(string[]?, int?, int?, int?, TextAlignment, bool)
Writes a styled text in the console. The height will depend on the font used. Font enum for details.
[Visual]
public static void WritePositionedStyledText(string[]? text = null, int? line = null, int? width = null, int? margin = null, TextAlignment align = TextAlignment.Center, bool negative = false)
Parameters
text
string[]The styled string to write.
line
int?The line where the string is written in the console. If null, will be written from the ContentHeight.
width
int?The width of the string. If null, the width is the window width.
margin
int?The upper and lower margin.
align
TextAlignmentThe alignment of the string.
negative
boolIf true, the text is highlighted.
Remarks
For more information, consider visiting the documentation available here.