Class Terminal
A console terminal helper to create nicer output and receive input from the user. This class is thread-safe :).
Inherited Members
Namespace: Swan
Syntax
public static class Terminal
Properties
AvailableWriters
Gets the available output writers in a bitwise mask.
Declaration
public static TerminalWriters AvailableWriters { get; }
Property Value
Type | Description |
---|---|
TerminalWriters | The available writers. |
CursorLeft
Gets or sets the cursor left position.
Declaration
public static int CursorLeft { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The cursor left. |
CursorTop
Gets or sets the cursor top position.
Declaration
public static int CursorTop { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The cursor top. |
IsConsolePresent
Gets a value indicating whether the Console is present.
Declaration
public static bool IsConsolePresent { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
OutputEncoding
Gets or sets the output encoding for the current console.
Declaration
public static Encoding OutputEncoding { get; set; }
Property Value
Type | Description |
---|---|
Encoding | The output encoding. |
Methods
BacklineCursor()
Moves the output cursor one line up starting at left position 0 Please note that backlining the cursor does not clear the contents of the previous line so you might need to clear it by writing an empty string the length of the console width.
Declaration
public static void BacklineCursor()
Clear()
Clears the screen.
Declaration
public static void Clear()
Flush(Nullable<TimeSpan>)
Waits for all of the queued output messages to be written out to the console. Call this method if it is important to display console text before quitting the application such as showing usage or help. Set the timeout to null or TimeSpan.Zero to wait indefinitely.
Declaration
public static void Flush(TimeSpan? timeout = default(TimeSpan? ))
Parameters
Type | Name | Description |
---|---|---|
Nullable<TimeSpan> | timeout | The timeout. Set the amount of time to black before this method exits. |
OverwriteLine(String, Nullable<ConsoleColor>, TerminalWriters)
As opposed to WriteLine methods, it prepends a Carriage Return character to the text so that the console moves the cursor one position up after the text has been written out.
Declaration
public static void OverwriteLine(string text, ConsoleColor? color = default(ConsoleColor? ), TerminalWriters writerFlags = TerminalWriters.StandardOutput)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text. |
Nullable<ConsoleColor> | color | The color. |
TerminalWriters | writerFlags | The writer flags. |
ReadKey(Boolean, Boolean)
Reads a key from the Terminal. This is the closest equivalent to Console.ReadKey.
Declaration
public static ConsoleKeyInfo ReadKey(bool intercept, bool disableLocking = false)
Parameters
Type | Name | Description |
---|---|---|
Boolean | intercept | if set to |
Boolean | disableLocking | if set to |
Returns
Type | Description |
---|---|
ConsoleKeyInfo | The console key information. |
ReadKey(String, Boolean)
Reads a key from the Terminal.
Declaration
public static ConsoleKeyInfo ReadKey(string prompt, bool preventEcho = true)
Parameters
Type | Name | Description |
---|---|---|
String | prompt | The prompt. |
Boolean | preventEcho | if set to |
Returns
Type | Description |
---|---|
ConsoleKeyInfo | The console key information. |
ReadLine()
Reads a line of text from the console.
Declaration
public static string ReadLine()
Returns
Type | Description |
---|---|
String | The read line. |
ReadLine(String)
Reads a line from the input.
Declaration
public static string ReadLine(string prompt)
Parameters
Type | Name | Description |
---|---|---|
String | prompt | The prompt. |
Returns
Type | Description |
---|---|
String | The read line. |
ReadNumber(String, Int32)
Reads a number from the input. If unable to parse, it returns the default number.
Declaration
public static int ReadNumber(string prompt, int defaultNumber)
Parameters
Type | Name | Description |
---|---|---|
String | prompt | The prompt. |
Int32 | defaultNumber | The default number. |
Returns
Type | Description |
---|---|
Int32 | Conversions of string representation of a number to its 32-bit signed integer equivalent. |
ReadPrompt(String, IDictionary<ConsoleKey, String>, String)
Creates a table prompt where the user can enter an option based on the options dictionary provided.
Declaration
public static ConsoleKeyInfo ReadPrompt(string title, IDictionary<ConsoleKey, string> options, string anyKeyOption)
Parameters
Type | Name | Description |
---|---|---|
String | title | The title. |
IDictionary<ConsoleKey, String> | options | The options. |
String | anyKeyOption | Any key option. |
Returns
Type | Description |
---|---|
ConsoleKeyInfo | A value that identifies the console key that was pressed. |
SetCursorPosition(Int32, Int32)
Sets the cursor position.
Declaration
public static void SetCursorPosition(int left, int top)
Parameters
Type | Name | Description |
---|---|---|
Int32 | left | The left. |
Int32 | top | The top. |
Write(Char, Nullable<ConsoleColor>, Int32, Boolean, TerminalWriters)
Writes a character a number of times, optionally adding a new line at the end.
Declaration
public static void Write(char charCode, ConsoleColor? color = default(ConsoleColor? ), int count = 1, bool newLine = false, TerminalWriters writerFlags = TerminalWriters.StandardOutput)
Parameters
Type | Name | Description |
---|---|---|
Char | charCode | The character code. |
Nullable<ConsoleColor> | color | The color. |
Int32 | count | The count. |
Boolean | newLine | if set to |
TerminalWriters | writerFlags | The writer flags. |
Write(String, Nullable<ConsoleColor>, TerminalWriters)
Writes the specified text in the given color.
Declaration
public static void Write(string text, ConsoleColor? color = default(ConsoleColor? ), TerminalWriters writerFlags = TerminalWriters.StandardOutput)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text. |
Nullable<ConsoleColor> | color | The color. |
TerminalWriters | writerFlags | The writer flags. |
WriteLine(TerminalWriters)
Writes a New Line Sequence to the standard output.
Declaration
public static void WriteLine(TerminalWriters writerFlags = TerminalWriters.StandardOutput)
Parameters
Type | Name | Description |
---|---|---|
TerminalWriters | writerFlags | The writer flags. |
WriteLine(String, Nullable<ConsoleColor>, TerminalWriters)
Writes a line of text in the current console foreground color to the standard output.
Declaration
public static void WriteLine(string text, ConsoleColor? color = default(ConsoleColor? ), TerminalWriters writerFlags = TerminalWriters.StandardOutput)
Parameters
Type | Name | Description |
---|---|---|
String | text | The text. |
Nullable<ConsoleColor> | color | The color. |
TerminalWriters | writerFlags | The writer flags. |
WriteWelcomeBanner(ConsoleColor)
Writes a standard banner to the standard output containing the company name, product name, assembly version and trademark.
Declaration
public static void WriteWelcomeBanner(ConsoleColor color = null)
Parameters
Type | Name | Description |
---|---|---|
ConsoleColor | color | The color. |