Console Wrapper
How do I wrap the console?
Terminaux provides you with a powerful and easy-to-use console wrapper that allows you to customize how the console behaves in your .NET console applications that make use of this wrapper and/or built-in Terminaux features.
One big advantage of using this console wrapper is that you're able to get the console cursor visibility, but only if you're using Terminaux's cursor visibility wrapper. This works on Windows, macOS, Android, and Linux.
Usage
To use this console wrapper, just replace all the calls to Console with our replacement ConsoleWrapper to take advantage of Terminaux's console wrapping feature.
Supported actions for the console wrapper
You can use this wrapper only for the following actions:
CursorLeft(get and set)CursorTop(get and set)WindowWidth(get and set)WindowHeight(get and set)BufferWidth(get and set)BufferHeight(get and set)CursorVisible(get and set)KeyAvailable(get)TreatCtrlCAsInput(get and set)Clear()(with and without background)GetCursorPosition()SetCursorPosition()SetWindowDimensions()SetBufferDimensions()Beep()ReadKey()Write()WriteLine()Error.Write()Error.WriteLine()
Note that properties and functions that work only for Windows, such as MoveBufferArea, and have no good alternative alternatives for macOS and Linux are not going to be wrapped.
Customizing the wrappers
You can customize the console wrappers so that applications that call the Terminaux console wrapper can make use of your own custom wrapper function by setting the wrapper using SetWrapper() found in the ConsoleWrapperTools class once you register it using RegisterWrapper(). You need to make a new class that inherits from BaseConsoleWrapper.
Overridable functions and properties
You can make changes to the following wrappers by overriding a function or a property in your console wrapper class:
IsDumbMovementDetectedCursorLeftSetCursorLeftCursorTopSetCursorTopWindowWidthSetWindowWidthWindowHeightSetWindowHeightBufferWidthSetBufferWidthBufferHeightSetBufferHeightCursorVisibleGetCursorVisibleTreatCtrlCAsInputKeyAvailableClear()(without background)ClearLoadBack()(with background)GetCursorPosition()SetCursorPosition()SetWindowDimensions()SetBufferDimensions()Beep()BeepSeq()ReadKey()WriteChar()WriteString()WriteParameterized()WriteLine()WriteLineStirng()WriteLineParameterized()WriteError()WriteErrorLine()
In order for your console wrapper to be usable, all your custom wrapper functions must be fast, as interactive TUIs rely on performance.
Example of a very simple console wrapper class
A very simple example of this is:
internal class Null : BaseConsoleWrapper
{
public override bool IsDumb => true;
public override int CursorLeft { get => 0; set => throw new NotImplementedException(); }
public override int CursorTop { get => 0; set => throw new NotImplementedException(); }
public override Coordinate GetCursorPosition => new(CursorLeft, CursorTop);
// other overrides
}Last updated