Class BaseConsoleWrapper
Base console wrapper class for the System.Console class to ensure safety against dumb consoles and Windows-only features.
Inheritance
Namespace
Syntax
public class BaseConsoleWrapper
Fields
_moved
Checks to see if the console has moved. Only set this to true if the console has really moved, for example, each call to setting cursor position, key reading, writing text, etc.
Field Value
Declaration
protected bool _moved
Properties
BufferHeight
The console buffer height (rows)
Property Value
Declaration
public virtual int BufferHeight { get; }
BufferWidth
The console buffer width (columns)
Property Value
Declaration
public virtual int BufferWidth { get; }
CursorLeft
The cursor left position
Property Value
Declaration
public virtual int CursorLeft { get; set; }
CursorTop
The cursor top position
Property Value
Declaration
public virtual int CursorTop { get; set; }
CursorVisible
The cursor visibility mode
Property Value
Declaration
public virtual bool CursorVisible { get; set; }
GetCursorPosition
The cursor top position
IsDumb
Checks to see if the console is dumb
Property Value
Declaration
public virtual bool IsDumb { get; }
KeyAvailable
Whether a key is pressed
Property Value
Declaration
public virtual bool KeyAvailable { get; }
MovementDetected
Has the console moved? Should be set by Write*, Set*, and all console functions that have to do with moving the console.
Property Value
Declaration
public virtual bool MovementDetected { get; }
TreatCtrlCAsInput
Whether to treat Ctrl + C as input or not
Property Value
Declaration
public virtual bool TreatCtrlCAsInput { get; set; }
WindowHeight
The console window height (rows)
Property Value
Declaration
public virtual int WindowHeight { get; }
WindowWidth
The console window width (columns)
Property Value
Declaration
public virtual int WindowWidth { get; }
Methods
Beep()
Beeps the console
Declaration
public virtual void Beep()
BeepCustom(int, int)
Beeps the console
Declaration
public virtual void BeepCustom(int freq, int ms)
Parameters
| Name | Type | Description |
|---|---|---|
| freq | int | Frequency in hertz |
| ms | int | Duration in milliseconds |
BeepSeq()
Beeps the console (VT Sequence method)
Declaration
public virtual void BeepSeq()
Clear()
Clears the console screen.
Declaration
public virtual void Clear()
ClearLoadBack()
Clears the console screen while loading the background.
Declaration
public virtual void ClearLoadBack()
ReadKey(bool)
Reads a key
Returns
Declaration
public virtual ConsoleKeyInfo ReadKey(bool intercept = false)
Parameters
| Name | Type | Description |
|---|---|---|
| intercept | bool | Whether to intercept |
SetBufferDimensions(int, int)
Sets the buffer dimensions
Declaration
public virtual void SetBufferDimensions(int width, int height)
Parameters
| Name | Type | Description |
|---|---|---|
| width | int | The buffer width to be set (from 0) |
| height | int | The buffer height to be set (from 0) |
SetBufferHeight(int)
Sets the buffer height
Declaration
public virtual void SetBufferHeight(int height)
Parameters
| Name | Type | Description |
|---|---|---|
| height | int | The buffer height to be set (from 0) |
SetBufferWidth(int)
Sets the buffer width
Declaration
public virtual void SetBufferWidth(int width)
Parameters
| Name | Type | Description |
|---|---|---|
| width | int | The buffer width to be set (from 0) |
SetCursorLeft(int)
Sets the cursor left
Declaration
public virtual void SetCursorLeft(int left)
Parameters
| Name | Type | Description |
|---|---|---|
| left | int | The left to be set (from 0) |
SetCursorPosition(int, int)
Sets the cursor position
Declaration
public virtual void SetCursorPosition(int left, int top)
Parameters
| Name | Type | Description |
|---|---|---|
| left | int | The left to be set (from 0) |
| top | int | The top to be set (from 0) |
SetCursorTop(int)
Sets the cursor top
Declaration
public virtual void SetCursorTop(int top)
Parameters
| Name | Type | Description |
|---|---|---|
| top | int | The top to be set (from 0) |
SetWindowDimensions(int, int)
Sets the window dimensions
Declaration
public virtual void SetWindowDimensions(int width, int height)
Parameters
| Name | Type | Description |
|---|---|---|
| width | int | The window width to be set (from 0) |
| height | int | The window height to be set (from 0) |
SetWindowHeight(int)
Sets the window height
Declaration
public virtual void SetWindowHeight(int height)
Parameters
| Name | Type | Description |
|---|---|---|
| height | int | The window height to be set (from 0) |
SetWindowWidth(int)
Sets the window width
Declaration
public virtual void SetWindowWidth(int width)
Parameters
| Name | Type | Description |
|---|---|---|
| width | int | The window width to be set (from 0) |
Write(char)
Writes a character to console (stdout)
Declaration
public virtual void Write(char value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | char | A character |
Write(string)
Writes text to console (stdout)
Declaration
public virtual void Write(string text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
Write(string, params object[])
Writes text to console (stdout)
Declaration
public virtual void Write(string text, params object[] args)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
| args | object[] | The arguments to evaluate |
WriteError(char)
Writes a character to console (stderr)
Declaration
public virtual void WriteError(char value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | char | A character |
WriteError(string)
Writes text to console (stderr)
Declaration
public virtual void WriteError(string text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
WriteError(string, params object[])
Writes text to console (stderr)
Declaration
public virtual void WriteError(string text, params object[] args)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
| args | object[] | The arguments to evaluate |
WriteErrorLine()
Writes new line to console (stderr)
Declaration
public virtual void WriteErrorLine()
WriteErrorLine(string)
Writes text to console (stderr) with line terminator
Declaration
public virtual void WriteErrorLine(string text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
WriteErrorLine(string, params object[])
Writes text to console (stderr) with line terminator
Declaration
public virtual void WriteErrorLine(string text, params object[] args)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
| args | object[] | The arguments to evaluate |
WriteLine()
Writes new line to console (stdout)
Declaration
public virtual void WriteLine()
WriteLine(string)
Writes text to console (stdout) with line terminator
Declaration
public virtual void WriteLine(string text)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
WriteLine(string, params object[])
Writes text to console (stdout) with line terminator
Declaration
public virtual void WriteLine(string text, params object[] args)
Parameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to write |
| args | object[] | The arguments to evaluate |