Console Wrapper
How do I wrap the console?
Terminaux provides you with a powerful 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. This wrapper is easy to use, amidst the recent structural improvements to the console wrapper functionality compared to Terminaux 1.x.
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.
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. However, 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()
Setting 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
. 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
}
You can make changes to the following wrappers by overriding a function in your console wrapper class:
IsDumb
MovementDetected
CursorLeft
SetCursorLeft
CursorTop
SetCursorTop
WindowWidth
SetWindowWidth
WindowHeight
SetWindowHeight
BufferWidth
SetBufferWidth
BufferHeight
SetBufferHeight
CursorVisible
GetCursorVisible
TreatCtrlCAsInput
KeyAvailable
Clear()
(without background)ClearLoadBack()
(with background)GetCursorPosition()
SetCursorPosition()
SetWindowDimensions()
SetBufferDimensions()
Beep()
BeepSeq()
ReadKey()
WriteChar()
WriteString()
WriteParameterized()
WriteLine()
WriteLineStirng()
WriteLineParameterized()
WriteError()
WriteErrorLine()
Last updated